:root {
  --bg: #ffffff;
  --chrome: #f7f8f9;
  --desk-chrome: #eef1f4;
  --surface: #ffffff;
  --hover: #e6eaef;
  --border: #e6e8eb;
  --border-strong: #d4d7db;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #0b8057;
  --accent-hover: #096743;
  --accent-soft: #e4f4ec;
  --accent-border: #b7e0cd;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --gray-soft: #f3f4f6;
  /* Auth theme tokens — originally scoped to .auth-shell, but the supplier-admin form reuses
     the auth classes (.login-btn/.field/.field-label/.auth-card) under .desk-shell instead, so
     these must resolve globally or the form renders with an invisible button and no borders. */
  --sage: #0f9d6a;
  --sage-hover: #0b8057;
  --sage-soft: #e4f4ec;
  --auth-text: #18231d;
  --auth-muted: #68736c;
  --auth-err: #c2433a;
  --auth-err-soft: #fbedeb;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  height: 56px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.brand .brand-text {
  display: flex; flex-direction: column; justify-content: space-between;
  height: 26px;  /* match the mark box so name top-aligns and sub bottom-aligns */
}
.brand .name { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; line-height: 1; }
.brand .sub { color: var(--text-muted); font-size: 12px; line-height: 1; }
header .spacer { flex: 1; }
.status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status.offline .dot { background: var(--text-faint); }
.logout-btn {
  padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff;
  color: var(--text-muted); font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.logout-btn:hover { background: var(--gray-soft); color: var(--text); }

/* Desk shell — the page is exactly one viewport tall and scrolls INTERNALLY.
   .layout used to be height: calc(100vh - 56px), which subtracted only the header; the
   .tabs strip sitting between them (~38px) was never counted, so the document ran ~38px
   longer than the viewport and the foot of the desk fell below the fold. Sizing is now
   flex-driven so nothing is hard-coded, and 100dvh follows the mobile address bar (100vh
   is the LARGE viewport and overshoots on phones). Scoped with :has(.layout) so the
   signed-out auth-shell, which relies on a normally scrolling document, is unaffected. */
body:has(.layout) {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
header, .tabs { flex: 0 0 auto; }
.layout { display: flex; flex: 1 1 auto; min-height: 0; }

.sessions {
  width: 380px; flex-shrink: 0;
  background: var(--desk-chrome);
  border-right: 1px solid var(--border-strong);
  overflow-y: auto;
}
.sessions .section-label {
  padding: 18px 18px 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint);
}
.session {
  padding: 12px 18px; cursor: pointer;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
  text-align: left; width: 100%;
}
.session:hover { background: var(--hover); }
.session.active { background: var(--surface); border-left-color: var(--accent); }
/* keep the selection stable while the pointer is over it: hover must not outrank selected */
.session.active:hover { background: var(--surface); }
.session .row { display: flex; align-items: center; gap: 8px; }
.session .name-row { margin-bottom: 5px; }
.session .badge-row { gap: 6px; flex-wrap: wrap; }
.session .name {
  font-weight: 600; font-size: 13.5px; color: var(--text);
  flex: 1; min-width: 0;
  line-height: 1.3;
  word-break: break-word;
}
.session .meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session .preview { font-size: 12px; color: var(--text-muted); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.badge-attn { background: var(--amber-soft); color: var(--amber); }
.badge-created { background: var(--green-soft); color: var(--green); }
.badge-live { background: var(--accent-soft); color: var(--accent); }
.badge-terminal { background: var(--gray-soft); color: var(--text-muted); }
.badge-manual { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.badge-seed { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }
.badge-test { background: var(--gray-soft); color: var(--text-faint); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.chat-header .cust { font-weight: 600; font-size: 15px; }
.chat-header .sub { color: var(--text-muted); font-size: 12px; }

.voice-bar {
  padding: 8px 18px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.voice-bar audio { width: 100%; max-width: 210px; height: 34px; }

.messages { flex: 1; overflow-y: auto; padding: 22px 22px 14px; }
.msg { max-width: 72%; margin-bottom: 18px; }
.msg .who {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 5px; display: flex; gap: 8px; align-items: center;
}
.msg .who .when { font-weight: 400; color: var(--text-faint); }
.own {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 4px;
}
.own-auto { background: var(--accent-soft); color: var(--accent); }
.own-human { background: var(--green-soft); color: var(--green); }
.msg .bubble {
  padding: 10px 14px; border-radius: 10px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px;
}
.msg.customer { margin-left: 0; margin-right: auto; }
.msg.customer .bubble { background: var(--gray-soft); color: var(--text); border: 1px solid var(--border-strong); border-bottom-left-radius: 3px; }
.msg.bot, .msg.desk { margin-left: auto; margin-right: 0; }
.msg.bot .who, .msg.desk .who { justify-content: flex-end; }
.msg.bot .who .role-name { color: var(--accent); }
.msg.desk .who .role-name { color: var(--text-muted); }
.msg.bot .bubble { background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent-border); border-bottom-right-radius: 3px; }
.msg.desk .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }

.intent-card {
  background: var(--accent-soft); border: 1px solid var(--accent-border);
  border-radius: 8px; padding: 14px 16px; margin: 4px 0 20px;
}
.intent-card h4 { margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
.intent-card .line { font-size: 13.5px; color: var(--text); padding: 2px 0; }
.intent-card .line code { font-weight: 600; color: var(--text); }

.actions {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; background: #fff;
}
button {
  padding: 9px 15px; border-radius: 6px; cursor: pointer;
  font-weight: 500; font-size: 13px; font-family: inherit;
  border: 1px solid transparent; transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap; background: #fff; color: var(--text);
}
button.approve { background: var(--accent); color: #fff; }
button.approve:hover { background: var(--accent-hover); }
button.reject { background: #fff; color: var(--red); border-color: #fca5a5; }
button.reject:hover { background: var(--red-soft); }
button.takeover { background: #fff; color: var(--text-muted); border-color: var(--border-strong); }
button.takeover:hover { background: var(--gray-soft); color: var(--text); }
button.identify { background: var(--amber-soft); color: var(--amber); border-color: #fde68a; }
button.identify:hover { background: #fef3c7; }
button.close { background: #fff; color: var(--text-muted); border-color: var(--border-strong); }
button.close:hover { background: var(--red-soft); color: var(--red); border-color: #fca5a5; }
button:disabled { opacity: 0.45; cursor: default; }
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
input[type=text], input[type=password], input[type=email] {
  flex: 1; padding: 10px 13px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  font-family: inherit; font-size: 13px;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.empty { color: var(--text-faint); text-align: center; margin-top: 48px; font-size: 13.5px; }
.x3-error { color: var(--red); font-size: 12px; background: var(--red-soft); padding: 8px 12px; border-radius: 6px; margin-bottom: 14px; }

.cand { font-size: 12px; color: var(--text-muted); padding: 1px 0 1px 14px; }
.cand-desc { color: var(--text); }
.cand-reason { color: var(--text-faint); font-style: italic; margin-left: 6px; }
.raw-text { font-size: 12px; color: var(--text-muted); background: var(--gray-soft); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 0 0 20px; white-space: pre-wrap; word-wrap: break-word; }
.raw-label { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin-bottom: 4px; }
.sage-card { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 12px 16px; margin: 0 0 20px; }
.sage-grid { display: grid; grid-template-columns: 92px 1fr; row-gap: 5px; column-gap: 10px; }
.sage-k { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.sage-v { font-size: 13px; color: var(--text); }
.sage-latency { margin-top: 8px; font-size: 11px; color: var(--text-faint); font-style: italic; }
.muted { color: var(--text-faint); }
.voice-extra { margin-top: 6px; }
.voice-extra audio { width: 100%; max-width: 130px; height: 34px; display: block; }
.voice-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.voice-meta strong { color: var(--text); }
.voice-lang { font: inherit; font-size: 12px; padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
.retranscribe { font: inherit; font-size: 12px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--accent); cursor: pointer; }
.retranscribe:hover { background: var(--gray-soft); }

.back-btn {
  display: none; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 6px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text); cursor: pointer;
}
.back-btn:hover { background: var(--gray-soft); }

/* login / auth — "trade ledger" direction (Sage-green, serif display, mono refs) */
.auth-shell {
  --ink: #0b1e18;
  --ink2: #133126;
  --sage: #0f9d6a;
  --sage-hover: #0b8057;
  --sage-soft: #e4f4ec;
  --paper: #faf9f5;
  --rule-dark: rgba(255,255,255,0.12);
  --rule-light: #e6e2d6;
  --auth-text: #18231d;
  --auth-muted: #68736c;
  --auth-err: #c2433a;
  --auth-err-soft: #fbedeb;
  display: flex; min-height: 100vh; background: var(--paper);
}
.auth-panel {
  position: relative; overflow: hidden;
  flex: 0 0 46%; max-width: 560px;
  display: flex; flex-direction: column;
  padding: 48px 52px;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(31,167,113,0.18), transparent 60%),
    linear-gradient(160deg, var(--ink) 0%, var(--ink2) 100%);
  color: #e8f2ec;
}
.auth-brand { display: flex; align-items: center; gap: 13px; }
.auth-mark {
  width: 42px; height: 42px; border-radius: 9px;
  background: var(--sage); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', 'Georgia', serif;
  font-weight: 600; font-size: 21px; letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.22), 0 8px 24px rgba(15,157,106,0.35);
}
.auth-name { font-family: 'Fraunces', 'Georgia', serif; font-weight: 600; font-size: 20px; letter-spacing: -0.01em; line-height: 1.1; color: #f4faf6; }
.auth-sub { color: #8aa89a; font-size: 11px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.10em; text-transform: uppercase; }
.auth-copy { margin: auto 0; padding: 48px 0; }
.auth-eyebrow {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--sage);
  margin: 0 0 18px;
}
.auth-copy h1 {
  font-family: 'Fraunces', 'Georgia', serif; font-weight: 500;
  font-size: 40px; letter-spacing: -0.02em; line-height: 1.08;
  color: #f4faf6; margin: 0 0 20px; max-width: 440px;
}
.auth-copy p { font-size: 15px; line-height: 1.6; color: #a9c0b2; margin: 0; max-width: 400px; }
.auth-docket { margin-top: 44px; border-top: 1px solid var(--rule-dark); padding-top: 22px; font-family: 'IBM Plex Mono', monospace; }
.docket-row { display: flex; align-items: baseline; gap: 16px; font-size: 12px; padding: 4px 0; }
.docket-k { color: #6f8f7e; letter-spacing: 0.12em; text-transform: uppercase; font-size: 10px; min-width: 64px; }
.docket-v { color: #d7e8dd; letter-spacing: 0.02em; }
.docket-stamp {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 16px; padding: 6px 13px;
  border: 1px solid rgba(31,167,113,0.5); border-radius: 999px;
  color: #4cc78f; font-size: 11px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase;
}
.auth-foot { color: #5f7a6c; font-size: 12px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.04em; }
.auth-main {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px; background: var(--paper);
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-family: 'Fraunces', 'Georgia', serif; font-weight: 500; font-size: 26px; letter-spacing: -0.02em; margin: 0 0 8px; color: var(--auth-text); }
.auth-lead { color: var(--auth-muted); font-size: 14px; margin: 0 0 28px; }
.auth-main a { color: var(--sage); text-decoration: none; }
.auth-main a:hover { color: var(--sage-hover); text-decoration: underline; }
.auth-main a.login-btn { color: #fff; }
.auth-main a.login-btn:hover { color: #fff; text-decoration: none; }
.auth-error {
  color: var(--auth-err); font-size: 13px; background: var(--auth-err-soft);
  padding: 11px 14px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #f1c8c3;
}
.field-group { margin-bottom: 18px; }
.field-label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--auth-muted); font-family: 'IBM Plex Mono', monospace; margin: 0 0 7px;
}
.field {
  width: 100%; height: 44px; padding: 0 14px;
  font-size: 14px; color: var(--auth-text);
  background: #fff; border: 1px solid var(--rule-light); border-radius: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus { outline: none; border-color: var(--sage); box-shadow: 0 0 0 3px var(--sage-soft); }
.field::placeholder { color: #a9a99d; }
.field-msg { display: block; color: var(--auth-err); font-size: 12px; margin-top: 5px; }
.login-btn {
  width: 100%; height: 46px; margin-top: 6px;
  background: var(--sage); color: #fff; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
}
.login-btn:hover { background: var(--sage-hover); color: #fff; text-decoration: none; }
.login-btn:active { transform: translateY(1px); }
.auth-panel ::selection { background: rgba(15,157,106,0.35); color: #fff; }
.auth-panel ::-moz-selection { background: rgba(15,157,106,0.35); color: #fff; }
.auth-main ::selection { background: var(--sage-soft); color: var(--auth-text); }
.auth-main ::-moz-selection { background: var(--sage-soft); color: var(--auth-text); }
.auth-docket, .auth-docket * { user-select: none; -webkit-user-select: none; }
.auth-stamp { user-select: none; -webkit-user-select: none; }
@media (max-width: 840px) { .auth-panel { display: none; } }

/* tabs (approvals) */
.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 14px; font-size: 12.5px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.pending-item { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.pending-item .row { display: flex; align-items: center; gap: 10px; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sessions { width: 100%; flex: 1; min-height: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .chat { display: none; }
  body.detail-open .sessions { display: none; }
  body.detail-open .chat { display: flex; min-height: 0; }
  .back-btn { display: inline-flex; }
  .msg { max-width: 92%; }
  .actions { flex-wrap: wrap; }
}

/* ===== Desk enrichment — account & order context (header strip + side rail) ===== */
.enrich { border-bottom: 1px solid var(--border); background: var(--surface); }
.enrich-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--chrome); border: none; border-bottom: 1px solid var(--border);
  padding: 6px 20px; cursor: pointer; font-size: 11px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); text-align: left;
}
.enrich-toggle .caret { transition: transform 0.15s; font-size: 9px; }
.enrich-toggle.open .caret { transform: rotate(90deg); }
.strip { display: flex; gap: 8px; padding: 10px 20px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 7px 11px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: #fff;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { border-color: var(--accent-border); box-shadow: 0 0 0 1px var(--accent-border); }
.light { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.light.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.light.amber { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.light.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.light.clear { background: var(--border-strong); }
.chip .clabel { font-size: 12px; font-weight: 600; }
.chip .cval { font-size: 11px; color: var(--text-muted); font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.cval.bad, .sum-val.bad, .v.bad { color: var(--red); font-weight: 600; }
.cval.warn, .sum-val.warn, .v.warn { color: var(--amber); font-weight: 600; }
.enrich-panel { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--chrome); }
.panel-title {
  display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
}
.dtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.dtable th {
  text-align: left; font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-faint); padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.dtable td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.dtable tr:last-child td { border-bottom: none; }
.dtable .num, .dtable .mono, .kv .v, .kv code, .sum-val { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.dtable .num { text-align: right; }
.tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; }
.tag.overdue { background: var(--red-soft); color: var(--red); }
.tag.disputed { background: var(--amber-soft); color: var(--amber); }
.tag.open { background: var(--green-soft); color: var(--green); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text-muted); }
.kv .v { text-align: right; }
.kv code { color: var(--accent); }

/* side rail */
.rail { width: 272px; flex-shrink: 0; border-left: 1px solid var(--border); overflow-y: auto; background: var(--chrome); }
.rail details { border-bottom: 1px solid var(--border); background: #fff; }
.rail summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 11px 14px; cursor: pointer; font-size: 12.5px; font-weight: 600; }
.rail summary::-webkit-details-marker { display: none; }
.rail summary .sum-val { margin-left: auto; font-size: 11px; font-weight: 500; color: var(--text-muted); }
.rail summary .chev { color: var(--text-faint); font-size: 9px; transition: transform 0.15s; }
.rail details[open] summary .chev { transform: rotate(90deg); }
.rail .body { padding: 4px 14px 14px; font-size: 12px; }
@media (max-width: 720px) { .rail { display: none; } }
