/* The shell: the sidebar of conversations, the settings list, and the reading surface. */

.app {
  display: flex;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* ------------------------------------------------------------------------------------------ */
/* Sidebar (284 px, ground.sunken) */

.sidebar,
.settings-nav {
  width: var(--w-sidebar);
  flex: none;
  background: var(--ground-sunken);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  gap: 18px;
  min-height: 0;
}
.app[data-shell='settings'] .sidebar,
.app[data-shell='bare'] .sidebar,
.app[data-shell='main'] .settings-nav,
.app[data-shell='bare'] .settings-nav {
  display: none;
}
.app.is-collapsed[data-shell='main'] .sidebar {
  display: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 0 8px;
  min-height: 32px;
}
.wordmark {
  font-family: var(--font-serif);
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.wordmark:hover {
  color: var(--ink);
  text-decoration: none;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side-action {
  --focus-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: var(--t-control);
  color: var(--ink-quiet);
  text-decoration: none;
  transition: background-color var(--d-micro) var(--ease-enter), color var(--d-micro) var(--ease-enter);
}
.side-action:hover {
  background: color-mix(in oklch, var(--surface-selected) 55%, transparent);
  color: var(--ink);
  text-decoration: none;
}
.side-action.is-primary {
  background: var(--surface-raised);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}
.side-action.is-primary:hover {
  background: var(--surface-raised);
  border-color: var(--line-strong);
}
.side-action[aria-current='page'] {
  background: var(--surface-selected);
  border-color: transparent;
  color: var(--ink);
  font-weight: 500;
}
.side-action .badge {
  margin-left: auto;
}

.threads {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin: 0 -8px;
  padding: 0 8px 8px;
}
.thread-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.thread-group > .t-label {
  padding: 0 12px 8px;
  letter-spacing: 0.04em;
}
.thread {
  --focus-radius: 10px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 12px;
  border-radius: var(--r-row);
  font-size: var(--t-control);
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color var(--d-micro) var(--ease-enter);
}
.thread:hover {
  background: color-mix(in oklch, var(--surface-selected) 55%, transparent);
  color: var(--ink);
  text-decoration: none;
}
.thread[aria-current='page'] {
  background: var(--surface-selected);
  color: var(--ink);
}
.thread .thread-title {
  flex: 1;
}
.thread .needs-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.thread .thread-more {
  opacity: 0;
  margin: -6px -6px -6px 0;
  width: 28px;
  height: 28px;
}
.thread:hover .thread-more,
.thread:focus-within .thread-more,
.thread .thread-more[aria-expanded='true'] {
  opacity: 1;
}
@media (hover: none) {
  .thread .thread-more {
    opacity: 1;
  }
}
.threads-empty {
  padding: 4px 12px;
  font-size: var(--t-meta);
  color: var(--ink-quiet);
}

/* Enter once, when the list arrives: rows stagger 40 ms. Never on scroll, never on re-show. */
.threads.is-arriving .thread {
  animation: mx-rise var(--d-fade) var(--ease-enter) both;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

/* Your name, what this month has cost, and the bar towards the ceiling. Opens You. */
.me {
  --focus-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px 4px;
  border-top: 1px solid var(--line);
  text-align: left;
  width: 100%;
  border-radius: 0 0 12px 12px;
}
.me:hover .me-name {
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
}
.me-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.me-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.me-name {
  font-size: var(--t-control);
  font-weight: 500;
}
.me-spend {
  font-size: var(--t-small);
  color: var(--ink-quiet);
}
.me-spend.is-paused {
  color: var(--accent-text);
}
.spend-bar {
  height: 3px;
  border-radius: 2px;
  background: color-mix(in oklch, var(--surface-selected) 80%, var(--ground-sunken));
  overflow: hidden;
}
:root[data-theme='dark'] .spend-bar {
  background: var(--line-soft);
}
.spend-bar > span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  width: var(--share, 0%);
  transition: width var(--d-open) var(--ease-move);
}

/* ------------------------------------------------------------------------------------------ */
/* Settings list: "‹ Conversations", you, then the list. */

.back-link {
  --focus-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: var(--t-control);
  color: var(--ink-quiet);
  text-decoration: none;
  align-self: flex-start;
}
.back-link:hover {
  color: var(--ink);
  text-decoration: none;
}
.back-link svg {
  width: 14px;
  height: 14px;
}
.back-link.is-accent {
  color: var(--accent-text);
}
.profile-mini {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 6px;
  min-width: 0;
}
.profile-mini .me-text span:first-child {
  font-size: calc(16px * var(--ts));
  font-weight: 500;
}
.settings-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  margin-top: 6px;
}
.settings-links a {
  --focus-radius: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 12px;
  border-radius: var(--r-row);
  font-size: var(--t-control);
  color: var(--ink-soft);
  text-decoration: none;
}
.settings-links a:hover {
  background: color-mix(in oklch, var(--surface-selected) 55%, transparent);
  color: var(--ink);
  text-decoration: none;
}
.settings-links a[aria-current='page'] {
  background: var(--surface-selected);
  color: var(--ink);
}
.settings-links .badge {
  margin-left: auto;
}

/* ------------------------------------------------------------------------------------------ */
/* The reading surface */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--ground);
}
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px 0 32px;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: var(--t-heading);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.topbar .phone-only {
  display: none;
}
.app.is-collapsed .topbar .show-sidebar {
  display: inline-flex;
}
.topbar .show-sidebar {
  display: none;
}

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 40;
  opacity: 0;
  transition: opacity var(--d-fade) var(--ease-enter);
}
.scrim.is-shown {
  opacity: 1;
}

/* ------------------------------------------------------------------------------------------ */
/* Phone: the sidebar is a drawer; the header is ≡ · title · you. */

@media (max-width: 859px) {
  .app[data-shell='main'] .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 45;
    transform: translateX(-102%);
    visibility: hidden;
    transition:
      transform var(--d-open) var(--ease-move),
      visibility 0s linear var(--d-open);
    padding-top: calc(22px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    box-shadow: var(--e-floating);
  }
  body.drawer-open .app[data-shell='main'] .sidebar {
    transform: none;
    visibility: visible;
    transition: transform var(--d-open) var(--ease-move), visibility 0s;
  }
  .app[data-shell='settings'] .settings-nav {
    display: none;
  }
  .topbar {
    height: 52px;
    padding: env(safe-area-inset-top) 12px 0 8px;
    box-sizing: content-box;
  }
  .topbar .phone-only {
    display: inline-flex;
  }
  .topbar .desktop-only {
    display: none;
  }
  .topbar-title {
    text-align: center;
    font-size: calc(19px * var(--ts));
  }
  .side-action,
  .thread,
  .settings-links a {
    min-height: 44px;
  }
}
