/* ============================================================================
   ASRT Support Console — application styles.
   Palette, type, radii, elevation and motion come from css/tokens.css (the "warm
   ledger" system): paper neutrals, one engineered teal, mono for every figure, and
   an elevation ramp that separates surfaces by tone as well as by rule. This file
   owns the layout and the component classes the views already reference.

   Two contracts hold this file together:
   1. LEGACY ALIASES below map the old variable names onto the tokens, because the
      nine view modules still set colours inline (var(--brand-500), var(--ink-3)).
      Re-skin the aliases, never the views.
   2. MOBILE FIRST. Every rule targets the smallest screen; min-width media queries
      add the desktop rail, the third inbox column and the wider page gutters. A
      max-width query means "undo something the base rule did" and should be read
      as a bug until proven otherwise.
   ========================================================================= */

/* ---------- legacy aliases: old names, new palette ---------- */
:root {
  --brand-50:  #e9f4f0;
  --brand-100: #cfe6dd;
  --brand-200: #a5d3c5;
  --brand-300: #63b7a1;
  --brand-400: var(--accent);
  --brand-500: var(--accent);
  --brand-600: var(--accent-strong);
  --brand-700: var(--accent-strong);
  --brand-800: var(--accent-strong);
  --brand-900: var(--bg-inverse);

  --bg:          var(--bg-canvas);
  --bg-elevated: var(--bg-raised);
  --surface:     var(--bg-surface);
  --surface-2:   var(--bg-surface-2);
  --surface-3:   var(--bg-surface-3);
  --ink:         var(--text-primary);
  --ink-2:       var(--text-secondary);
  --ink-3:       var(--text-muted);
  --ink-4:       var(--text-muted);
  --line:        var(--border-subtle);
  --line-strong: var(--border-strong);

  --red:     var(--bad);    --red-soft:     var(--bad-bg);
  --amber:   var(--warn);   --amber-soft:   var(--warn-bg);
  --blue:    var(--info);   --blue-soft:    var(--info-bg);
  --violet:  var(--info);   --violet-soft:  var(--info-bg);
  --green:   var(--ok);     --green-soft:   var(--ok-bg);
  --slate:   var(--neutral);  --slate-soft: var(--neutral-bg);
  --cyan:    var(--accent); --cyan-soft:    var(--accent-soft);

  --radius-xs: var(--r-xs);
  --radius-sm: var(--r-sm);
  --radius:    var(--r-md);
  --radius-lg: var(--r-lg);
  --radius-xl: var(--r-xl);

  /* only floating layers cast anything */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow:    var(--shadow-md);
  --ring: var(--shadow-focus);

  --sidebar-w: var(--rail-w);
  --tabbar-h: 58px;
  --composer-h: 96px;
  --inbox-list-w: 340px;
  --inbox-detail-w: 330px;

  /* the one transition every interactive part shares, so a hover is not re-timed
     per component and reduced-motion has a single thing to switch off */
  --t-fast: var(--dur-1) var(--ease);
  --t: var(--dur-2) var(--ease);
  --t-slow: var(--dur-3) var(--ease-out);

  /* iOS Safari counts the collapsing URL bar inside 100vh, which pushes the composer
     and the tab bar under it. dvh tracks the visible box; the @supports guard keeps
     browsers that predate it on the old value. */
  --app-h: 100vh;
  --flow-h: 100vh;
}
@supports (height: 100dvh) {
  :root { --app-h: 100dvh; --flow-h: 100dvh; }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  accent-color: var(--accent);
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: var(--fs-md);
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, h5 { font-weight: 650; line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); color: var(--ink); }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
a { color: var(--text-link); text-decoration: none; transition: color var(--t-fast); }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
input, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); color: var(--text-primary); }

.mono, .tnum { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.mono { font-size: .94em; letter-spacing: -0.01em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* scrollbars — thin, on the paper palette, never on touch */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
*::-webkit-scrollbar-track { background: transparent; }
@media (hover: none) and (pointer: coarse) {
  *::-webkit-scrollbar { width: 0; height: 0; }
}

/* ---------- boot splash ---------- */
.app-boot { height: var(--app-h); display: grid; place-items: center; background: var(--bg-canvas); }
.boot-splash { text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }
.boot-mark {
  width: 52px; height: 52px; margin: 0 auto 16px;
  background: url("/icons/favicon.svg") center / 46px no-repeat;
  animation: bootpulse 1.4s var(--ease) infinite;
}
@keyframes bootpulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.94); } }

/* ============================================================================
   AUTH — sign in, code, reset, invitation
   A console login is a card on paper with the company mark above it. The card
   carries the shadow so the form reads as the one thing to do on the page.
   ========================================================================== */
.auth-shell {
  height: var(--app-h);
  overflow-y: auto;
  display: grid;
  /* minmax(0,1fr), not 1fr: a bare 1fr track still refuses to shrink below its content's
   * min-content width, and six OTP boxes carry a ~58px intrinsic input width each — which
   * is exactly how a 390px phone ends up with a sideways-scrolling sign-in form. */
  grid-template-columns: minmax(0, 1fr);
  /* an auto row that can grow past the container: minmax keeps the form centred when
     there is slack and scrollable, never clipped, when there is not. */
  grid-template-rows: minmax(min-content, 1fr);
  align-items: center;
  background: var(--bg-canvas);
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.auth-panel { display: grid; place-items: center; min-width: 0; }
.auth-card {
  width: 100%; max-width: 400px; padding: 26px 22px;
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
}
.auth-mark { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.auth-mark .mark {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: var(--r-md); background: var(--sidebar-bg); color: var(--accent-on-dark);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.auth-mark .mark svg { width: 22px; height: 22px; }.auth-mark .wm { line-height: 1.1; }
.auth-mark .wm b { font-size: var(--fs-lg); letter-spacing: var(--tracking-tight); display: block; }
.auth-mark .wm span { font-size: var(--fs-xxs); color: var(--text-muted); font-weight: 700; letter-spacing: var(--tracking-label); }
.auth-card .eyebrow { text-transform: uppercase; letter-spacing: var(--tracking-label); font-size: var(--fs-xxs); color: var(--text-muted); font-weight: 700; }
.auth-card h2 { font-size: var(--fs-2xl); margin: 6px 0 4px; }
.auth-card .sub { color: var(--text-muted); margin-bottom: 22px; font-size: var(--fs-sm); }
.auth-foot { margin-top: 20px; text-align: center; color: var(--text-muted); font-size: var(--fs-xs); }
.auth-links { margin-top: 16px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: var(--fs-sm); }
.auth-links .link { min-height: 32px; }

/* A form-level error is a block with weight behind it: it is the only thing standing
 * between "my code was wrong" and "the whole sign-in is broken". Field-level errors
 * underneath stay plain text (see .field .err). */
.err {
  font-size: var(--fs-sm); color: var(--bad);
  background: var(--bad-bg); border: 1px solid var(--bad-line); border-left-width: 3px;
  border-radius: var(--r-sm); padding: 10px 12px;
}
.field .err { background: none; border: 0; padding: 0; color: var(--bad); font-size: var(--fs-xs); }
.link {
  background: none; border: 0; padding: 0; margin: 0; font: inherit; cursor: pointer;
  color: var(--text-link); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
  display: inline-flex; align-items: center; gap: 6px; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; transition: color var(--t-fast);
}
.link:hover { color: var(--accent-strong); }
.link:disabled { color: var(--text-muted); text-decoration: none; cursor: default; }
@media (hover: none) and (pointer: coarse) { .link { font-size: var(--fs-md); } }

/* password reveal, parked inside the field it belongs to */
.input-icon--tail .input { padding-left: 12px; padding-right: 42px; }
.reveal {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: grid; place-items: center;
  background: none; border: 0; color: var(--text-muted); cursor: pointer;
  border-radius: var(--r-sm); touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast), color var(--t-fast);
}
.reveal:hover { color: var(--text-primary); background: var(--bg-hover); }
@media (hover: none) and (pointer: coarse) { .reveal { width: 44px; height: 44px; } }

/* six-digit emailed code */
.otp-row { display: flex; gap: 8px; }
.otp-box {
  /* width:0 alongside flex-basis:0 — an input's intrinsic width is otherwise its
     default size attribute, and six of them are wider than a phone. */
  flex: 1 1 0; width: 0; min-width: 0; height: 52px; text-align: center;
  font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 600;
  background: var(--bg-input); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--t), box-shadow var(--t);
  -webkit-appearance: none; appearance: none;
}
.otp-box:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.otp-box.filled { border-color: var(--accent-line); background: var(--bg-raised); }
.otp-note { font-size: var(--fs-sm); color: var(--text-muted); }
.otp-note b { color: var(--text-primary); font-family: var(--font-mono); }
.otp-countdown { font-variant-numeric: tabular-nums; }

@media (min-width: 900px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr) minmax(420px, 46%); align-items: center; gap: 40px; padding-inline: max(40px, 10vw); }
  .auth-aside { display: block; border-right: 1px solid var(--border-subtle); padding-right: 40px; }
  .auth-aside .lede { color: var(--text-secondary); font-size: var(--fs-lg); max-width: 34ch; margin-top: 18px; line-height: 1.5; }
  .auth-aside .facts { margin-top: 22px; display: grid; gap: 0; border-top: 1px solid var(--border-hairline); }
  .auth-aside .facts div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--border-hairline); font-size: var(--fs-sm); color: var(--text-muted); }
  .auth-aside .facts div b { color: var(--text-primary); font-weight: 500; }
  /* A stretched code box looks like a text field, not six digits: cap the row so the
     boxes stay roughly square and the group reads as one instrument. */
  .otp-row { max-width: 320px; }
  .otp-box { height: 50px; }
}
@media (max-width: 899px) { .auth-aside { display: none; } }

/* ============================================================================
   APP LAYOUT — mobile first: top bar, content, bottom tab bar
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) auto minmax(0, 1fr) auto;
  grid-template-areas: "topbar" "banner" "main" "nav";
  height: var(--app-h);
  padding-top: env(safe-area-inset-top);
  background: var(--bg-canvas);
}
.app-brand { display: none; }

/* An opaque bar with its own divider. It was translucent and blurred for a while, which
   is the look of a template: everything scrolling under a frosted strip is harder to
   read, and the columns below already have their own rules to separate them. */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 8px;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  min-width: 0;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: relative; z-index: 30;
}
.topbar .tb-title { font-size: var(--fs-lg); font-weight: 650; letter-spacing: var(--tracking-tight); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .tb-spacer { flex: 1 1 auto; }
.global-search {
  display: none;                 /* the inbox has its own search on small screens */
  align-items: center; gap: 8px; height: 36px; padding: 0 11px;
  background: var(--bg-surface-2); border: 1px solid transparent; border-radius: var(--r-sm); color: var(--text-muted);
  transition: background var(--t), border-color var(--t), box-shadow var(--t);
}
.global-search:hover { background: var(--bg-surface-3); }
.global-search:focus-within { border-color: var(--accent-line); box-shadow: var(--ring); background: var(--bg-raised); }
.global-search svg { width: 15px; height: 15px; flex: none; }
.global-search input { border: 0; background: transparent; outline: none; width: 100%; min-width: 0; color: var(--text-primary); font-size: var(--fs-md); }
.global-search input[type="search"] { -webkit-appearance: none; appearance: none; border-radius: 0; }
.global-search kbd { font-family: var(--font-mono); font-size: var(--fs-xxs); color: var(--text-muted);
  border: 1px solid var(--border-strong); border-radius: var(--r-xs); padding: 1px 5px; background: var(--bg-surface); }

.icon-btn {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--r-sm); color: var(--text-secondary);
  transition: background var(--t), color var(--t), border-color var(--t);
  position: relative; touch-action: manipulation;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-subtle); }
.icon-btn:active { background: var(--bg-selected); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot-badge {
  position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-full);
  background: var(--bad); color: #fff; font-size: var(--fs-xxs); font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--bg-surface); font-family: var(--font-mono);
}
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 3px; border-radius: var(--r-sm);
  border: 1px solid var(--border-subtle); background: var(--bg-surface);
  transition: border-color var(--t), background var(--t), box-shadow var(--t); touch-action: manipulation;
}
.user-chip:hover { border-color: var(--border-strong); background: var(--bg-raised); }
.user-chip .avatar { width: 28px; height: 28px; font-size: var(--fs-xs); }
.user-chip .uc-meta { line-height: 1.15; text-align: left; }
.user-chip .uc-meta b { font-size: var(--fs-sm); display: block; }
.user-chip .uc-meta span { font-size: var(--fs-xxs); color: var(--text-muted); }
/* Below a small phone's width the name in the chip is what squeezes the page title to
   "Inb…". The menu still opens with the full identity; the avatar is enough here. */
@media (max-width: 560px) {
  .user-chip .uc-meta { display: none; }
  .user-chip { padding: 4px 6px; }
}

/* nav — the phone gets a bottom tab bar; the rail is built from the same items but
   only exists from 900px up, where there is width to show every section at once. */
.sidenav { display: none; }
.tabbar {
  grid-area: nav;
  display: flex; flex-direction: row; align-items: stretch;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--sidebar-line);
  padding: 0 env(safe-area-inset-left) env(safe-area-inset-bottom) env(safe-area-inset-right);
  gap: 0;
}
.nav-group-label { display: none; }
.nav-item {
  flex: 1 1 0; min-width: 0; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 0 8px; position: relative;
  color: var(--sidebar-fg); font-size: var(--fs-xxs); font-weight: 600; letter-spacing: .02em;
  touch-action: manipulation; user-select: none;
  transition: color var(--t), background var(--t); text-decoration: none;
}
.nav-item svg { width: 20px; height: 20px; opacity: .75; transition: opacity var(--t); }
.nav-item .nav-label { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { color: var(--sidebar-fg-active); background: var(--sidebar-hover); text-decoration: none; }
.nav-item.active { color: var(--sidebar-fg-active); background: var(--sidebar-active); }
.nav-item.active svg { opacity: 1; color: var(--accent-on-dark); }
.nav-item.active::after { content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 2px; background: var(--accent-on-dark); }
.nav-item .count {
  position: absolute; top: 6px; right: calc(50% - 22px);
  font-family: var(--font-mono); font-size: var(--fs-xxs); font-weight: 700; line-height: 1;
  color: var(--accent-ink); background: var(--accent-on-dark);
  border-radius: var(--r-full); padding: 2px 5px; min-width: 17px; text-align: center;
}
.sidenav .side-foot { display: none; }

/* The install banner lives in the grid, not in the toast stack: it stays up until it is
   dismissed, and a permanently floating panel lands on the composer's send button. In
   flow it pushes the workspace down instead of covering it, and an empty slot costs 0px. */
.banner-slot { grid-area: banner; }
.banner-slot:empty { display: none; }

.main { grid-area: main; overflow: hidden; position: relative; min-height: 0; background: var(--bg-canvas);
  /* landscape notch: keeps page + inbox + composer clear of the cutout (env() is 0 in portrait and on desktop) */
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.scroll-y { overflow-y: auto; height: 100%; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.page { padding: 20px 14px calc(30px + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .ph-text h1 { font-size: var(--fs-2xl); }
.page-head .ph-text p { color: var(--text-muted); margin-top: 5px; font-size: var(--fs-sm); }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* desktop: the ledger rail returns, the tab bar goes away */
@media (min-width: 900px) {
  .layout {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) auto minmax(0, 1fr);
    grid-template-areas: "brand topbar" "banner banner" "nav main";
  }
  .app-brand {
    grid-area: brand; display: flex; align-items: center; gap: 10px; padding: 0 14px;
    background: var(--sidebar-bg); color: var(--sidebar-fg);
    border-right: 1px solid var(--sidebar-line);
  }
  .app-brand .mark { width: 32px; height: 32px; flex: none; border-radius: var(--r-md); display: grid; place-items: center; background: rgba(247, 245, 240, 0.07); color: var(--accent-on-dark); box-shadow: inset 0 0 0 1px rgba(247, 245, 240, .08); }
  .app-brand .mark svg { width: 19px; height: 19px; }
  .app-brand .wm { line-height: 1.05; min-width: 0; }
  .app-brand .wm b { font-size: var(--fs-lg); letter-spacing: var(--tracking-tight); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--sidebar-fg-active); }
  .app-brand .wm span { font-size: var(--fs-xxs); color: var(--sidebar-fg); font-weight: 700; letter-spacing: var(--tracking-label); }

  .topbar { padding: 0 max(18px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left)); gap: 12px; }
  .topbar .tb-title { font-size: var(--fs-lg); margin-right: 2px; }
  .global-search { display: flex; min-width: 200px; max-width: 340px; flex: 1 1 200px; height: 36px; }
  .user-chip { padding: 4px 12px 4px 4px; }
  .user-chip .avatar { width: 30px; height: 30px; }

  .sidenav {
    grid-area: nav;
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    overflow-y: auto; overflow-x: hidden;
    padding: 14px 10px 16px; border-top: 0; border-right: 1px solid var(--sidebar-line);
    background: var(--sidebar-bg);
  }
  .tabbar { display: none; }
  .nav-group-label {
    display: block; font-size: var(--fs-xxs); font-weight: 700; letter-spacing: var(--tracking-label); text-transform: uppercase;
    color: rgba(183, 176, 161, 0.6); padding: 16px 10px 6px;
  }
  .nav-item {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 11px;
    min-width: 0; height: 38px; padding: 0 11px; border-radius: var(--r-sm); font-size: var(--fs-md); letter-spacing: 0;
  }
  .nav-item svg { width: 18px; height: 18px; }
  .nav-item .nav-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* one fill and one edge: the lit ring this had as well was the same state announced
     three ways, which is how a rail starts looking like it has never been used */
  .nav-item.active::after { content: ""; position: absolute; left: 0; right: auto; top: 8px; bottom: 8px; width: 2px; height: auto; border-radius: 0 2px 2px 0; }
  .nav-item .count { position: static; color: var(--sidebar-fg-active); background: rgba(53, 201, 165, 0.24); }
  .sidenav .side-foot { display: block; margin-top: auto; padding-top: 14px; }
  .page { padding: 26px 26px 56px; }
}

/* ============================================================================
   PRIMITIVES
   ========================================================================== */
.card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-lg);
  transition: border-color var(--t);
}
.card.pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border-hairline); }
.card-head h3 { font-size: var(--fs-lg); }
.card-head .ch-sub { color: var(--text-muted); font-size: var(--fs-xs); }
.card-body { padding: 18px; }
.card-grid { display: grid; gap: 16px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 760px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 640px) and (max-width: 759px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 760px) and (max-width: 899px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* buttons — flat, one border, one tone change on hover. This block spent a while with a
   gradient face, a glow and a 1px lift on hover; that is a template's idea of a button and
   it made the primary action look like every other screenshot on the internet. The height
   is the only thing that moved from the original: 38px fits the denser type scale. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-surface); color: var(--text-primary);
  font-weight: 550; font-size: var(--fs-md); white-space: nowrap;
  transition: background var(--t), border-color var(--t), color var(--t);
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: transparent; }
.btn.outline { background: transparent; }
.btn.sm { height: 31px; padding: 0 11px; font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn.sm svg { width: 14px; height: 14px; }
.btn.lg { height: 46px; padding: 0 20px; font-size: var(--fs-lg); border-radius: var(--r-md); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .48; cursor: not-allowed; }
.btn.loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.loading::after { content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: spin .6s linear infinite; }
.btn.loading:not(.primary):not(.danger)::after { border-color: var(--border-strong); border-top-color: var(--text-secondary); }
/* A decision button must keep its words while it works — .loading hides the label, and an
   operator who clicked "Approve" needs to read that it is still going, not guess. */
.btn.is-busy { cursor: progress; opacity: .82; }
.btn.is-busy .spinner { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* segmented control — a tray the selected option sits proud of */
.segmented { display: inline-flex; background: var(--bg-surface-2); border: 1px solid var(--border-subtle); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 6px 13px; border-radius: var(--r-xs); color: var(--text-muted); font-weight: 550; font-size: var(--fs-sm); transition: background var(--t), color var(--t); touch-action: manipulation; }
.segmented button.on { background: var(--bg-raised); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--border-subtle); }
.segmented button:hover:not(.on) { color: var(--text-primary); background: var(--bg-hover); }

/* form fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); letter-spacing: .005em; }
.field .hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field .err { font-size: var(--fs-xs); color: var(--bad); }
.input, .select, .textarea {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-strong); color: var(--text-primary);
  border-radius: var(--r-md); padding: 0 12px; height: 42px; font-size: var(--fs-md);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  -webkit-appearance: none; appearance: none;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.textarea { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--bg-raised); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input.invalid, .textarea.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.input[type="search"] { -webkit-appearance: none; appearance: none; }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238a8578' stroke-width='2'%3E%3Cpath d='M3 5.5 7 9.5 11 5.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > * { flex: 1 1 180px; min-width: 0; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
.checkbox { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; -webkit-user-select: none; user-select: none; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }

/* iOS auto-zooms the viewport when a focused input is under 16px */
@media (hover: none) and (pointer: coarse) {
  .input, .select, .textarea, .otp-box, .global-search input, .composer textarea { font-size: 16px; }
  .otp-box { font-size: var(--fs-xl); }
}

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 40px; height: 23px; border-radius: var(--r-full); background: var(--bg-surface-3); box-shadow: inset 0 0 0 1px var(--border-strong); transition: background var(--t), box-shadow var(--t); flex: none; position: relative; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--bg-raised); box-shadow: inset 0 0 0 1px var(--border-hairline); transition: transform var(--dur-2) var(--ease-out); }
.switch input:checked + .track { background: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }
.switch .sw-label { font-size: var(--fs-sm); color: var(--text-secondary); }

/* chips / badges — hairline rectangles, not pills of colour. The colour carries the meaning
   and the border is what keeps a tinted chip off a tinted background; rounding them into
   capsules is the single most recognisable sign of a design nobody argued about. */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 7px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 600; background: var(--neutral-bg); color: var(--neutral);
  border: 1px solid var(--neutral-line); white-space: nowrap;
}
.chip .cdot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip.removable button { display: inline-grid; place-items: center; border: 0; background: transparent; color: inherit; opacity: .6; padding: 0; width: 16px; height: 16px; margin-right: -3px; }
.chip.removable button:hover { opacity: 1; }
.chip.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-line); }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.chip.bad  { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad-line); }
.chip.info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }
.chip.grey { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.chip.teal { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }
[data-theme="dark"] .chip.teal { color: var(--accent); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: var(--r-xs);
  font-size: var(--fs-xxs); font-weight: 700; letter-spacing: var(--tracking-label); text-transform: uppercase;
  background: var(--neutral-bg); color: var(--neutral); border: 1px solid var(--neutral-line); }
.badge .bdot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.open     { background: var(--chip-open-bg);     color: var(--chip-open);     border-color: var(--accent-line); }
.badge.pending  { background: var(--chip-pending-bg);  color: var(--chip-pending);  border-color: var(--warn-line); }
.badge.resolved { background: var(--chip-resolved-bg); color: var(--chip-resolved); border-color: var(--ok-line); }
.badge.archived { background: var(--neutral-bg);       color: var(--neutral);       border-color: var(--neutral-line); }
.badge.auto     { background: var(--info-bg);          color: var(--info);          border-color: var(--info-line); }
.badge.human    { background: var(--accent-soft);      color: var(--accent-strong); border-color: var(--accent-line); }
.badge.paused   { background: var(--warn-bg);          color: var(--warn);          border-color: var(--warn-line); }
.badge.failed, .badge.urgent { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.badge.sent, .badge.new { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
[data-theme="dark"] .badge.human { color: var(--accent); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 600; background: var(--bg-surface-2); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); }
.priority-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.priority-low    { background: var(--neutral); }
.priority-normal { background: var(--info); }
.priority-high   { background: var(--warn); }
.priority-urgent { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }

/* avatar — a rounded square of colour with mono initials, so two people who share an
   initial read as different rows. Circles were tried and pushed the whole screen toward
   the same soft blob shape as the chips and the pills. */
.avatar { width: 36px; height: 36px; border-radius: var(--r-sm); flex: none; display: grid; place-items: center;
  font-weight: 700; color: var(--text-inverse); font-size: var(--fs-sm); background: var(--neutral);
  text-transform: uppercase; -webkit-user-select: none; user-select: none; font-family: var(--font-mono);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
.avatar.sm { width: 28px; height: 28px; font-size: var(--fs-xs); }
.avatar.lg { width: 48px; height: 48px; font-size: var(--fs-xl); }
.avatar.xl { width: 62px; height: 62px; font-size: var(--fs-2xl); }

/* tables */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border-subtle); background: var(--bg-surface); isolation: isolate; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
table.data th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: var(--fs-xxs);
  letter-spacing: var(--tracking-label); text-transform: uppercase; padding: 10px 15px; background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-subtle); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.data td { padding: 11px 15px; border-bottom: 1px solid var(--border-hairline); vertical-align: middle; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tr.clickable { cursor: pointer; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
@media (hover: hover) { table.data tbody tr:hover { background: var(--bg-hover); } table.data tbody tr.clickable:hover { background: var(--bg-selected); } }
/* Sticky headers are unreliable inside a Safari overflow-x box, and on a phone a
   wide table is worse than a stacked one — the views keep the wrap, we drop the pin. */
@media (max-width: 639px) { table.data th { position: static; } }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-subtle); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; border: 0; background: transparent; color: var(--text-muted); font-weight: 550; font-size: var(--fs-md);
  position: relative; white-space: nowrap; touch-action: manipulation; border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: color var(--t), background var(--t); }
.tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab.on { color: var(--accent-strong); }
[data-theme="dark"] .tab.on { color: var(--accent); }
.tab.on::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.tabpanel { padding-top: 18px; }

/* toolbar / filters */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .grow { flex: 1 1 auto; min-width: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-inline { position: relative; flex: 1 1 160px; min-width: 0; }
.search-inline svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-muted); }
.search-inline .input { padding-left: 34px; height: 38px; border-radius: var(--r-sm); }

/* empty / loading / error states */
/* align-content:center matters: with a stretched height, grid's default align-content
   is stretch, which spreads the icon, heading and note across the whole pane. */
.state { display: grid; place-items: center; align-content: center; text-align: center; padding: 52px 20px; color: var(--text-muted); }
.state .state-ic { width: 52px; height: 52px; border-radius: var(--r-full); display: grid; place-items: center; background: var(--bg-surface-2); color: var(--text-muted); margin-bottom: 14px; border: 1px solid var(--border-hairline); }
.state .state-ic svg { width: 24px; height: 24px; }
.state h4 { color: var(--text-primary); font-size: var(--fs-lg); margin-bottom: 4px; }
.state p { max-width: 44ch; font-size: var(--fs-sm); line-height: 1.55; }
.state .btn { margin-top: 16px; }
.skeleton { background: var(--skeleton); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: var(--r-sm); color: transparent !important; }
.skeleton.line { height: 12px; margin: 9px 0; }
.skeleton.block { height: 62px; margin: 11px 0; border-radius: var(--r-md); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .6s linear infinite; }
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 200; opacity: 0; transition: width .3s var(--ease), opacity .3s; }
.loading-bar.on { opacity: 1; }

/* modal — sheet on a phone, centered box on a desktop */
.modal-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: var(--overlay);
  display: grid; place-items: end center; z-index: 100; animation: fade var(--dur-2); }
.modal { width: 100%; max-width: 560px; max-height: calc(var(--flow-h) - 24px); background: var(--bg-surface);
  border: 1px solid var(--border-subtle); border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-xl); display: flex; flex-direction: column; animation: sheetup var(--dur-3) var(--ease-out); overflow: hidden; }
.modal.wide { max-width: 840px; }
.modal.slim { max-width: 420px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border-hairline); background: var(--bg-surface-2); }
.modal-head h3 { font-size: var(--fs-lg); }
.modal-head .mh-sub { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 2px; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; -webkit-overflow-scrolling: touch; }
.modal-foot { padding: 13px 18px calc(13px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border-hairline); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-surface-2); flex-wrap: wrap; }
.modal-close { width: 34px; height: 34px; border-radius: var(--r-full); border: 0; color: var(--text-muted); display: grid; place-items: center; flex: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: background var(--t), color var(--t); }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .modal-backdrop { place-items: center; padding: 24px; }
  .modal { border-radius: var(--r-lg); animation: fade var(--dur-2); max-height: calc(var(--flow-h) - 48px); }
  .modal-foot { padding-bottom: 13px; }
}

/* drawer */
.drawer-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: var(--overlay); z-index: 90; animation: fade var(--dur-2); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle); box-shadow: var(--shadow-xl); z-index: 95; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); animation: slidein var(--dur-3) var(--ease-out); }
@keyframes slidein { from { transform: translateX(40px); opacity: .6; } to { transform: none; opacity: 1; } }

/* toast */
/* 130, not "as high as possible": a menu opened from the tab bar has to clear the
   install bar and the toasts, and a toast that eats the menu is unusable. */
.toast-stack { position: fixed; right: 10px; left: 10px; bottom: calc(12px + var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 130; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 10px; width: 100%; max-width: 400px; margin-left: auto; padding: 12px 14px;
  background: var(--bg-raised); border: 1px solid var(--border-subtle); border-left-width: 3px; border-left-color: var(--neutral-line);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); animation: toastin var(--dur-3) var(--ease-out); pointer-events: auto; }
@keyframes toastin { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast .t-ic { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--neutral); }
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-body b { display: block; font-size: var(--fs-md); margin-bottom: 1px; }
.toast .t-body span { font-size: var(--fs-sm); color: var(--text-muted); }
.toast .t-x { border: 0; background: transparent; color: var(--text-muted); font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: var(--r-xs); }
.toast .t-x:hover { color: var(--text-primary); background: var(--bg-hover); }
.toast.success { border-left-color: var(--ok); }   .toast.success .t-ic { color: var(--ok); }
.toast.error   { border-left-color: var(--bad); }  .toast.error .t-ic { color: var(--bad); }
.toast.info    { border-left-color: var(--info); } .toast.info .t-ic { color: var(--info); }
.toast.warn    { border-left-color: var(--warn); } .toast.warn .t-ic { color: var(--warn); }
@media (min-width: 900px) {
  .toast-stack { left: auto; right: 20px; bottom: 20px; }
  .toast { margin-left: 0; }
}

/* dropdown menu */
.menu { min-width: 210px; background: var(--bg-raised); border: 1px solid var(--border-subtle); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: 5px; animation: fade var(--dur-1);
  /* a tall menu must scroll inside a landscape phone, not run off the viewport */
  max-height: calc(var(--flow-h) - 120px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 11px;
  border: 0; background: transparent; border-radius: var(--r-sm); color: var(--text-primary); font-weight: 400; font-size: var(--fs-md);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: background var(--t-fast), color var(--t-fast); }
.menu button:hover, .menu a:hover { background: var(--bg-hover); text-decoration: none; }
.menu svg { width: 15px; height: 15px; color: var(--text-muted); flex: none; }
.menu .sep { height: 1px; background: var(--border-hairline); margin: 5px 8px; }
.menu .danger, .menu .danger svg { color: var(--bad); }
.menu-label { font-size: var(--fs-xxs); color: var(--text-muted); text-transform: uppercase; letter-spacing: var(--tracking-label); font-weight: 700; padding: 8px 11px 4px; }

/* install banner (PWA) — in-flow strip, see .banner-slot
   The text takes the rail's own foreground tokens, not --text-inverse: that alias flips to
   near-black in dark mode while --sidebar-bg stays dark in both, and the strip went
   unreadable the moment the theme did. */
.install-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%;
  padding: 11px max(14px, env(safe-area-inset-right)) 11px max(14px, env(safe-area-inset-left));
  background: var(--sidebar-bg); color: var(--sidebar-fg-active);
  border-bottom: 1px solid var(--sidebar-line); box-shadow: var(--shadow-md); }
.install-bar .ib-text { flex: 1 1 180px; min-width: 0; }
.install-bar .ib-text b { display: block; font-size: var(--fs-md); }
.install-bar .ib-text span { font-size: var(--fs-xs); color: var(--sidebar-fg); }
.install-bar .btn { background: transparent; border-color: rgba(247, 245, 240, .3); color: var(--sidebar-fg-active); box-shadow: none; }
.install-bar .btn:hover { background: rgba(247, 245, 240, .1); }
.install-bar .btn.primary { background: var(--accent-on-dark); border-color: var(--accent-on-dark); color: var(--accent-ink); }

/* misc */
.divider { height: 1px; background: var(--border-hairline); margin: 6px 0; }
.kbd { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--bg-surface-2); border: 1px solid var(--border-subtle); border-radius: var(--r-xs); padding: 1px 6px; color: var(--text-secondary); }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-4 { gap: 4px } .gap-6 { gap: 6px } .gap-8 { gap: 8px } .gap-10 { gap: 10px } .gap-12 { gap: 12px } .gap-14 { gap: 14px } .gap-16 { gap: 16px } .gap-20 { gap: 20px }
.mt-4 { margin-top: 4px } .mt-8 { margin-top: 8px } .mt-12 { margin-top: 12px } .mt-16 { margin-top: 16px } .mt-20 { margin-top: 20px } .mt-24 { margin-top: 24px }
.mb-8 { margin-bottom: 8px } .mb-12 { margin-bottom: 12px } .mb-16 { margin-bottom: 16px }
.space-between { justify-content: space-between }
.text-right { text-align: right }

/* key-value list */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border-hairline); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-muted); }
.kv .v { color: var(--text-primary); font-weight: 500; text-align: right; }

/* ============================================================================
   INBOX — one pane at a time on a phone, three columns from 1200px
   ========================================================================== */
.inbox { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; min-height: 0; }
.inbox-list { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-surface); }
.inbox:not(.show-list) .inbox-list { display: none; }
.inbox .thread { display: none; }
.inbox:not(.show-list) .thread { display: flex; }
.inbox-list-head { padding: 12px 13px; border-bottom: 1px solid var(--border-hairline); }
.conv-scroll { overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
/* A thread row is a ruled line in a list, not a card in a stack. Rounded rows with their own
   hover shadow cost vertical room, make the selected row one of four signals instead of one,
   and are the reason a chat list stops looking like a work queue. */
.conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--border-hairline); cursor: pointer; position: relative; touch-action: manipulation; }
.conv:hover { background: var(--bg-hover); }
.conv.active { background: var(--bg-selected); }
.conv.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.conv .c-main { flex: 1; min-width: 0; }
.conv .c-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv .c-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .c-time { font-size: var(--fs-xxs); color: var(--text-muted); flex: none; font-family: var(--font-mono); }
.conv .c-preview { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; line-height: 1.45; }
.conv .c-badges { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; align-items: center; }
.conv .c-flag { position: absolute; right: 11px; bottom: 11px; width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg-surface); }
.conv .unread { background: var(--accent); color: var(--accent-ink); font-family: var(--font-mono); font-size: var(--fs-xxs); font-weight: 700;
  border-radius: var(--r-full); min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; }

.thread { flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-canvas); }
.thread-head { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); background: var(--bg-surface); display: flex; align-items: center; gap: 10px; }
.thread-head .th-id { min-width: 0; }
.thread-head .th-id b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-md); font-weight: 650; }
.thread-head .th-id span { font-size: var(--fs-xs); color: var(--text-muted); font-family: var(--font-mono); }
.thread-head .th-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.thread-head .th-back { display: grid; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 12px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background-image: radial-gradient(var(--paper-grid) 1px, transparent 1px); background-size: 22px 22px; }
.day-sep { align-self: center; margin: 12px 0; }
.day-sep span { font-size: var(--fs-xxs); font-weight: 600; color: var(--text-muted); background: var(--bg-surface);
  padding: 3px 12px; border-radius: var(--r-full); border: 1px solid var(--border-subtle); font-family: var(--font-mono); }
.msg { display: flex; max-width: 88%; margin-bottom: 3px; }
.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; }
/* The tail corner is what makes a bubble a bubble: one corner at 5px against 14px
   reads as pointed without an SVG. */
.msg .bubble { padding: 9px 12px; border-radius: var(--r-lg); position: relative; word-wrap: break-word; overflow-wrap: anywhere;
  background: var(--bg-raised); border: 1px solid var(--border-subtle); border-bottom-left-radius: var(--r-xs); }
.msg.out .bubble { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text-primary); border-bottom-left-radius: var(--r-lg); border-bottom-right-radius: var(--r-xs); }
.msg .m-text { font-size: var(--fs-md); line-height: 1.45; white-space: pre-wrap; }
.msg .m-meta { display: flex; align-items: center; gap: 5px; font-size: var(--fs-xxs); color: var(--text-muted); margin-top: 3px; justify-content: flex-end; font-family: var(--font-mono); }
.msg .m-meta svg { width: 13px; height: 13px; }
.msg.note { align-self: center; max-width: 96%; }
.msg.note .bubble { background: var(--warn-bg); color: var(--warn); border-radius: var(--r-md); border: 1px dashed var(--warn-line); }
.msg.automated .bubble { border-style: dashed; border-color: var(--info-line); }
.msg .m-who { font-size: var(--fs-xxs); font-weight: 700; color: var(--accent-strong); margin-bottom: 3px; letter-spacing: .02em; }
[data-theme="dark"] .msg .m-who { color: var(--accent); }
.msg.failed .bubble { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad-line); }
.msg-media { border-radius: var(--r-md); overflow: hidden; margin: 2px 0 6px; max-width: 300px; background: var(--bg-surface-2); border: 1px solid var(--border-hairline); }
.msg-media img, .msg-media video { width: 100%; height: auto; display: block; }
.msg-media .doc { display: flex; align-items: center; gap: 10px; padding: 11px 13px; }
.msg-status { display: inline-flex; }
.status-checks { color: var(--text-muted); }
.status-checks.read { color: var(--accent); }

.composer { border-top: 1px solid var(--border-subtle); background: var(--bg-surface); padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px -12px rgba(25, 24, 20, .18); }
.composer .cr-row { display: flex; gap: 4px; margin-bottom: 7px; flex-wrap: wrap; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-width: 0; min-height: 42px; max-height: 140px; resize: none; border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); padding: 10px 13px; background: var(--bg-input); line-height: 1.4;
  transition: border-color var(--t), box-shadow var(--t); }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--bg-raised); }
.composer .send { width: 42px; height: 42px; border-radius: var(--r-sm); flex: none; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; touch-action: manipulation; transition: background var(--t); }
.composer .send:hover { background: var(--accent-strong); }
.composer .send:disabled { background: var(--bg-surface-3); color: var(--text-muted); cursor: not-allowed; }
.composer .send svg { width: 18px; height: 18px; }
.composer .mode-banner { display: flex; align-items: center; gap: 7px; font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: 7px; }

/* staged attachments (media composer) */
.file-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.file-chip { display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 7px 10px;
  border: 1px solid var(--border-subtle); border-radius: var(--r-md); background: var(--bg-surface-2); font-size: var(--fs-xs); }
.file-chip.uploading { border-color: var(--accent-line); background: var(--accent-soft); }
.file-chip.failed { border-color: var(--bad-line); background: var(--bad-bg); }
.file-chip .fc-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-chip .fc-bar { height: 3px; background: var(--border-hairline); border-radius: var(--r-full); overflow: hidden; margin-top: 4px; }
.file-chip .fc-bar i { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }
.file-chip .fc-x { color: var(--text-muted); padding: 2px; border-radius: var(--r-xs); }

/* small icon button: the bubble and chip controls, which must not outsize what they act on. */
.icon-btn.xs { width: 28px; height: 28px; border-radius: var(--r-sm); }
.icon-btn.xs svg { width: 14px; height: 14px; }
/* The 44px floor further up cannot widen these: this rule is later in the sheet, so `.xs` wins
   the cascade and a finger would be aimed at 28px. The glyph stays small — the hit area is what
   grows, drawn as a transparent overlay so the row it sits in does not reflow. */
@media (hover: none) and (pointer: coarse) {
  .icon-btn.xs { position: relative; }
  .icon-btn.xs::after { content: ""; position: absolute; inset: -9px; }
}

/* per-bubble actions — always tappable, because a hover-only affordance is invisible on a phone */
.msg .m-actions { display: flex; gap: 2px; justify-content: flex-end; margin-top: 2px; opacity: .45; transition: opacity var(--t); }
.msg:hover .m-actions, .msg:focus-within .m-actions { opacity: 1; }
@media (hover: none) { .msg .m-actions { opacity: 1; } }
.msg .m-actions .icon-btn.xs { color: var(--text-muted); }
.msg .m-actions .icon-btn.xs:hover { color: var(--accent-strong); background: var(--bg-hover); }

/* the message being quoted inside a bubble */
.msg .m-quote { border-left: 3px solid var(--accent-line); padding: 4px 0 4px 9px; margin-bottom: 6px;
  background: var(--bg-surface-2); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.msg .m-quote .mq-who { font-size: var(--fs-xxs); font-weight: 700; color: var(--accent-strong); }
.msg .m-quote .mq-text { font-size: var(--fs-xs); color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
[data-theme="dark"] .msg .m-quote .mq-who { color: var(--accent); }

/* composer context strips: the reply target, and the AI suggestion that is not yet sent */
.reply-bar, .draft-bar { display: flex; align-items: center; gap: 8px; padding: 8px 11px; margin-bottom: 9px;
  border: 1px solid var(--border-subtle); border-radius: var(--r-md); background: var(--bg-surface-2); font-size: var(--fs-xs); }
.reply-bar { border-left: 3px solid var(--accent); background: var(--accent-soft); }
.reply-bar > svg, .draft-bar > svg { color: var(--accent-strong); flex: none; }
.reply-bar .rb-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; flex: 1; }
.reply-bar .rb-body b { font-size: var(--fs-xs); }
.reply-bar .rb-quote { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-bar { border-left: 3px solid var(--info); background: var(--info-bg); }
.draft-bar .small { flex: 1; min-width: 0; }
.draft-bar .spinner { width: 14px; height: 14px; }

/* the thread accepts a dropped file */
.thread.dropping .messages { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--accent-soft); }

/* ticket vocabulary shares the status badge shell, so a case and a chat read the same way */
.badge.on_hold { background: var(--chip-pending-bg); color: var(--chip-pending); }
.badge.closed { background: var(--neutral-bg); color: var(--neutral); }
.badge.medium { background: var(--neutral-bg); color: var(--neutral); }
.badge.high { background: var(--warn-bg); color: var(--warn); }
.badge.low { background: var(--info-bg); color: var(--info); }

/* conversation detail rail — full-screen sheet on a phone */
.conv-detail { position: absolute; top: 0; right: 0; bottom: 0; width: 100%; border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface); overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch;
  transform: translateX(100%); transition: transform var(--dur-3) var(--ease-out); box-shadow: var(--shadow-xl); z-index: 20; }
.conv-detail.open { transform: none; }
.cd-section { padding: 16px; border-bottom: 1px solid var(--border-hairline); }
.cd-section h4 { font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-muted); margin-bottom: 11px; font-weight: 700; }
.cd-hero { padding: 22px 16px; text-align: center; border-bottom: 1px solid var(--border-hairline); background: var(--bg-surface-2); }
.cd-hero .avatar { margin: 0 auto 12px; }
.cd-hero .cd-name { font-weight: 650; font-size: var(--fs-lg); letter-spacing: var(--tracking-tight); }
.cd-hero .cd-num { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 3px; font-family: var(--font-mono); }

@media (min-width: 900px) {
  .inbox { grid-template-columns: var(--inbox-list-w) minmax(0, 1fr); }
  .inbox-list { display: flex !important; border-right: 1px solid var(--border-subtle); }
  .inbox .thread { display: flex !important; }
  .inbox[data-detail="off"] { grid-template-columns: var(--inbox-list-w) minmax(0, 1fr); }
  .thread-head { padding: 11px 18px; }
  .thread-head .th-back { display: none; }
  .messages { padding: 20px 24px calc(20px + env(safe-area-inset-bottom)); }
  .msg { max-width: 74%; }
  .composer { padding: 14px 18px; }
  .conv-detail { position: static; width: auto; transform: none; box-shadow: none; overflow-y: auto;
    border-left: 1px solid var(--border-subtle); display: none; }
  .inbox:not([data-detail="off"]) .conv-detail { display: block; }
  .inbox:not([data-detail="off"]) { grid-template-columns: var(--inbox-list-w) minmax(0, 1fr) var(--inbox-detail-w); }
}
@media (min-width: 900px) and (max-width: 1199px) {
  .inbox:not([data-detail="off"]) { grid-template-columns: var(--inbox-list-w) minmax(0, 1fr); }
  .inbox .conv-detail { position: absolute; right: 0; top: 0; bottom: 0; width: 350px; display: block;
    transform: translateX(100%); box-shadow: var(--shadow-xl); z-index: 20; }
  .inbox .conv-detail.open { transform: none; }
}

/* ============================================================================
   METRICS / CHARTS — figures are mono everywhere, labels are not
   ========================================================================== */
.metric { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-md); padding: 16px; position: relative; overflow: hidden;
  }
.metric .m-label { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; display: flex; align-items: center; gap: 7px; }
.metric .m-value { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -0.025em; margin-top: 8px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.metric .m-foot { margin-top: 7px; font-size: var(--fs-xs); color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.metric .m-ic { width: 34px; height: 34px; border-radius: var(--r-md); display: grid; place-items: center; position: absolute; top: 14px; right: 14px; background: var(--bg-surface-2); color: var(--text-muted); border: 1px solid var(--border-hairline); }
.metric .m-ic svg { width: 17px; height: 17px; }
.trend-up { color: var(--ok); } .trend-down { color: var(--bad); }
.trend-up svg, .trend-down svg { width: 13px; height: 13px; }

.chart-wrap { position: relative; width: 100%; min-width: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-secondary); }
.legend .lg i { width: 9px; height: 9px; border-radius: 3px; }
.spark { width: 100%; height: 46px; display: block; }
.bar-row { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: var(--fs-sm); }
.bar-row .bl-name { width: 92px; color: var(--text-secondary); flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 8px; background: var(--bg-surface-3); border-radius: var(--r-full); overflow: hidden; box-shadow: inset 0 1px 2px rgba(25, 24, 20, .06); }
.bar-fill { height: 100%; border-radius: var(--r-full); transition: width .5s var(--ease-out); }
.bar-row .bl-val { width: 42px; text-align: right; color: var(--text-muted); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.donut-center { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center b { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.025em; font-family: var(--font-mono); }
.donut-center span { font-size: var(--fs-xxs); color: var(--text-muted); }

/* rule / item lists */
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border-hairline); transition: background var(--t-fast); }
.list-row:last-child { border-bottom: 0; }
@media (hover: hover) { .list-row:hover { background: var(--bg-hover); } }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-weight: 600; }
.list-row .lr-sub { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 3px; }
.list-row .lr-actions { display: flex; gap: 4px; align-items: center; }
.drag-handle { cursor: grab; color: var(--text-muted); }
.drag-handle:active { cursor: grabbing; }
.sortable.dragging { opacity: .5; }
.sortable.drop-target { box-shadow: inset 0 3px 0 var(--accent); }
.rule-row { border-radius: var(--r-md); }
.rule-row:hover { background: var(--bg-hover); }

.tag-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.swatch-btn { background: transparent; border: 1px solid var(--border-subtle); border-radius: var(--r-sm); padding: 3px; cursor: pointer; display: inline-flex; transition: border-color var(--t); }
.swatch-btn:hover { border-color: var(--border-strong); }

/* emergency banner */
.emergency-banner { display: flex; align-items: center; gap: 10px; padding: 11px 16px; background: var(--bad-bg); color: var(--bad); border-bottom: 1px solid var(--bad-line); font-weight: 600; font-size: var(--fs-sm); }
.emergency-banner svg { width: 17px; height: 17px; }

/* footer */
.app-footer { color: var(--text-muted); font-size: var(--fs-xs); text-align: center; padding: 20px; }

.h-full { height: 100%; }
.gap-14 { gap: 14px }

/* ============================================================================
   THE FINGER FLOOR — last, on purpose
   ----------------------------------------------------------------------------
   A media query adds no specificity, so this block has to sit after every
   component it overrides: `.composer .send { width: 42px }` in the inbox section
   silently beat the 44px rule while that rule lived near the top of the sheet, and
   the phone kept getting the desktop control. Same reason `.icon-btn.xs` and the
   chip × need an overlay rather than a size: the row they live in is the constraint.
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
  .btn { height: 44px; padding: 0 16px; }
  /* A compact button stays compact on the desk and on the phone — what grows is the hit
     area, 4px above and below, which is the part a finger actually needs. */
  .btn.sm { position: relative; }
  .btn.sm::before { content: ""; position: absolute; inset: -4px; }
  .icon-btn { width: 44px; height: 44px; }
  .composer .send { width: 44px; height: 44px; }
  /* fields first: a 42px input on a phone is not a comfort problem, it is a mis-tap
     problem, and iOS zooms the page when a focused control is small. */
  .input, .select, .textarea { min-height: 44px; }
  .search-inline .input { height: 44px; }
  .user-chip { height: 44px; }
  .tabbar { --tabbar-h: 64px; }
  .tab { min-height: 44px; }
  .otp-box { height: 56px; }
  .chip.removable button { width: 22px; height: 22px; margin-right: -6px; position: relative; }
  .chip.removable button::after { content: ""; position: absolute; inset: -12px; }
  .modal-close { width: 44px; height: 44px; }
  .menu button, .menu a { min-height: 44px; }
  .segmented button { min-height: 44px; }
}

/* ============================================================================
   REDUCED MOTION + PRINT
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  @page { margin: 14mm; }
  html, body { height: auto; overflow: visible; background: #fff; color: #000; }
  .layout { display: block; height: auto; padding: 0; }
  .sidenav, .tabbar, .topbar, .app-brand, .toast-stack, .menu, .modal-backdrop, .drawer, .drawer-backdrop,
  .page-actions, .toolbar, .filters, .tabs, .install-bar, .loading-bar, .composer, .th-actions, .conv-detail { display: none !important; }
  .main { overflow: visible; height: auto; }
  .scroll-y { overflow: visible; height: auto; }
  .page { padding: 0; max-width: none; }
  /* print flattens the whole ramp: a screen shadow is a grey smear on paper */
  .card, .metric, .table-wrap, .modal, .menu, .drawer { border: 1px solid #ccc; break-inside: avoid; box-shadow: none; }
  table.data th { position: static; }
  a { color: #000; text-decoration: none; }
  .no-print { display: none !important; }
}
