/* Airline Inbox layout: app shell, drawer, top bar, page header, grids, auth and error pages.
   Tokens only (see tokens.css). Breakpoints: 639.98px phone, 959.98px drawer, 960px auth side, 1100px two columns. */

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px; padding: 12px;
  background: var(--side-bg); border-right: 1px solid var(--side-line);
}

.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 40px; padding: 0 6px; }
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
  font-size: 15px; font-weight: 600; line-height: 20px; color: var(--ink);
  letter-spacing: var(--tracking-tight); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; flex: none; display: block; }
.logo-img { display: block; width: 100%; height: 100%; }
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
.sidebar .nav-close { display: none; }

.workspace {
  display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.ws-avatar {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--radius-xs);
  background: var(--accent-soft); color: var(--accent-soft-ink); font-size: 12px; font-weight: 600;
}
.ws-text { display: grid; min-width: 0; }
.ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--ink); }
.ws-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  margin: 20px 10px 6px; font-size: 11px; font-weight: 600; line-height: 14px;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--side-ink-muted);
}
.nav > .nav-label:first-child { margin-top: 4px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 0 10px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; line-height: 20px;
  color: var(--side-ink); text-decoration: none;
}
.nav-link .i { color: var(--side-muted); }
.nav-link.active, .nav-link[aria-current="page"] {
  background: var(--side-active); color: var(--side-active-ink);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-xs);
}
.nav-link.active .i, .nav-link[aria-current="page"] .i { color: var(--accent-icon); }
/* active item: a 2px accent rule just inside the left edge (drawn, so nothing shifts) */
.nav-link.active::before, .nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: 4px; top: 50%; width: 2px; height: 16px; margin-top: -8px;
  border-radius: 2px; background: var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  .nav-link:hover { background: var(--side-hover); color: var(--ink); text-decoration: none; }
  .nav-link { transition: background-color var(--dur-1) ease, color var(--dur-1) ease; }
}
.nav-badge {
  margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: var(--radius-full);
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 600; line-height: 1;
  font-variant-numeric: tabular-nums; background: var(--accent-soft); color: var(--accent-soft-ink);
}

.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--side-line); display: flex; flex-direction: column; gap: 8px; }
.side-note {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 16px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.side-note .i { margin-top: 1px; color: var(--accent-icon); }
.side-note strong { font-weight: 600; color: var(--ink); }

.user { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.user > form { flex: none; margin: 0; }
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3); color: var(--ink-2); font-size: 12px; font-weight: 600;
}
.user-text { display: grid; flex: 1; min-width: 0; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--side-active-ink); }
.user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--side-ink-muted); }

/* haptics preference: only where a touch screen is the main pointer; same inset as .user */
.haptics-pref { display: none; }
@media (any-pointer: coarse) {
  .haptics-pref { display: block; padding: 6px 4px; }
  .haptics-pref .switch { font-size: 13px; line-height: 18px; }
  .haptics-pref .hint { font-size: 12px; line-height: 16px; color: var(--side-ink-muted); }
}

/* ---------- top bar ---------- */
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 var(--gutter);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(8px)) {
  .topbar { background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(8px); }
}
.topbar .menu-btn { display: none; }

.crumb {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; line-height: 18px;
  color: var(--muted); text-decoration: none;
}
.crumb:hover { color: var(--ink); text-decoration: none; }

.global-search { position: relative; flex: 1; min-width: 0; max-width: 460px; margin: 0; }
.global-search > .i {
  position: absolute; left: 10px; top: 50%; z-index: 1; margin-top: -8px;
  color: var(--muted); pointer-events: none;
}
.global-search input[type="search"] {
  height: 36px; min-height: 36px; padding-left: 34px; padding-right: 34px; background: var(--surface);
}
.global-search kbd { position: absolute; right: 8px; top: 50%; margin-top: -10px; }
.global-search input:focus ~ kbd { display: none; }
/* phone-only buttons, shown by the phones block below */
.topbar .search-open, .topbar .search-close { display: none; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.topbar-right .icon-btn { color: var(--ink-2); }
.topbar-right .icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-soft-ink); }
.topbar-right .icon-btn > .i { display: block; }
/* theme toggle: exactly one icon. Light (or no theme set) shows the moon; dark shows the sun. Scoped to the toggle
   so the icon's own display rule (.topbar-right .icon-btn > .i) cannot show both. */
.topbar-right [data-theme-toggle] > .theme-icon-dark { display: none; }
:root[data-theme="dark"] .topbar-right [data-theme-toggle] > .theme-icon-dark { display: block; }
:root[data-theme="dark"] .topbar-right [data-theme-toggle] > .theme-icon-light { display: none; }

/* ---------- main column ---------- */
.main {
  width: 100%; min-width: 0; max-width: calc(var(--content-max) + 2 * var(--gutter));
  margin: 0 auto; padding: 24px var(--gutter) 64px;
}
/* one rhythm for every top-level block: 20px between blocks (16px on phones). Sibling margins collapse, so the
   page head's own 20px bottom margin and the next block's top margin meet at 20px rather than adding up. */
.main > * + * { margin-top: var(--space-5); }
@media (max-width: 639.98px) {
  .main > * + * { margin-top: var(--space-4); }
}
.scrim { display: none; }

/* ---------- page header ---------- */
/* the hairline under the title sits inside the head's bottom padding, so the rhythm to the next block is unchanged */
.page-head { position: relative; display: grid; gap: 4px; margin-bottom: 20px; padding-bottom: 14px; min-width: 0; }
.page-head::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: var(--title-rule); pointer-events: none;
}
.page-head .crumb { margin-bottom: 2px; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.title-row h1, .page-head h1 { overflow-wrap: anywhere; }
.page-head p, .page-head .sub { max-width: 75ch; margin: 0; font-size: 14px; color: var(--muted); }
.actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.section-title { margin: 0; font-size: 15px; font-weight: 600; line-height: 22px; color: var(--ink); }
.section-sub { margin: 0; font-size: 13px; line-height: 18px; color: var(--muted); }

/* ---------- layout grids ---------- */
.grid { display: grid; gap: 16px; min-width: 0; }
.grid-2 { display: grid; gap: 16px; min-width: 0; }
.grid-3 { display: grid; gap: 16px; min-width: 0; }
.grid-main { display: grid; gap: 16px; min-width: 0; }
@media (min-width: 640px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
}

.split { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.split-wide { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px; }

/* ---------- auth pages (auth_base.html) ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100dvh; background: var(--surface); }
.auth-main { display: flex; flex-direction: column; min-width: 0; padding: 28px 32px; }
.auth-main > .brand { align-self: flex-start; }
.auth-form {
  width: 100%; max-width: 400px; margin: auto; padding: 32px 0;
  display: grid; gap: 20px; min-width: 0;
}
.auth-form h1 {
  margin: 0; font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: var(--tracking-tighter);
  color: var(--ink); overflow-wrap: anywhere;
}
.auth-form .lead { margin: 0; font-size: 15px; line-height: 22px; color: var(--muted); }
.auth-form .btn-primary { min-height: var(--control-h-lg); }
.auth-foot { margin: 0; text-align: center; font-size: 14px; line-height: 20px; color: var(--muted); }
.auth-legal {
  display: flex; align-items: flex-start; gap: 8px; margin-top: 24px;
  font-size: 12px; line-height: 16px; color: var(--muted);
}
.auth-legal .i { margin-top: 1px; }
.auth-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; padding-left: 24px; font-size: 12px; line-height: 16px; }
.auth-links a { overflow-wrap: anywhere; }
@media (pointer: coarse) {
  .auth-links { row-gap: 12px; }
  .auth-links a { padding-block: 14px; margin-block: -14px; }
}

.auth-side { display: none; }
.auth-side .eyebrow {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; line-height: 16px;
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--accent-soft-ink);
}
.auth-side .eyebrow .i { width: 14px; height: 14px; }
.auth-art { width: 100%; max-width: 440px; }
.auth-art svg { display: block; width: 100%; height: auto; }
.side-lead { margin: 0; font-size: 22px; line-height: 30px; font-weight: 600; letter-spacing: var(--tracking-tight); color: var(--ink); }
.benefits { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 15px; line-height: 22px; color: var(--ink-2); }
.benefits li { display: flex; align-items: flex-start; gap: 10px; }
.tick {
  display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; margin-top: 1px;
  border-radius: 50%; background: var(--good-soft); color: var(--good-ink);
}
.tick .i { width: 14px; height: 14px; }

@media (min-width: 960px) {
  .auth { grid-template-columns: minmax(420px, 5fr) minmax(0, 6fr); }
  .auth-side {
    display: flex; flex-direction: column; justify-content: center; gap: 24px; min-width: 0; padding: 48px;
    background: linear-gradient(160deg, var(--accent-soft) 0%, var(--bg) 70%);
    border-left: 1px solid var(--border);
  }
}
@media (max-width: 639.98px) {
  .auth-main { padding: 20px var(--gutter); }
  .auth-form { padding: 24px 0; }
  .auth-form h1 { font-size: 24px; line-height: 30px; }
}

/* ---------- error page (error.html uses the auth layout) ---------- */
.error-icon {
  display: inline-grid; place-items: center; width: 48px; height: 48px; margin: 0 auto;
  border-radius: 50%; background: var(--surface-3); color: var(--critical-ink);
}
.error-icon .i { width: 24px; height: 24px; }
.auth-form .empty-state h1 { font-size: var(--text-2xl); line-height: 28px; }

/* the standalone error page: a header with the brand, the message centred below it */
.error-page { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.error-head { height: 64px; display: flex; align-items: center; padding: 0 24px; }
.error-main { flex: 1; display: grid; place-items: center; padding: 24px 16px 72px; }
.error-main .empty-state { max-width: 440px; }
.error-main .empty-state h1 { font-size: var(--text-2xl); line-height: 28px; }
@media (max-width: 639.98px) { .error-head { padding: 0 16px; } }

/* ---------- drawer below the drawer breakpoint (phones and small tablets) ---------- */
@media (max-width: 959.98px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: var(--z-drawer);
    width: min(300px, 86vw); height: 100dvh;
    transform: translateX(-100%); visibility: hidden; box-shadow: var(--shadow-lg);
    transition: transform var(--dur-3) var(--ease-drawer), visibility 0s linear var(--dur-3);
  }
  .nav-open .sidebar, .sidebar:target {
    transform: none; visibility: visible;
    transition: transform var(--dur-3) var(--ease-drawer);
  }
  .sidebar .nav-close { display: inline-grid; margin-left: auto; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: var(--z-scrim);
    background: var(--scrim); opacity: 0; pointer-events: none;
    transition: opacity var(--dur-3) ease;
  }
  .nav-open .scrim { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { gap: 8px; }
}

/* ---------- phones ---------- */
@media (max-width: 639.98px) {
  .main { padding-top: 20px; padding-bottom: 48px; }
  .global-search kbd { display: none; }
  .page-head h1 { font-size: 20px; line-height: 26px; }
  .actions { width: 100%; margin-left: 0; }
  /* phone search: a 44px search button; with JS the field opens over the whole top bar (app.js) */
  html.js .topbar .search-open { display: inline-grid; width: 44px; height: 44px; }
  html.js .topbar:not(.search-is-open) .global-search { display: none; }
  html.js .topbar.search-is-open .global-search {
    position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
    max-width: none; padding: 0 var(--gutter); background: var(--bg);
  }
  html.js .topbar.search-is-open .global-search > .i { left: calc(var(--gutter) + 10px); }
  html.js .topbar.search-is-open .global-search input[type="search"] { flex: 1; min-width: 0; height: 44px; min-height: 44px; }
  html.js .topbar.search-is-open .search-close { display: inline-grid; flex: none; width: 44px; height: 44px; }
}

/* ---------- touch: 44px targets on coarse pointers (desktop density unchanged; .icon-btn is in controls.css) ---------- */
@media (pointer: coarse) {
  .brand-row { height: 44px; }
  .brand { min-height: 44px; }
  .nav-link { min-height: 44px; }
  .crumb { min-height: 44px; }
  .global-search input[type="search"] { height: 44px; min-height: 44px; }
}
