/* RF-Chatbot client console — design system (CR-010 M1).
   Token-based: one --accent drives the whole theme (set per-tenant from
   Site.settings.accent). Self-hosted, no build step, no external fonts. */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #171c26;
  --ink-2: #3c4453;
  --muted: #6b7484;
  --line: #e5e9f0;
  --line-2: #eef1f6;

  /* the one per-tenant token — everything below derives from it */
  --accent: #3a5a98;
  --accent-ink: #ffffff;
  --accent-weak: color-mix(in srgb, var(--accent) 10%, var(--panel));
  --accent-line: color-mix(in srgb, var(--accent) 24%, var(--panel));

  --good: #12894b; --good-weak: #e5f4ec;
  --info: #2c6bb3; --info-weak: #e7f0f9;
  --warn: #9a6a12; --warn-weak: #f6efdf;
  --neutral-weak: #eef1f6;

  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 28px -14px rgba(16,24,40,.22);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c111b; --panel: #141b28; --panel-2: #1a2231;
    --ink: #e9edf5; --ink-2: #b9c2d2; --muted: #8792a5;
    --line: #232d3e; --line-2: #1b2434;
    --accent: #7f9fd8; --accent-ink: #0c111b;
    --accent-weak: color-mix(in srgb, var(--accent) 16%, var(--panel));
    --accent-line: color-mix(in srgb, var(--accent) 32%, var(--panel));
    --good: #35c07a; --good-weak: #10241a; --info: #6aa6e6; --info-weak: #0f1e2c;
    --warn: #d5a53e; --warn-weak: #241d10; --neutral-weak: #1b2434;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.7);
  }
}
:root[data-theme="light"] {
  --bg: #eef1f6; --panel: #ffffff; --panel-2: #f8fafc;
  --ink: #171c26; --ink-2: #3c4453; --muted: #6b7484;
  --line: #e5e9f0; --line-2: #eef1f6; --accent-ink: #ffffff;
  --accent-weak: color-mix(in srgb, var(--accent) 10%, var(--panel));
  --accent-line: color-mix(in srgb, var(--accent) 24%, var(--panel));
  --good: #12894b; --good-weak: #e5f4ec; --info: #2c6bb3; --info-weak: #e7f0f9;
  --warn: #9a6a12; --warn-weak: #f6efdf; --neutral-weak: #eef1f6;
}
:root[data-theme="dark"] {
  --bg: #0c111b; --panel: #141b28; --panel-2: #1a2231;
  --ink: #e9edf5; --ink-2: #b9c2d2; --muted: #8792a5;
  --line: #232d3e; --line-2: #1b2434; --accent-ink: #0c111b;
  --accent-weak: color-mix(in srgb, var(--accent) 16%, var(--panel));
  --accent-line: color-mix(in srgb, var(--accent) 32%, var(--panel));
  --good: #35c07a; --good-weak: #10241a; --info: #6aa6e6; --info-weak: #0f1e2c;
  --warn: #d5a53e; --warn-weak: #241d10; --neutral-weak: #1b2434;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ===== shell ===== */
.console { container-type: inline-size; min-height: 100vh; }
.app { display: grid; grid-template-columns: 222px 1fr; min-height: 100vh; }

.side { border-right: 1px solid var(--line); background: var(--panel-2); display: flex;
  flex-direction: column; padding: 16px 12px; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.brand .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.brand .bt { font-weight: 650; font-size: 14px; line-height: 1.15; }
.brand .bt small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 14px; }
.nav a svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; opacity: .85; }
.nav a:hover { background: var(--line-2); }
.nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav a.active svg { opacity: 1; }
.side .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; padding: 8px; border-top: 1px solid var(--line); }
.who .av { width: 30px; height: 30px; border-radius: 999px; background: var(--accent-line);
  color: var(--accent); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.who .nm { font-size: 13px; min-width: 0; } .who .nm small { display: block; color: var(--muted); font-size: 11px; }
.who form { margin-left: auto; }
.who .exit { border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 8px; padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.who .exit:hover { color: var(--ink); }

.main { display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(6px); z-index: 4; }
.top h1 { font-size: 16px; margin: 0; letter-spacing: -.01em; font-weight: 650; }
.top .push { flex: 1; }
.pick { display: inline-flex; align-items: center; gap: 7px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--ink-2); }
.pick svg { width: 14px; height: 14px; stroke: var(--muted); fill: none; stroke-width: 1.8; }
.body { padding: 24px; display: flex; flex-direction: column; gap: 22px; }

.eyebrow { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  font-family: var(--font-mono); margin: 0 0 12px; }

/* headline + tiles */
.headline { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.headline .big { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 40px;
  font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.headline .cap { color: var(--ink-2); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 15px; background: var(--panel);
  display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 600;
  letter-spacing: -.01em; }
.tile .sub { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.tile .foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.spark { width: 74px; height: 26px; display: block; flex: none; }

/* funnel */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 18px 18px 8px; }
.funnel { display: flex; flex-direction: column; }
.stage { display: grid; grid-template-columns: 160px 1fr 78px; align-items: center; gap: 14px; padding: 9px 0; }
.stage .name { font-size: 14px; color: var(--ink-2); }
.stage .track { height: 30px; border-radius: 7px; background: var(--panel-2); position: relative; overflow: hidden; }
.stage .fill { position: absolute; inset: 0 auto 0 0; border-radius: 7px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 78%, #fff)); }
.stage .val { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.drop { display: grid; grid-template-columns: 160px 1fr 78px; }
.drop .chip { grid-column: 2; justify-self: start; margin-left: 6px; font-family: var(--font-mono);
  font-size: 11.5px; color: var(--warn); background: var(--warn-weak); padding: 1px 8px; border-radius: 999px; }
.cutover-note { font-size: 12.5px; color: var(--warn); background: var(--warn-weak);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; cursor: help; }

/* period selector */
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg a { color: var(--muted); font-size: 13px; padding: 5px 14px; border-radius: 999px; }
.seg a.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.12); }

/* lists */
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.listhead { display: grid; align-items: center; gap: 12px; padding: 9px 16px; background: var(--panel-2);
  border-bottom: 1px solid var(--line); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-family: var(--font-mono); }
.item { display: grid; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--panel-2); }
.conv { grid-template-columns: 1fr 150px 116px 118px; }
.lead { grid-template-columns: 1.4fr 168px 132px 120px; }
.item .q { font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .who2 { font-weight: 550; }
.item .meta, .item .mono { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.item .right { justify-self: end; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.pill.done { color: var(--good); background: var(--good-weak); }
.pill.active { color: var(--info); background: var(--info-weak); }
.pill.aband { color: var(--muted); background: var(--neutral-weak); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--neutral-weak); color: var(--ink-2); font-family: var(--font-mono); }
.yes { color: var(--good); } .no { color: var(--muted); }

.pager { margin-top: 14px; color: var(--muted); font-size: 13px; font-family: var(--font-mono); display: flex; gap: 14px; align-items: center; }
.pager a { color: var(--accent); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.backlink { color: var(--accent); font-size: 14px; }

/* transcript */
.dmeta { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 14px; }
.chatlog { display: flex; flex-direction: column; gap: 10px; }
.bub { max-width: 72%; padding: 9px 12px; border-radius: 13px; font-size: 14px; line-height: 1.45; }
.bub.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.bub.bot, .bub.system, .bub.operator { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }

/* mobile bottom nav */
.tabbar { display: none; }

@container (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 12px 16px; }
  .body { padding: 16px 16px 84px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .headline .big { font-size: 34px; }
  .stage { grid-template-columns: 118px 1fr 62px; gap: 10px; }
  .drop { grid-template-columns: 118px 1fr 62px; }
  .conv { grid-template-columns: 1fr auto; }
  .conv .col-when, .conv .col-msgs { display: none; }
  .lead { grid-template-columns: 1fr auto; }
  .lead .col-src, .lead .col-mail { display: none; }
  .listhead { display: none; }
  .bub { max-width: 84%; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line); z-index: 6; }
  .tabbar a { flex: 1; color: var(--muted); font-size: 11px; padding: 9px 0 8px; display: flex; flex-direction: column;
    align-items: center; gap: 3px; }
  .tabbar a svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; }
  .tabbar a.active { color: var(--accent); }
}

/* slide-in transcript drawer */
.scrim { position: fixed; inset: 0; background: rgba(10,14,22,.42); opacity: 0; transition: opacity .25s; z-index: 40; }
.scrim.open { opacity: 1; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 88vw); background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -18px 0 40px -24px rgba(0,0,0,.5);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.7,.2,1); z-index: 41;
  display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer .dh { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer .dh .x { margin-left: auto; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; color: var(--ink-2); font-size: 15px; line-height: 1; }
.drawer .dh .x:hover { color: var(--ink); }
.chatlog-wrap { padding: 16px; overflow: auto; flex: 1; }
.chatlog-wrap .dmeta { margin-top: 0; }
.loading { color: var(--muted); padding: 24px; text-align: center; font-family: var(--font-mono); font-size: 13px; }

/* keyboard focus + motion */
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ===== login ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box { width: 340px; max-width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 24px; box-shadow: var(--shadow); }
.login-box .mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; margin-bottom: 14px; }
.login-box h1 { font-size: 18px; margin: 0 0 2px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-box label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2); color: var(--ink); font: inherit; }
.login-box input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login-box button { width: 100%; margin-top: 18px; padding: 11px; border: 0; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px; cursor: pointer; }
.login-box .err { color: #c0392b; font-size: 13px; margin-top: 12px; }
