/* ==========================================================================
   Phere tenant portal — design system
   Self-contained: no CDN fonts, no external assets. System sans throughout.
   Light + dark via prefers-color-scheme; every color is a token below.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand — overridable per tenant (settings > branding writes --sy-brand) */
  --sy-brand:        #2a78d6;   /* identity accent (marks, active nav, logo) */
  --sy-brand-strong: #1c5cab;   /* solid buttons, links (>= 4.5:1 on surface) */
  --sy-brand-ink:    #ffffff;   /* text on top of brand-strong */
  --sy-brand-wash:   rgba(42, 120, 214, 0.10);
  --sy-brand-wash-2: rgba(42, 120, 214, 0.16);

  /* Neutrals — warm-tinted, calm */
  --sy-page:      #f6f6f3;      /* app canvas */
  --sy-surface:   #fcfcfb;      /* cards, sidebar, topbar */
  --sy-sunken:    #f1f1ed;      /* inset areas: code blocks, table header */
  --sy-ink:       #171713;      /* primary text */
  --sy-ink-2:     #52514e;      /* secondary text */
  --sy-ink-3:     #898781;      /* muted: axis labels, hints, meta */
  --sy-hairline:  #e4e3dc;      /* card borders, dividers */
  --sy-grid:      #e9e8e1;      /* chart gridlines (one step off surface) */
  --sy-shadow:    0 1px 2px rgba(23, 23, 19, 0.04), 0 4px 16px rgba(23, 23, 19, 0.04);
  --sy-shadow-lg: 0 4px 12px rgba(23, 23, 19, 0.07), 0 16px 48px rgba(23, 23, 19, 0.10);

  /* Charts (validated with the dataviz palette validator) */
  --sy-chart-1: #2a78d6;        /* series 1 — visitors, product bars */
  --sy-chart-2: #1baf7a;        /* series 2 — conversations */
  --sy-ord-1: #86b6ef;          /* ordinal ramp (funnel), light -> dark */
  --sy-ord-2: #5598e7;
  --sy-ord-3: #2a78d6;
  --sy-ord-4: #1c5cab;

  /* Status — reserved, never used as series colors */
  --sy-good:     #0ca30c;
  --sy-good-txt: #006300;
  --sy-warn:     #fab219;
  --sy-warn-txt: #7a5200;
  --sy-crit:     #d03b3b;
  --sy-crit-txt: #a02525;
  --sy-good-wash: rgba(12, 163, 12, 0.10);
  --sy-warn-wash: rgba(250, 178, 25, 0.14);
  --sy-crit-wash: rgba(208, 59, 59, 0.10);

  /* Spacing scale */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  /* Type scale */
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px;
  --fs-xl: 19px; --fs-2xl: 24px; --fs-3xl: 30px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  /* Radii */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 999px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sy-brand:        #3987e5;
    --sy-brand-strong: #3987e5;
    --sy-brand-ink:    #0b0b0b;  /* dark ink on the lighter dark-mode brand */
    --sy-brand-wash:   rgba(57, 135, 229, 0.16);
    --sy-brand-wash-2: rgba(57, 135, 229, 0.24);

    --sy-page:      #0f0f0e;
    --sy-surface:   #1a1a19;
    --sy-sunken:    #232322;
    --sy-ink:       #f4f4f0;
    --sy-ink-2:     #c3c2b7;
    --sy-ink-3:     #898781;
    --sy-hairline:  #2c2c2a;
    --sy-grid:      #2c2c2a;
    --sy-shadow:    0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
    --sy-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5), 0 16px 48px rgba(0, 0, 0, 0.5);

    --sy-chart-1: #3987e5;
    --sy-chart-2: #199e70;
    --sy-ord-1: #9ec5f4;         /* dark-mode ordinal ramp, re-validated */
    --sy-ord-2: #6da7ec;
    --sy-ord-3: #3987e5;
    --sy-ord-4: #256abf;

    --sy-good-txt: #0ca30c;
    --sy-warn-txt: #fab219;
    --sy-crit-txt: #e66767;
    --sy-good-wash: rgba(12, 163, 12, 0.16);
    --sy-warn-wash: rgba(250, 178, 25, 0.14);
    --sy-crit-wash: rgba(208, 59, 59, 0.18);

    color-scheme: dark;
  }
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  color: var(--sy-ink);
  background: var(--sy-page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: var(--sy-ink); }
p { margin: 0; }
a { color: var(--sy-brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--sy-brand); outline-offset: 2px; border-radius: var(--r-sm); }
svg { display: block; }

/* --------------------------------------------------------------------------
   3. App shell — sidebar / topbar / content
   -------------------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sy-surface);
  border-right: 1px solid var(--sy-hairline);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-4);
  position: sticky;
  top: 0;
  height: 100vh;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--sy-ink);
  padding: 0 var(--sp-2) var(--sp-5);
}
.wordmark-glyph {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--sy-brand), var(--sy-brand-strong));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  flex-shrink: 0;
}
@media (prefers-color-scheme: dark) {
  .wordmark-glyph { color: #0b0b0b; }
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px var(--sp-3);
  border-radius: var(--r-md);
  color: var(--sy-ink-2);
  font-weight: 500;
  font-size: var(--fs-md);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav a svg { width: 17px; height: 17px; stroke: currentColor; flex-shrink: 0; }
.nav a:hover { background: var(--sy-sunken); color: var(--sy-ink); text-decoration: none; }
.nav a.active { background: var(--sy-brand-wash); color: var(--sy-brand-strong); font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .nav a.active { color: var(--sy-ord-1); }
}

.sidebar-foot {
  border-top: 1px solid var(--sy-hairline);
  padding-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--sy-ink-3);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-6);
  background: var(--sy-surface);
  border-bottom: 1px solid var(--sy-hairline);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: var(--fs-lg); font-weight: 600; }
.topbar-spacer { flex: 1; }
.topbar-tenant { display: flex; align-items: center; gap: 10px; }
.tenant-name { font-size: var(--fs-sm); color: var(--sy-ink-2); font-weight: 500; }
.avatar {
  width: 30px; height: 30px; border-radius: var(--r-full);
  background: var(--sy-brand-wash-2);
  color: var(--sy-brand-strong);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.02em;
}
@media (prefers-color-scheme: dark) { .avatar { color: var(--sy-ord-1); } }

.menu-btn { display: none; }

.content { padding: var(--sp-6); max-width: 1200px; width: 100%; margin: 0 auto; }

.page-foot {
  margin-top: auto;
  padding: var(--sp-4) var(--sp-6);
  font-size: var(--fs-xs);
  color: var(--sy-ink-3);
  display: flex; justify-content: space-between; gap: var(--sp-3);
}

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font);
  font-size: var(--fs-md); font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
  line-height: 1.3;
}
.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--sy-brand-strong); color: var(--sy-brand-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  color: var(--sy-ink-2);
  border-color: var(--sy-hairline);
}
.btn-ghost:hover { background: var(--sy-sunken); color: var(--sy-ink); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sy-shadow);
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5) 0;
}
.card-title { font-size: var(--fs-lg); font-weight: 600; }
.card-sub { font-size: var(--fs-sm); color: var(--sy-ink-3); margin-top: 2px; }
.card-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); }

/* Stat tiles */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: var(--sp-4);
}
.stat-tile {
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sy-shadow);
  padding: var(--sp-4) var(--sp-5);
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: var(--fs-sm); color: var(--sy-ink-2); font-weight: 500; }
.stat-value {
  font-size: var(--fs-3xl);
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--sy-ink);
  line-height: 1.15;
  /* proportional figures on big standalone numbers — no tabular-nums here */
}
.stat-delta { font-size: var(--fs-sm); font-weight: 600; }
.stat-delta.up { color: var(--sy-good-txt); }
.stat-delta.down { color: var(--sy-crit-txt); }
.stat-delta .vs { color: var(--sy-ink-3); font-weight: 400; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.sy {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
}
table.sy th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--sy-ink-3);
  padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--sy-hairline);
  white-space: nowrap;
}
table.sy td {
  padding: 12px var(--sp-3);
  border-bottom: 1px solid var(--sy-hairline);
  color: var(--sy-ink-2);
  vertical-align: middle;
}
table.sy td.num, table.sy th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sy tr:last-child td { border-bottom: none; }
table.sy tbody tr { transition: background 0.1s; }
table.sy tbody tr:hover { background: var(--sy-sunken); }
table.sy td .primary { color: var(--sy-ink); font-weight: 500; }
table.sy td .meta { font-size: var(--fs-xs); color: var(--sy-ink-3); }

/* Chips / badges */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--r-full);
  white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: var(--r-full); flex-shrink: 0; }
.chip-good  { background: var(--sy-good-wash); color: var(--sy-good-txt); }
.chip-good .dot { background: var(--sy-good); }
.chip-warn  { background: var(--sy-warn-wash); color: var(--sy-warn-txt); }
.chip-warn .dot { background: var(--sy-warn); }
.chip-crit  { background: var(--sy-crit-wash); color: var(--sy-crit-txt); }
.chip-crit .dot { background: var(--sy-crit); }
.chip-neutral { background: var(--sy-sunken); color: var(--sy-ink-2); }
.chip-neutral .dot { background: var(--sy-ink-3); }
.chip-brand { background: var(--sy-brand-wash); color: var(--sy-brand-strong); }
@media (prefers-color-scheme: dark) { .chip-brand { color: var(--sy-ord-1); } }

/* Segmented control (date-range presets — one row above the charts) */
.seg {
  display: inline-flex;
  background: var(--sy-sunken);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.seg a {
  padding: 5px 14px;
  border-radius: 7px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--sy-ink-2);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.seg a:hover { color: var(--sy-ink); text-decoration: none; }
.seg a.active {
  background: var(--sy-surface);
  color: var(--sy-ink);
  box-shadow: var(--sy-shadow);
}

/* Sample-data badge — dashed ring so it reads as scaffolding, not status */
.badge-sample {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--sy-ink-3);
  border: 1px dashed var(--sy-ink-3);
  border-radius: var(--r-full);
  padding: 2px 10px;
}

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--sy-ink); }
.field .hint { font-size: var(--fs-xs); color: var(--sy-ink-3); }
.input, .field input[type="text"], .field input[type="email"], .field textarea, .field select {
  font-family: var(--font);
  font-size: var(--fs-md);
  color: var(--sy-ink);
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-md);
  padding: 10px 14px;
  transition: border-color 0.12s, box-shadow 0.12s;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 84px; }
.input:focus, .field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--sy-brand);
  box-shadow: 0 0 0 3px var(--sy-brand-wash);
}
.input::placeholder { color: var(--sy-ink-3); }
.field input[type="color"] {
  width: 44px; height: 34px; padding: 2px;
  border: 1px solid var(--sy-hairline); border-radius: var(--r-sm);
  background: var(--sy-surface); cursor: pointer;
}
.field-inline { display: flex; align-items: center; gap: var(--sp-3); }

/* Code block (install snippet) */
.codeblock {
  position: relative;
  background: var(--sy-sunken);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  overflow-x: auto;
}
.codeblock pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--sy-ink);
  white-space: pre;
}
.copy-btn { position: absolute; top: 10px; right: 10px; }

/* Empty states */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--sp-7) var(--sp-5);
  gap: var(--sp-2);
}
.empty svg { width: 40px; height: 40px; stroke: var(--sy-ink-3); margin-bottom: var(--sp-2); }
.empty h3 { font-size: var(--fs-lg); }
.empty p { color: var(--sy-ink-2); font-size: var(--fs-md); max-width: 42ch; }

.checklist {
  list-style: none; margin: var(--sp-4) 0 0; padding: 0;
  display: flex; flex-direction: column; gap: var(--sp-2);
  text-align: left;
}
.checklist li {
  display: flex; align-items: center; gap: 10px;
  font-size: var(--fs-md); color: var(--sy-ink-2);
  background: var(--sy-sunken);
  border-radius: var(--r-md);
  padding: 10px 14px;
  min-width: 280px;
}
.checklist .step-n {
  width: 22px; height: 22px; border-radius: var(--r-full);
  background: var(--sy-brand-wash-2); color: var(--sy-brand-strong);
  font-size: var(--fs-xs); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
@media (prefers-color-scheme: dark) { .checklist .step-n { color: var(--sy-ord-1); } }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }

/* Section head above a card group */
.section-head { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-6) 0 var(--sp-3); }
.section-head h2 { font-size: var(--fs-xl); }
.section-head:first-child { margin-top: 0; }

/* --------------------------------------------------------------------------
   5. Charts (inline SVG rendered by portal-charts.js)
   -------------------------------------------------------------------------- */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; font-family: var(--font); }
.chart .gridline { stroke: var(--sy-grid); stroke-width: 1; }
.chart .axisline { stroke: var(--sy-hairline); stroke-width: 1; }
.chart .tick { fill: var(--sy-ink-3); font-size: 11px; }
.chart .cat-label { fill: var(--sy-ink-2); font-size: 12px; }
.chart .val-label { fill: var(--sy-ink); font-size: 12px; font-weight: 600; }
.chart .end-label { fill: var(--sy-ink); font-size: 12px; font-weight: 600; }
.chart .crosshair { stroke: var(--sy-ink-3); stroke-width: 1; }
.chart .hover-mark { transition: filter 0.08s; }
.chart .hover-mark:hover, .chart .hover-mark.is-hover { filter: brightness(1.12); }

.chart-legend {
  display: flex; flex-wrap: wrap; gap: var(--sp-4);
  font-size: var(--fs-sm); color: var(--sy-ink-2);
  padding-bottom: var(--sp-2);
}
.chart-legend .key { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend .swatch-line { width: 16px; height: 2px; border-radius: 1px; }
.chart-legend .swatch-rect { width: 11px; height: 11px; border-radius: 3px; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-md);
  box-shadow: var(--sy-shadow-lg);
  padding: 8px 12px;
  font-size: var(--fs-sm);
  z-index: 30;
  min-width: 130px;
  display: none;
}
.chart-tooltip .tt-title { color: var(--sy-ink-3); font-size: var(--fs-xs); margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.chart-tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.chart-tooltip .tt-val { font-weight: 700; color: var(--sy-ink); }
.chart-tooltip .tt-name { color: var(--sy-ink-2); }

/* Table-view twin under each chart */
details.chart-table { margin-top: var(--sp-2); }
details.chart-table summary {
  font-size: var(--fs-xs); color: var(--sy-ink-3); cursor: pointer;
  user-select: none; width: fit-content;
}
details.chart-table summary:hover { color: var(--sy-ink-2); }
details.chart-table table.sy { font-size: var(--fs-sm); margin-top: var(--sp-2); }

/* Funnel */
.funnel-step-rate {
  font-size: var(--fs-xs); color: var(--sy-ink-3);
  display: flex; align-items: center; gap: 6px;
}

/* Conversation transcript thread */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--sy-ink-2); text-decoration: none;
  margin-bottom: var(--sp-4);
}
.back-link:hover { color: var(--sy-ink); text-decoration: none; }
.back-link svg { width: 15px; height: 15px; stroke: currentColor; }

/* Compact conversation header (one row, chips right) */
.conv-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  flex-wrap: wrap;
}
.conv-head .avatar { width: 36px; height: 36px; font-size: var(--fs-sm); flex-shrink: 0; }
.conv-head .who { min-width: 0; flex: 1; }
.conv-head .who .name { font-weight: 600; color: var(--sy-ink); font-size: var(--fs-lg); }
.conv-head .who .meta {
  font-size: var(--fs-sm); color: var(--sy-ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-head .chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Transcript thread — visitor LEFT, assistant/human RIGHT, avatars both sides */
.thread-scroll {
  max-height: min(50vh, 520px);
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-4);
  overscroll-behavior: contain;
}
.msg-row { display: flex; align-items: flex-end; gap: 10px; }
.msg-row.right { flex-direction: row-reverse; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: var(--r-full);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
  margin-bottom: 18px; /* aligns with bubble body, above the meta line */
}
.msg-avatar.visitor { background: var(--sy-sunken); border: 1px solid var(--sy-hairline); color: var(--sy-ink-2); }
.msg-avatar.ai { background: var(--sy-brand-wash-2); color: var(--sy-brand-strong); }
.msg-avatar.human { background: var(--sy-brand-strong); color: var(--sy-brand-ink); }
@media (prefers-color-scheme: dark) { .msg-avatar.ai { color: var(--sy-ord-1); } }

.bubble {
  max-width: min(86%, 640px);
  padding: 10px 14px;
  border-radius: 14px;
  font-size: var(--fs-md);
  line-height: 1.55;
  color: var(--sy-ink);
  overflow-wrap: anywhere;
}
.bubble .b-text { white-space: pre-wrap; }
.bubble .b-meta {
  font-size: var(--fs-xs); color: var(--sy-ink-3);
  margin-top: 5px; white-space: nowrap;
}
.bubble-user {
  background: var(--sy-sunken);
  border: 1px solid var(--sy-hairline);
  border-bottom-left-radius: 4px;
}
.bubble-assistant {
  background: var(--sy-brand-wash);
  border: 1px solid transparent;
  border-bottom-right-radius: 4px;
}
.bubble-assistant .b-meta { text-align: right; }
/* Human-agent reply: stronger wash + accent edge (activates when role data
   distinguishes humans from the AI — see conversation_detail.html) */
.bubble-human {
  background: var(--sy-brand-wash-2);
  border: 1px solid transparent;
  border-right: 3px solid var(--sy-brand-strong);
  border-bottom-right-radius: 4px;
}
.bubble-human .b-meta { text-align: right; }

/* Quote callout — slim strip */
.quote-callout {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--sy-brand-wash);
  border: 1px solid var(--sy-brand);
  border-radius: var(--r-md);
  padding: 10px var(--sp-4);
  flex-wrap: wrap;
}
.quote-callout svg { width: 18px; height: 18px; stroke: var(--sy-brand-strong); flex-shrink: 0; }
.quote-callout .q-title { font-weight: 700; color: var(--sy-ink); white-space: nowrap; }
.quote-callout .q-body { color: var(--sy-ink-2); font-size: var(--fs-md); }
@media (prefers-color-scheme: dark) {
  .quote-callout svg { stroke: var(--sy-ord-1); }
}

/* Reply composer */
.composer { border-top: 1px solid var(--sy-hairline); padding: var(--sp-4) var(--sp-5); }
.composer-banner {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  font-size: var(--fs-md); color: var(--sy-ink-2);
}
.composer-banner .live-dot {
  width: 8px; height: 8px; border-radius: var(--r-full);
  background: var(--sy-good); flex-shrink: 0;
  box-shadow: 0 0 0 3px var(--sy-good-wash);
}
.composer-banner strong { color: var(--sy-ink); }
.composer-banner form { margin-left: auto; }
.composer textarea {
  width: 100%;
  font-family: var(--font); font-size: var(--fs-md); color: var(--sy-ink);
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline); border-radius: var(--r-md);
  padding: 10px 14px; resize: vertical; min-height: 64px;
  margin-top: var(--sp-3);
}
.composer textarea:focus {
  outline: none; border-color: var(--sy-brand);
  box-shadow: 0 0 0 3px var(--sy-brand-wash);
}
.composer-actions {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-3); flex-wrap: wrap;
}
.composer-actions .spacer { flex: 1; }

/* Prepared-answer chips (click to fill the composer) */
.qa-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: var(--sp-3); }
.qa-chip {
  font-family: var(--font); font-size: var(--fs-xs); font-weight: 600;
  color: var(--sy-ink-2);
  background: var(--sy-sunken);
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-full);
  padding: 5px 12px; cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.qa-chip:hover { border-color: var(--sy-brand); color: var(--sy-brand-strong); }

/* Prepared-answer management rows (Settings) */
.qa-item {
  border: 1px solid var(--sy-hairline);
  border-radius: var(--r-md);
  background: var(--sy-surface);
}
.qa-item summary {
  display: flex; align-items: baseline; gap: var(--sp-3);
  padding: 12px var(--sp-4);
  cursor: pointer; user-select: none;
  list-style: none;
}
.qa-item summary::-webkit-details-marker { display: none; }
.qa-item summary:hover { background: var(--sy-sunken); border-radius: var(--r-md); }
.qa-item-title { font-weight: 600; color: var(--sy-ink); white-space: nowrap; }
.qa-item-preview {
  color: var(--sy-ink-3); font-size: var(--fs-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.qa-item-form { padding: var(--sp-2) var(--sp-4) var(--sp-4); border-top: 1px solid var(--sy-hairline); }
.qa-item-form .field { margin-top: var(--sp-3); margin-bottom: var(--sp-3); }

/* Flash banner (demo mode / confirmations) */
.flash {
  display: flex; align-items: center; gap: 10px;
  border-radius: var(--r-md);
  padding: 10px var(--sp-4);
  font-size: var(--fs-sm); font-weight: 500;
  margin-bottom: var(--sp-4);
}
.flash-info { background: var(--sy-warn-wash); color: var(--sy-warn-txt); border: 1px dashed var(--sy-warn-txt); }
.flash-ok { background: var(--sy-good-wash); color: var(--sy-good-txt); border: 1px solid var(--sy-good); }

/* Row link inside tables (visitor name -> detail page) */
table.sy td a.row-link { color: var(--sy-ink); font-weight: 500; text-decoration: none; }
table.sy td a.row-link:hover { color: var(--sy-brand-strong); text-decoration: underline; }

/* Unanswered queries list */
.query-list { list-style: none; margin: 0; padding: 0; }
.query-list li {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--sy-hairline);
  font-size: var(--fs-md);
}
.query-list li:last-child { border-bottom: none; }
.query-list .q { color: var(--sy-ink); }
.query-list .n { color: var(--sy-ink-3); font-size: var(--fs-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   6. Login (standalone page)
   -------------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-5);
  background:
    radial-gradient(900px 480px at 15% -10%, var(--sy-brand-wash), transparent 60%),
    radial-gradient(700px 420px at 110% 110%, var(--sy-brand-wash), transparent 55%),
    var(--sy-page);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--sy-surface);
  border: 1px solid var(--sy-hairline);
  border-radius: 18px;
  box-shadow: var(--sy-shadow-lg);
  padding: var(--sp-6);
}
.login-wordmark {
  display: flex; align-items: center; gap: 10px;
  font-size: 21px; font-weight: 700; letter-spacing: -0.02em;
  justify-content: center;
  margin-bottom: var(--sp-5);
}
.login-wordmark .wordmark-glyph { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }
.login-card h1 { font-size: var(--fs-xl); text-align: center; margin-bottom: var(--sp-1); }
.login-card .lead {
  text-align: center; color: var(--sy-ink-2); font-size: var(--fs-md);
  margin-bottom: var(--sp-5);
}
.login-sent {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  text-align: center; padding: var(--sp-4) 0 var(--sp-2);
}
.login-sent .mail-ring {
  width: 52px; height: 52px; border-radius: var(--r-full);
  background: var(--sy-good-wash);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--sp-2);
}
.login-sent .mail-ring svg { width: 24px; height: 24px; stroke: var(--sy-good-txt); }
.login-sent h2 { font-size: var(--fs-lg); }
.login-sent p { color: var(--sy-ink-2); font-size: var(--fs-md); }
.login-foot {
  margin-top: var(--sp-5); text-align: center;
  font-size: var(--fs-xs); color: var(--sy-ink-3);
}

/* --------------------------------------------------------------------------
   7. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 920px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: var(--sy-shadow-lg); }
  .scrim {
    display: none; position: fixed; inset: 0; z-index: 35;
    background: rgba(15, 15, 14, 0.4);
    border: none; padding: 0; cursor: pointer;
  }
  .shell.nav-open .scrim { display: block; }
  .menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: transparent; border: 1px solid var(--sy-hairline);
    border-radius: var(--r-md); cursor: pointer; color: var(--sy-ink-2);
  }
  .menu-btn svg { width: 18px; height: 18px; stroke: currentColor; }
  .topbar { padding: 0 var(--sp-4); }
  .content { padding: var(--sp-4); }
  .grid-2 { grid-template-columns: 1fr; }
  .tenant-name { display: none; }
}
