/* App shell: sidebar + main column. Desktop ≥1024px keeps a persistent,
   collapsible sidebar; smaller screens use a slide-over drawer. */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  z-index: 50;
}
.sidebar.is-rail {
  width: var(--rail-w);
  align-items: center;
  gap: 4px;
  padding: 12px 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 12px;
  flex-shrink: 0;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: var(--r-sm);
  text-decoration: none;
  user-select: none;
}
.wordmark-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.wordmark-text span {
  font-weight: 500;
  color: var(--ink-2);
}
.sidebar-actions {
  padding: 0 12px 8px;
  display: grid;
  gap: 8px;
  flex-shrink: 0;
}
.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-hairline);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  transition: background-color 0.15s;
}
.new-chat:hover {
  background: var(--raised);
}
.new-chat .grow {
  flex: 1;
  text-align: left;
}
.search {
  position: relative;
}
.search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.search input {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 32px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  font-size: 13.5px;
  outline: none;
}
.search input::placeholder {
  color: var(--ink-3);
}
.search input:hover {
  background: var(--hover);
}
.search input:focus {
  background: var(--surface);
  box-shadow: var(--shadow-hairline);
}
.search input::-webkit-search-cancel-button {
  display: none;
}
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 12px;
}
.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  margin-top: 12px;
  padding: 0 4px 0 10px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}
.row {
  position: relative;
}
.row-link {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 32px 0 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--ink-2);
  text-decoration: none;
  transition: background-color 0.12s, color 0.12s;
}
.row-link:hover {
  background: var(--hover);
  color: var(--ink);
}
.row-link.is-active {
  background: var(--hover);
  color: var(--ink);
  font-weight: 500;
}
.row-link .title {
  flex: 1;
  min-width: 0;
}
.row-link .pin {
  color: var(--ink-3);
  flex-shrink: 0;
}
.row-more {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--ink-3);
}
.row-more:hover {
  background: var(--hover);
  color: var(--ink);
}
@media (hover: hover) {
  .row-more {
    opacity: 0;
  }
  .row:hover .row-more,
  .row-more:focus-visible,
  .row-more[aria-expanded="true"] {
    opacity: 1;
  }
}
.row-input {
  width: calc(100% - 8px);
  height: 32px;
  margin: 0 4px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
  font-size: 13.5px;
  outline: none;
}
.folder-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 32px 0 8px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--ink-2);
  text-align: left;
}
.folder-toggle:hover {
  background: var(--hover);
  color: var(--ink);
}
.folder-toggle .chev {
  color: var(--ink-3);
  transition: transform 0.2s var(--ease);
}
.folder-toggle[aria-expanded="true"] .chev {
  transform: rotate(90deg);
}
.folder-toggle .name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
}
.folder-toggle .count {
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.folder-children {
  margin-left: 15px;
  padding-left: 6px;
  border-left: 1px solid var(--line);
}
.sidebar-empty {
  padding: 32px 10px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}
.sidebar-foot {
  flex-shrink: 0;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sidebar.is-rail .sidebar-foot {
  margin-top: auto;
  border: 0;
  width: 100%;
}
.callout {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-hairline);
  text-align: left;
}
.callout:hover {
  background: var(--raised);
}
.callout strong {
  display: block;
  font-size: 13px;
  font-weight: 500;
}
.callout span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-3);
}
.user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px;
  border-radius: var(--r-md);
  text-align: left;
}
.user-btn:hover,
.user-btn[aria-expanded="true"] {
  background: var(--hover);
}
.sidebar.is-rail .user-btn {
  justify-content: center;
}
.user-btn .meta {
  min-width: 0;
  flex: 1;
}
.user-btn .name {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
}
.user-btn .sub {
  display: block;
  font-size: 11.5px;
  color: var(--ink-3);
}
.avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

/* ── Main column ─────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 48px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  flex-shrink: 0;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
}
.view {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.dock {
  flex-shrink: 0;
  padding: 0 24px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.dock-inner {
  max-width: var(--thread-w);
  margin: 0 auto;
}

/* ── Desktop / mobile switching ──────────────────────────── */
.only-mobile {
  display: none !important;
}
.drawer-overlay {
  display: none;
}
@media (max-width: 1023.98px) {
  .only-mobile {
    display: inline-flex !important;
  }
  .only-desktop {
    display: none !important;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(284px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: var(--shadow-pop);
    visibility: hidden;
  }
  .app.drawer-open .sidebar {
    transform: none;
    visibility: visible;
  }
  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .app.drawer-open .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}
@media (max-width: 640px) {
  .topbar {
    padding: 0 8px;
  }
  .dock {
    padding: 0 12px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
