/* ============================================================================
   Frank dashboard — design system
   References for quality bar: Chatwoot (3-pane inbox density),
   Twenty (hairline borders, generous whitespace, refined type),
   Inbox Zero (calm color, meaningful status use, "why" surfacing),
   assistant-ui (message-thread typography in the detail pane).
   ========================================================================== */

/* ---------- 1. Tokens (light) ---------- */
:root {
  /* neutrals — near-white → near-black scale (Twenty-ish hairlines) */
  --c-bg:          #f7f7f8;
  --c-surface:     #ffffff;
  --c-surface-2:   #fafafa;
  --c-surface-3:   #f2f2f4;
  --c-border:      #e6e6ea;
  --c-border-soft: #ececef;
  --c-text:        #14161a;
  --c-text-mute:   #5b6070;
  --c-text-faint:  #8b90a0;

  /* accent — one blue, calm */
  --c-accent:      #2f6feb;
  --c-accent-2:    #2657c2;
  --c-accent-soft: #eaf1ff;
  --c-accent-ring: rgba(47, 111, 235, 0.28);

  /* status (used sparingly, never on chrome) */
  --c-ok:          #12855c;
  --c-ok-soft:     #e6f4ee;
  --c-warn:        #a06600;
  --c-warn-soft:   #fbf1dc;
  --c-danger:      #c8352b;
  --c-danger-soft: #fbe9e7;
  --c-info:        #2f6feb;
  --c-info-soft:   #eaf1ff;

  /* radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* spacing scale */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 40px;

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --fs-11: 11px; --fs-12: 12px; --fs-13: 13px; --fs-14: 14px;
  --fs-15: 15px; --fs-16: 16px; --fs-18: 18px; --fs-20: 20px; --fs-24: 24px;

  /* elevation */
  --shadow-1: 0 1px 2px rgba(20, 22, 26, 0.04), 0 1px 1px rgba(20, 22, 26, 0.02);
  --shadow-2: 0 6px 24px rgba(20, 22, 26, 0.10), 0 2px 6px rgba(20, 22, 26, 0.05);
  --shadow-pop: 0 12px 40px rgba(20, 22, 26, 0.16);

  /* layout */
  --rail-w:    236px;
  --rail-w-sm: 60px;
  --list-w:    360px;
}

/* ---------- 2. Tokens (dark) ---------- */
/* System-default (no explicit choice) follows prefers-color-scheme.
   An explicit choice via [data-theme] wins in either direction. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg:          #0e1013;
    --c-surface:     #16181c;
    --c-surface-2:   #191b20;
    --c-surface-3:   #1e2127;
    --c-border:      #262a31;
    --c-border-soft: #21242a;
    --c-text:        #eceef2;
    --c-text-mute:   #9aa0ad;
    --c-text-faint:  #6b7180;

    --c-accent:      #5b8dff;
    --c-accent-2:    #7ea4ff;
    --c-accent-soft: rgba(91, 141, 255, 0.14);
    --c-accent-ring: rgba(91, 141, 255, 0.35);

    --c-ok:          #4dbf8a;
    --c-ok-soft:     rgba(77, 191, 138, 0.14);
    --c-warn:        #e0b155;
    --c-warn-soft:   rgba(224, 177, 85, 0.14);
    --c-danger:      #f07067;
    --c-danger-soft: rgba(240, 112, 103, 0.14);
    --c-info:        #5b8dff;
    --c-info-soft:   rgba(91, 141, 255, 0.14);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
    --shadow-pop: 0 20px 60px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --c-bg:          #0e1013;
  --c-surface:     #16181c;
  --c-surface-2:   #191b20;
  --c-surface-3:   #1e2127;
  --c-border:      #262a31;
  --c-border-soft: #21242a;
  --c-text:        #eceef2;
  --c-text-mute:   #9aa0ad;
  --c-text-faint:  #6b7180;
  --c-accent:      #5b8dff;
  --c-accent-2:    #7ea4ff;
  --c-accent-soft: rgba(91, 141, 255, 0.14);
  --c-accent-ring: rgba(91, 141, 255, 0.35);
  --c-ok:          #4dbf8a;
  --c-ok-soft:     rgba(77, 191, 138, 0.14);
  --c-warn:        #e0b155;
  --c-warn-soft:   rgba(224, 177, 85, 0.14);
  --c-danger:      #f07067;
  --c-danger-soft: rgba(240, 112, 103, 0.14);
  --c-info:        #5b8dff;
  --c-info-soft:   rgba(91, 141, 255, 0.14);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-pop: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* ---------- 3. Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  min-height: 100vh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--c-accent-ring); outline-offset: 2px; border-radius: var(--r-sm); }
.hidden { display: none !important; }

/* ---------- 4. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  height: 34px;
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-13);
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 60ms ease;
  white-space: nowrap;
}
.btn:hover { background: var(--c-surface-2); }
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; height: 40px; }
.btn-primary {
  background: var(--c-accent); color: #fff; border-color: transparent;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}
.btn-primary:hover { background: var(--c-accent-2); }
.btn-danger { color: var(--c-danger); }
.btn-danger:hover { background: var(--c-danger-soft); border-color: color-mix(in srgb, var(--c-danger) 25%, var(--c-border)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--c-text-mute); }
.btn-ghost:hover { color: var(--c-text); background: var(--c-surface-2); }
.btn-sm { height: 28px; padding: 0 var(--s-3); font-size: var(--fs-12); border-radius: var(--r-sm); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--r-sm);
  color: var(--c-text-mute);
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }

/* ---------- 5. Login ---------- */
.login-view {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--s-6);
  background:
    radial-gradient(1000px 600px at 20% -10%, color-mix(in srgb, var(--c-accent) 12%, transparent), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, color-mix(in srgb, var(--c-accent) 8%, transparent), transparent 60%),
    var(--c-bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: var(--s-7) var(--s-6);
  box-shadow: var(--shadow-2);
}
.brand-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--c-accent-soft);
  color: var(--c-accent);
  margin: 0 auto var(--s-4);
}
.login-title { font-size: var(--fs-24); font-weight: 650; text-align: center; letter-spacing: -0.01em; }
.login-sub { color: var(--c-text-mute); text-align: center; font-size: var(--fs-13); margin-top: var(--s-1); }
.login-form { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-6); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--fs-12); color: var(--c-text-mute); font-weight: 500; }
.field input, .field textarea, .field select {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  border-radius: var(--r-md);
  padding: 9px 12px;
  font-size: var(--fs-14);
  width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-ring);
}
.form-error { color: var(--c-danger); font-size: var(--fs-13); margin-top: var(--s-2); }

/* ---------- 6. App shell (3-pane) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
  min-height: 100vh;
  background: var(--c-bg);
}

/* Rail --------------------------------------------------------------------- */
.rail {
  grid-column: 1; /* explicit — see .detail-col comment for why */
  display: flex; flex-direction: column;
  justify-content: space-between;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: var(--s-4) var(--s-3);
  min-width: 0;
  position: sticky; top: 0; height: 100vh;
}
.rail-top { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.rail-brand {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  color: var(--c-accent);
  background: var(--c-accent-soft);
  border-radius: var(--r-md);
  margin: 0 var(--s-2) var(--s-2);
}
.rail-nav { display: flex; flex-direction: column; gap: 2px; }
.rail-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  color: var(--c-text-mute);
  font-size: var(--fs-13); font-weight: 500;
  transition: background 120ms ease, color 120ms ease;
  position: relative;
}
.rail-item:hover { background: var(--c-surface-2); color: var(--c-text); }
.rail-item.is-active { background: var(--c-accent-soft); color: var(--c-accent); }
.rail-item svg { flex: 0 0 20px; }
.rail-label { flex: 1; min-width: 0; text-align: left; }
.rail-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 18px; padding: 0 6px;
  font-size: var(--fs-11); font-weight: 600;
  color: var(--c-accent);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.rail-item.is-active .rail-badge { background: var(--c-surface); border-color: transparent; }
.rail-bottom { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2); border-top: 1px solid var(--c-border-soft); padding-top: var(--s-3); }
.mode-chip {
  flex: 1; min-width: 0;
  font-size: var(--fs-11); font-weight: 700; letter-spacing: 0.06em;
  color: var(--c-text-mute); text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-soft);
  text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mode-chip.is-auto { color: var(--c-warn); background: var(--c-warn-soft); border-color: color-mix(in srgb, var(--c-warn) 20%, var(--c-border-soft)); }
.rail-icon-btn {
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--c-text-mute);
  transition: background 120ms ease, color 120ms ease;
}
.rail-icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }

/* List column -------------------------------------------------------------- */
.list-col {
  grid-column: 2; /* explicit — see .detail-col comment for why */
  border-right: 1px solid var(--c-border);
  background: var(--c-surface);
  display: flex; flex-direction: column;
  min-width: 0;
  height: 100vh;
  position: sticky; top: 0;
}
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-3);
  border-bottom: 1px solid var(--c-border-soft);
}
.list-title { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; }
.list-title h2 { font-size: var(--fs-16); font-weight: 650; letter-spacing: -0.005em; }
.list-count { color: var(--c-text-faint); font-size: var(--fs-12); font-variant-numeric: tabular-nums; }
.list-controls { display: flex; align-items: center; gap: var(--s-1); }

/* Filter pills — All / Pending / Escalated / Failed, each with a live count */
.filter-pills {
  display: flex; align-items: center; gap: 6px;
  padding: 0 var(--s-4) var(--s-3);
  flex-wrap: wrap;
}
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-mute);
  font-size: var(--fs-12); font-weight: 600;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.filter-pill:hover { background: var(--c-surface-2); color: var(--c-text); }
.filter-pill.is-active { background: var(--c-text); color: var(--c-surface); border-color: transparent; }
.filter-pill .pill-count {
  font-variant-numeric: tabular-nums;
  font-size: 10.5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--c-surface-3); color: var(--c-text-mute);
}
.filter-pill.is-active .pill-count { background: rgba(255,255,255,0.22); color: inherit; }
.filter-pill.tone-danger:not(.is-active) .pill-count { background: var(--c-danger-soft); color: var(--c-danger); }
.filter-pill.tone-warn:not(.is-active) .pill-count { background: var(--c-warn-soft); color: var(--c-warn); }

.list-scroll { flex: 1; overflow-y: auto; scrollbar-gutter: stable; }
.list-body { display: flex; flex-direction: column; }
.list-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  column-gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border-soft);
  cursor: pointer;
  transition: background 120ms ease;
  position: relative;
}
.list-row:hover { background: var(--c-surface-2); }
.list-row.is-selected { background: var(--c-accent-soft); }
.list-row.is-selected::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  background: var(--c-accent); border-radius: 0 3px 3px 0;
}
.avatar {
  width: 34px; height: 34px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--c-surface-3);
  color: var(--c-text-mute);
  font-size: var(--fs-13); font-weight: 600;
  align-self: start;
}
.avatar.rel-colleague { background: color-mix(in srgb, var(--c-info) 14%, transparent); color: var(--c-info); }
.avatar.rel-recruiter { background: color-mix(in srgb, var(--c-warn) 14%, transparent); color: var(--c-warn); }
.avatar.rel-client    { background: color-mix(in srgb, #7c5cf5 14%, transparent);      color: #7c5cf5; }
.avatar.rel-friend    { background: color-mix(in srgb, var(--c-ok) 14%, transparent);   color: var(--c-ok); }
.avatar.rel-family    { background: color-mix(in srgb, #d956a1 14%, transparent);       color: #d956a1; }

.row-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-top { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; }
.row-name { font-weight: 600; font-size: var(--fs-14); color: var(--c-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-time { color: var(--c-text-faint); font-size: var(--fs-11); flex: 0 0 auto; margin-left: auto; }
.row-preview { color: var(--c-text-mute); font-size: var(--fs-13); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: center; gap: var(--s-2); margin-top: 4px; flex-wrap: wrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* Badges — status/decision */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px;
  border-radius: 999px;
  font-size: var(--fs-11); font-weight: 600; letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--c-surface-2);
  color: var(--c-text-mute);
  border: 1px solid var(--c-border-soft);
}
.badge-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.b-ESCALATE          { color: var(--c-danger); background: var(--c-danger-soft); border-color: transparent; }
.b-DRAFT_FOR_APPROVAL{ color: var(--c-warn);   background: var(--c-warn-soft);   border-color: transparent; }
.b-AUTO_REPLY        { color: var(--c-ok);     background: var(--c-ok-soft);     border-color: transparent; }
.b-ASK_CLARIFICATION { color: var(--c-info);   background: var(--c-info-soft);   border-color: transparent; }
.s-pending  { color: var(--c-text-mute); }
.s-sent     { color: var(--c-ok);     background: var(--c-ok-soft);     border-color: transparent; }
.s-failed   { color: var(--c-danger); background: var(--c-danger-soft); border-color: transparent; }
.s-rejected { color: var(--c-text-mute); background: var(--c-surface-3); }
.s-cancelled{ color: var(--c-text-mute); background: var(--c-surface-3); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px; border-radius: 999px;
  font-size: var(--fs-11);
  background: var(--c-surface-3); color: var(--c-text-mute);
  border: 1px solid var(--c-border-soft);
}
.chip-num { font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 10.5px; }

.empty-state {
  padding: var(--s-8) var(--s-6);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--c-text-mute); text-align: center;
}
.empty-emoji { font-size: 28px; color: var(--c-text-faint); }
.empty-title { color: var(--c-text); font-weight: 600; }
.empty-sub { color: var(--c-text-mute); font-size: var(--fs-13); max-width: 30ch; }
.spinner {
  width: 14px; height: 14px; border-radius: 999px;
  border: 2px solid var(--c-border); border-top-color: var(--c-accent);
  display: inline-block; animation: spin 0.7s linear infinite;
  margin-right: 6px; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Detail column ------------------------------------------------------------ */
.detail-col {
  /* Explicit grid-column (not relying on DOM-order auto-placement): when
     .list-col gets display:none for the Settings view, auto-placement would
     otherwise slide this into the now-vacant 2nd (collapsed, 0-width) track
     instead of the 3rd — pinning all three columns avoids that. */
  grid-column: 3;
  background: var(--c-bg);
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}
.placeholder {
  min-height: 100%;
  display: grid; place-items: center;
  padding: var(--s-6);
  color: var(--c-text-mute);
}
.placeholder-inner { max-width: 320px; text-align: center; }
.placeholder-mark {
  width: 60px; height: 60px; margin: 0 auto var(--s-4);
  border-radius: var(--r-lg);
  background: var(--c-surface-2);
  color: var(--c-text-faint);
  display: grid; place-items: center;
  border: 1px solid var(--c-border-soft);
}
.placeholder h3 { color: var(--c-text); font-size: var(--fs-16); font-weight: 600; margin-bottom: var(--s-1); }
.placeholder p { font-size: var(--fs-13); line-height: 1.55; }

.detail-body, .settings-body, .contacts-detail-body {
  padding: var(--s-5) var(--s-6);
  max-width: 780px;
  margin: 0 auto;
}

/* Detail header */
.detail-hero {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--c-border-soft);
  margin-bottom: var(--s-5);
}
.detail-avatar { width: 44px; height: 44px; font-size: var(--fs-14); }
.detail-heading { flex: 1; min-width: 0; }
.detail-name { font-size: var(--fs-18); font-weight: 650; letter-spacing: -0.005em; }
.detail-sub { color: var(--c-text-mute); font-size: var(--fs-12); margin-top: 2px; }
.detail-actions-top { display: flex; gap: var(--s-1); }

.callout {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--c-warn-soft);
  color: var(--c-text);
  border: 1px solid color-mix(in srgb, var(--c-warn) 30%, var(--c-border-soft));
  margin-bottom: var(--s-4);
  font-size: var(--fs-13);
}
.callout.danger { background: var(--c-danger-soft); border-color: color-mix(in srgb, var(--c-danger) 30%, var(--c-border-soft)); }
.callout.info { background: var(--c-info-soft); border-color: color-mix(in srgb, var(--c-info) 30%, var(--c-border-soft)); }
.callout-icon { flex: 0 0 20px; margin-top: 2px; }
.callout-body { min-width: 0; }
.callout-title { font-weight: 600; margin-bottom: 2px; }

/* Conversation thread (assistant-ui-ish) */
.thread {
  display: flex; flex-direction: column; gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.thread-msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: var(--fs-14);
  line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word;
}
.thread-msg.from-contact {
  align-self: flex-start;
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-top-left-radius: 6px;
}
.thread-msg.from-frank, .thread-msg.from-davit {
  align-self: flex-end;
  background: var(--c-accent);
  color: #fff;
  border-top-right-radius: 6px;
}
.thread-msg.from-davit { background: var(--c-text); color: var(--c-surface); }
.thread-attr {
  align-self: inherit;
  font-size: var(--fs-11);
  color: var(--c-text-faint);
  margin: 0 8px;
}
.thread-msg.from-contact + .thread-attr { align-self: flex-start; }
.thread-msg.from-frank + .thread-attr,
.thread-msg.from-davit + .thread-attr { align-self: flex-end; }

/* Draft composer */
.composer {
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.composer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--c-border-soft);
  background: var(--c-surface-2);
  font-size: var(--fs-12); color: var(--c-text-mute); font-weight: 500;
}
.composer-head-left { display: flex; align-items: center; gap: var(--s-2); }
.composer textarea {
  display: block; width: 100%;
  min-height: 110px;
  padding: var(--s-3) var(--s-4);
  border: 0;
  background: var(--c-surface);
  resize: vertical;
  font-size: var(--fs-14); line-height: 1.55;
}
.composer textarea:focus { outline: none; }
.composer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  flex-wrap: wrap; row-gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-top: 1px solid var(--c-border-soft);
  background: var(--c-surface-2);
}
.composer-foot-info { color: var(--c-text-faint); font-size: var(--fs-11); padding-left: var(--s-2); flex: 1 1 auto; min-width: 180px; }
.composer-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: flex-end; flex: 1 1 auto; }

/* Reasoning / metadata section */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s-3);
  margin: var(--s-5) 0;
  padding: var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-lg);
}
.meta-cell {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.meta-key { font-size: var(--fs-11); color: var(--c-text-faint); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.meta-val { font-size: var(--fs-13); color: var(--c-text); font-variant-numeric: tabular-nums; }

.section-title {
  font-size: var(--fs-12); color: var(--c-text-faint);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
  margin: var(--s-5) 0 var(--s-3);
}

.contact-controls {
  display: flex; gap: var(--s-2); flex-wrap: wrap;
  margin-top: var(--s-3);
}

/* Contacts list (right pane variant) */
.contacts-list { display: flex; flex-direction: column; gap: var(--s-2); }
.contact-card {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-md);
}
.contact-card .contact-info { flex: 1; min-width: 0; }
.contact-card .contact-name { font-weight: 600; font-size: var(--fs-14); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card .contact-sub { color: var(--c-text-mute); font-size: var(--fs-12); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card .contact-actions { display: flex; gap: var(--s-1); flex-wrap: wrap; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.status-dot.on { background: var(--c-ok); }
.status-dot.off { background: var(--c-text-faint); }
.status-dot.takeover { background: var(--c-warn); }

/* Settings */
.settings-body h1 { font-size: var(--fs-20); font-weight: 650; letter-spacing: -0.01em; }
.settings-body .field-hint { color: var(--c-text-mute); font-size: var(--fs-12); margin-top: 4px; }
.settings-section {
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  padding: var(--s-5);
  margin-top: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-4);
}
.settings-section h3 { font-size: var(--fs-14); font-weight: 600; }
.settings-actions { display: flex; align-items: center; gap: var(--s-3); }

/* Segmented control (mode picker) */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--c-surface-3);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border-soft);
  width: fit-content;
}
.segmented button {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: var(--fs-12); font-weight: 600;
  color: var(--c-text-mute);
  transition: background 120ms ease, color 120ms ease;
}
.segmented button.is-on {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-1);
}

/* Technical details — raw machine values, tucked away by default */
.tech-details {
  margin-top: var(--s-4);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  overflow: hidden;
}
.tech-details summary {
  cursor: pointer;
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--c-text-mute);
  display: flex; align-items: center; gap: 6px;
  list-style: none;
  user-select: none;
}
.tech-details summary::-webkit-details-marker { display: none; }
.tech-details summary::before {
  content: "›";
  display: inline-block;
  transition: transform 120ms ease;
  font-size: var(--fs-14);
  width: 10px;
}
.tech-details[open] summary::before { transform: rotate(90deg); }
.tech-details-body {
  padding: var(--s-3);
  border-top: 1px solid var(--c-border-soft);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--c-text-mute);
  display: flex; flex-direction: column; gap: 6px;
  word-break: break-word;
}
.tech-details-row { display: flex; gap: 8px; }
.tech-details-row .k { color: var(--c-text-faint); flex: 0 0 140px; }
.tech-details-row .v { flex: 1; min-width: 0; }

/* Intent chips — toggle-style multi-select, replacing a comma-separated field */
.intent-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 6px;
}
.intent-chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-mute);
  font-size: var(--fs-12); font-weight: 500;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.intent-chip:hover { border-color: color-mix(in srgb, var(--c-accent) 40%, var(--c-border)); }
.intent-chip.is-on {
  background: var(--c-accent-soft); color: var(--c-accent);
  border-color: color-mix(in srgb, var(--c-accent) 35%, var(--c-border));
}
.intent-chip .dot {
  width: 8px; height: 8px; border-radius: 999px;
  border: 1.5px solid currentColor;
  flex: 0 0 auto;
}
.intent-chip.is-on .dot { background: currentColor; }
.intent-chip-add {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border-radius: 999px;
  border: 1px dashed var(--c-border);
  background: transparent;
}
.intent-chip-add input {
  border: 0; background: transparent; font-size: var(--fs-12);
  width: 130px; padding: 0;
}
.intent-chip-add input:focus { outline: none; }

/* Confidence slider — human-readable, not a raw 0..1 number input */
.confidence-control { display: flex; flex-direction: column; gap: 8px; }
.confidence-readout {
  display: flex; align-items: baseline; gap: 6px;
  font-size: var(--fs-15); font-weight: 650;
  color: var(--c-text);
}
.confidence-readout .unit { font-size: var(--fs-12); font-weight: 500; color: var(--c-text-mute); }
.confidence-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--c-accent) 0%, var(--c-accent) var(--pct, 85%), var(--c-surface-3) var(--pct, 85%), var(--c-surface-3) 100%);
  outline: none;
}
.confidence-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 999px;
  background: var(--c-surface);
  border: 2px solid var(--c-accent);
  box-shadow: var(--shadow-1);
  cursor: pointer;
}
.confidence-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 999px;
  background: var(--c-surface);
  border: 2px solid var(--c-accent);
  cursor: pointer;
}
.confidence-scale { display: flex; justify-content: space-between; font-size: var(--fs-11); color: var(--c-text-faint); }

/* Take-over emphasis for escalations */
.btn-takeover {
  background: var(--c-warn); color: #fff; border-color: transparent;
}
.btn-takeover:hover { background: color-mix(in srgb, var(--c-warn) 85%, black); }

/* Settings: collapse the middle list column entirely — nothing to list there.
   Desktop/tablet only (min-width matches the mobile breakpoint below): at
   ≤860px .mode-settings' higher specificity (.app-shell.mode-settings, two
   classes) would otherwise beat the mobile media query's plain .app-shell
   rule regardless of source order, breaking the single-column mobile
   layout. Mobile already stacks a single column without a "middle column"
   to collapse, so this rule simply doesn't apply there. */
@media (min-width: 861px) {
  .app-shell.mode-settings { grid-template-columns: var(--rail-w) 0 1fr; }
}
.app-shell.mode-settings .list-col { display: none; }
@media (max-width: 1180px) and (min-width: 861px) {
  .app-shell.mode-settings { grid-template-columns: var(--rail-w-sm) 0 1fr; }
}

/* Toasts */
.toasts {
  position: fixed; bottom: var(--s-5); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--s-2);
  z-index: 40;
}
.toast {
  min-width: 240px; max-width: 90vw;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--c-text); color: var(--c-surface);
  font-size: var(--fs-13);
  box-shadow: var(--shadow-pop);
  animation: toast-in 200ms ease;
}
.toast.err { background: var(--c-danger); color: #fff; }
.toast.ok  { background: var(--c-ok); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 7. Responsive ---------- */
.mobile-back {
  position: fixed; top: var(--s-3); left: var(--s-3);
  z-index: 30;
  height: 32px; padding: 0 12px 0 8px;
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-size: var(--fs-13); font-weight: 500;
  box-shadow: var(--shadow-1);
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: var(--rail-w-sm) var(--list-w) 1fr; }
  .rail-label { display: none; }
  .rail-badge {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px;
  }
  .mode-chip { display: none; }
  .rail-brand { margin: 0 auto var(--s-2); }
  .rail-item { justify-content: center; padding: 10px; }
  .rail-bottom { flex-direction: column; }
}

@media (max-width: 860px) {
  /* Single coherent mobile layout: rail as a horizontal top strip (row 1),
     then either the list or the detail pane stacked below (row 2) — JS
     toggles which one is visible via is-hidden-mobile / is-open-mobile.
     Every grid-item gets grid-column reset to 1 here explicitly, since the
     desktop rules pin them to columns 1/2/3 of a 3-column grid that no
     longer exists at this width — leaving any of those pins in place
     creates a stray implicit column and misplaces content. */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .rail, .list-col, .detail-col { grid-column: 1; }
  .rail {
    grid-row: 1;
    flex-direction: row;
    position: static;
    height: auto;
    padding: var(--s-2) var(--s-3);
    border-right: 0;
    border-bottom: 1px solid var(--c-border);
    align-items: center;
  }
  .rail-top { flex-direction: row; align-items: center; gap: var(--s-2); flex: 1; }
  .rail-nav { flex-direction: row; gap: 4px; }
  .rail-item { padding: 8px 10px; }
  .rail-bottom { flex-direction: row; border-top: 0; padding-top: 0; }
  .list-col, .detail-col { grid-row: 2; position: static; height: calc(100vh - 54px); }
  .list-col { display: block; }
  .list-col.is-hidden-mobile { display: none; }
  .detail-col { display: none; }
  .detail-col.is-open-mobile { display: block; }
  .mobile-back { display: inline-flex; }
}

/* ---------- 8. Small niceties ---------- */
.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--c-surface-3);
  border: 1px solid var(--c-border-soft);
  color: var(--c-text-mute);
}
.linkish { color: var(--c-accent); text-decoration: none; }
.linkish:hover { text-decoration: underline; }
::selection { background: color-mix(in srgb, var(--c-accent) 30%, transparent); }

/* Knowledge tab — reuses .list-row, .avatar, .chip, .settings-section, and
   .intent-chip; only these two things are net-new. */
.knowledge-group-head {
  padding: var(--s-4) var(--s-4) var(--s-1);
  font-size: var(--fs-11); font-weight: 700; letter-spacing: 0.08em;
  color: var(--c-text-faint); text-transform: uppercase;
  border-top: 1px solid var(--c-border-soft);
  background: var(--c-surface-2);
}
.list-body > .knowledge-group-head:first-child { border-top: 0; }
.list-row.knowledge-add-row {
  background: var(--c-accent-soft);
}
.list-row.knowledge-add-row:hover {
  background: color-mix(in srgb, var(--c-accent) 20%, var(--c-surface-2));
}
.list-row.knowledge-add-row .avatar {
  background: var(--c-accent);
  color: #fff;
  font-weight: 700;
}
.knowledge-detail-body {
  padding: var(--s-5) var(--s-6);
  max-width: 780px;
  margin: 0 auto;
}
