/* CS Platform admin — multichannel CS console.
   Palette matched to whistlergarden.id's own brand colors: gold/amber accent,
   black-into-brown gradient chrome (sidebar, login) echoing the site's
   footer band. Typography and spacing kept as the system-font, no-CDN
   original — matching the venue's font/letter-spacing read too tracked-out
   and marketing-y for a dense working dashboard.
   Status semantics unchanged: emerald = healthy/online channel, amber =
   warn, red = danger.
   No web fonts and no CDN: this app must work on a laptop with no internet. */

:root {
  /* Native form-control chrome (date/month picker icon, scrollbars) only
     switches to light-on-dark rendering if the browser is told the page
     supports it — without this, the calendar icon stays black-on-black
     whenever the dark theme is active. */
  color-scheme: light;
  --gold: #efab00;
  --gold-dim: #b9860a;
  --ink: #0e0e0e;
  --primary: #0e0e0e;
  --primary-strong: #000000;
  --primary-soft: #f5efe0;
  --accent: #10b981;
  --accent-soft: #e7f8f1;
  --warn: #b45309;
  --warn-soft: #fef4e6;
  --danger: #dc2626;
  --danger-soft: #fdeced;

  --bg: #fdfcfa;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --line: #eaeaeb;
  --fg: #0e0e0e;
  --muted: #757871;

  /* Buttons/inputs/selects need a firmer edge than table/card dividers —
     --line alone almost disappears against --surface in dark mode. */
  --control-border: #dcdcdb;
  --control-border-hover: #c7c6c2;
  --control-h: 2rem;
  --control-radius: 9px;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23757871' stroke-width='1.7'%3E%3Cpath d='M6 8l4 4 4-4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  /* Sidebar/login are fixed brand chrome — the same black-into-warm-brown
     gradient as the site's footer/"Book Now" band, regardless of the
     light/dark toggle. */
  --chrome-bg: linear-gradient(165deg, #0b0906 0%, #241a0f 55%, #42311a 100%);
  --chrome-fg: #f6f1e6;
  --chrome-muted: #b8ac97;
  --chrome-line: rgba(255, 255, 255, .1);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 15, 5, .06), 0 1px 3px rgba(20, 15, 5, .05);
  --shadow-lg: 0 16px 32px -8px rgba(20, 15, 5, .16);
  --shadow-glow: 0 0 0 3px rgba(239, 171, 0, .18);
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --ease-spring: cubic-bezier(.22, 1, .36, 1);
}

/* Two dark paths on purpose: the OS preference, and an explicit toggle that
   must win in both directions once the operator has chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --primary-soft: #2a2416;
    --accent-soft: #123328;
    --warn: #f59e0b;
    --warn-soft: #332a12;
    --danger: #f87171;
    --danger-soft: #331a1c;
    --bg: #15171a;
    --surface: #191c1f;
    --surface-2: #1c1f23;
    --line: #2c3036;
    --fg: #e7e9ec;
    --muted: #8b9198;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-lg: 0 18px 36px -8px rgba(0, 0, 0, .6);
    --control-border: #454b53;
    --control-border-hover: #5c636c;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%238b9198' stroke-width='1.7'%3E%3Cpath d='M6 8l4 4 4-4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary-soft: #2a2416;
  --accent-soft: #123328;
  --warn: #f59e0b;
  --warn-soft: #332a12;
  --danger: #f87171;
  --danger-soft: #331a1c;
  --bg: #15171a;
  --surface: #191c1f;
  --surface-2: #1c1f23;
  --line: #2c3036;
  --fg: #e7e9ec;
  --muted: #8b9198;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 36px -8px rgba(0, 0, 0, .6);
  --control-border: #454b53;
  --control-border-hover: #5c636c;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%238b9198' stroke-width='1.7'%3E%3Cpath d='M6 8l4 4 4-4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
/* `#login` sets display:grid, which outranks the UA rule for [hidden] — without
   this the login screen stays stacked over the shell after a successful login. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .875rem; }
.error { color: var(--danger); font-size: .875rem; }
.warn { color: var(--warn); }
a { color: var(--gold-dim); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.1rem 1rem;
  background: var(--surface-2);
  color: var(--fg);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .muted { color: var(--muted); }
.sidebar select, .sidebar .field > span { color: var(--fg); }
.sidebar select {
  background-color: var(--surface); color: var(--fg);
  border-color: var(--control-border);
}
.sidebar .field-sm > span { color: var(--muted); }

.brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; letter-spacing: -.01em; }
.brand-lg { font-size: 1.15rem; justify-content: center; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: 9px; background: var(--gold); color: #1a1509;
  box-shadow: 0 4px 14px -2px rgba(239, 171, 0, .5);
}
.brand-mark svg { width: 18px; height: 18px; }

.nav-group {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: .9rem 0 .35rem .2rem;
}
nav { display: flex; flex-direction: column; gap: 2px; }
nav button {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
  transition: background .15s var(--ease-spring), color .15s var(--ease-spring), transform .15s var(--ease-spring);
}
nav button svg { width: 17px; height: 17px; flex: none; }
nav button:hover { background: var(--surface); color: var(--fg); transform: translateX(2px); }
nav button[aria-current="page"] {
  background: var(--primary-soft); color: var(--gold-dim); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--gold);
}
.nav-badge {
  margin-left: auto; flex: none;
  background: var(--danger); color: #fff;
  font-size: .68rem; font-weight: 700; line-height: 1;
  padding: .2rem .42rem; border-radius: 999px; min-width: 1.15rem; text-align: center;
}

.sidebar-foot { margin-top: auto; display: grid; gap: .35rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.channel-row { display: flex; align-items: center; gap: .5rem; font-size: .85rem; padding: .2rem .1rem; color: var(--fg); }
.channel-row.is-off { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot-on { background: var(--accent); box-shadow: 0 0 0 3px rgba(16, 185, 129, .25), 0 0 8px rgba(16, 185, 129, .55); }
.sidebar .btn-ghost { color: var(--muted); border-color: var(--line); }
.sidebar .btn-ghost:hover { background: var(--surface); color: var(--fg); }

.version-btn {
  display: flex; align-items: baseline; justify-content: space-between; gap: .5rem;
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--muted);
  padding: .4rem .6rem; font-size: .78rem;
}
.version-btn:hover { background: var(--surface); color: var(--fg); }
.version-date { font-size: .68rem; color: var(--muted); }

.user-identity { display: flex; flex-direction: column; gap: 0; padding: .2rem .1rem; font-size: .82rem; color: var(--fg); }
.user-identity .muted { color: var(--muted); font-size: .72rem; text-transform: capitalize; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(14, 14, 14, .5); padding: 1.5rem;
}
.modal-box { width: min(480px, 100%); max-height: 80vh; overflow-y: auto; }
.version-history { max-height: 55vh; overflow-y: auto; }
.version-entry { display: grid; gap: .2rem; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.version-entry-head { display: flex; align-items: center; gap: .5rem; }
.version-entry-head strong { font-size: .9rem; }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.topbar-user { display: flex; flex-direction: column; align-items: flex-end; gap: 0; padding: 0 .3rem; font-size: .82rem; color: var(--fg); line-height: 1.25; }
.topbar-user strong { color: var(--gold); }
.topbar-user .muted { font-size: .72rem; text-transform: capitalize; }
main { padding: 1.5rem; display: grid; gap: 1rem; align-content: start; }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.1rem;
}
/* Sticks a card under the topbar so its actions stay reachable while the
   long list below it scrolls. --topbar-h is measured in app.js. */
.card-sticky {
  position: sticky;
  top: calc(var(--topbar-h, 72px) + .5rem);
  z-index: 4;
  background: var(--surface);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.card > .card-head:first-child { margin-top: 0; }
.stack { display: grid; gap: .6rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.item {
  display: grid; gap: .55rem; padding: .8rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  transition: border-color .15s var(--ease-spring), box-shadow .15s var(--ease-spring);
}
.item:hover { border-color: rgba(239, 171, 0, .35); box-shadow: var(--shadow); }
.item-grid { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.item-actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* ---------- dashboard stat tiles ---------- */
.stat-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-tile {
  display: grid; gap: .3rem; padding: .85rem .9rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  border-left: 3px solid var(--accent-tile, var(--line));
}
.stat-tile-label { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-tile-value { font-size: 1.6rem; font-weight: 700; color: var(--fg); line-height: 1.1; }
.stat-tile-hint { font-size: .74rem; color: var(--muted); }
.stat-tile-hot { --accent-tile: var(--danger); }
.stat-tile-warm { --accent-tile: var(--gold); }
.stat-tile-cold { --accent-tile: #3b82f6; }
.stat-tile-bot { --accent-tile: var(--accent); }
.stat-tile-agent { --accent-tile: #8b5cf6; }
.stat-tile-waiting { --accent-tile: var(--warn); }

/* pairs two dashboard cards side by side; stacks below the .kb-quickadd breakpoint */
.dashboard-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 860px) {
  .dashboard-row { grid-template-columns: 1fr; }
}

/* donut + legend */
.chart-row { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.donut-wrap { position: relative; flex: none; }
.donut-wrap svg { display: block; }
.donut-center {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1;
}
.donut-center-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--fg); }
.donut-center-label { display: block; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.legend { display: grid; gap: .5rem; flex: 1; min-width: 160px; }
.legend-item { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: .5rem; font-size: .85rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-label { color: var(--fg); }
.legend-value { font-weight: 700; color: var(--fg); }
.legend-pct { color: var(--muted); font-size: .78rem; min-width: 2.6em; text-align: right; }

/* trend bar chart */
.trend-chart { width: 100%; }
.trend-chart svg { width: 100%; height: 140px; max-height: 160px; }

/* horizontal bar list (per-agent load) */
.hbar-chart { display: grid; gap: .55rem; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 3fr auto; align-items: center; gap: .6rem; font-size: .85rem; }
.hbar-label { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 8px; border-radius: 5px; background: var(--line); overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 5px; transition: width .3s var(--ease-spring); }
.hbar-value { font-weight: 700; color: var(--fg); text-align: right; min-width: 1.5em; }

.empty {
  display: grid; gap: .3rem; place-items: center; text-align: center;
  padding: 2.2rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}

/* ---------- forms ---------- */
.field { display: grid; gap: .3rem; }
.field > span { font-size: .78rem; font-weight: 600; color: var(--muted); }
.field-sm > span { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; }

.cover-photo-field { display: flex; align-items: center; gap: .6rem; }
.cover-photo-preview {
  width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--line);
}
.cover-photo-empty {
  width: 64px; height: 64px; display: grid; place-items: center; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius);
  font-size: .68rem; color: var(--muted); padding: .2rem;
}

/* quick-add: one form for all kategori, instead of a blank row per table */
.kb-quickadd {
  display: grid; grid-template-columns: 10rem 14rem 1fr auto; gap: .7rem; align-items: start;
  padding-top: .8rem; margin-top: .2rem; border-top: 1px dashed var(--line);
}
.kb-quickadd textarea { min-height: var(--control-h); resize: none; overflow-y: auto; padding-top: .3rem; padding-bottom: .3rem; }
.kb-quickadd-action { display: flex; flex-direction: column; }
@media (max-width: 860px) {
  .kb-quickadd { grid-template-columns: 1fr 1fr; }
  .kb-quickadd-action { grid-column: 1 / -1; }
  .kb-quickadd-action .btn { width: 100%; justify-content: center; }
}

input, select, textarea {
  font: inherit; width: 100%; min-height: var(--control-h); padding: .3rem .6rem;
  color: var(--fg); background: var(--surface);
  border: 1px solid var(--control-border); border-radius: var(--control-radius);
  transition: border-color .15s var(--ease-spring), box-shadow .15s var(--ease-spring);
}
input:hover, select:hover, textarea:hover { border-color: var(--control-border-hover); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--gold); }
textarea { min-height: 4.5rem; resize: vertical; }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 2.1rem;
  background-image: var(--select-chevron);
  background-repeat: no-repeat; background-position: right .65rem center; background-size: 14px;
}
select:disabled { cursor: not-allowed; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 1px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--gold); box-shadow: var(--shadow-glow); }
.switch { display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: var(--muted); }

/* Chrome/Safari repaint an autofilled input with their own white/yellow
   background and ignore `background`, `color`, even `!important` on those
   properties directly — this is the one override that actually sticks. A
   9999s transition delay is the standard trick to stop it flashing on fill. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fg);
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
  box-shadow: 0 0 0 1000px var(--surface) inset;
  transition: background-color 9999s ease-in-out 0s;
}

/* Team page: search + type/status filters above the table. */
.filters { margin-bottom: .75rem; }
.filters input[type="text"] { flex: 2 1 200px; width: auto; }
.filters select { flex: 0 1 160px; width: auto; }

button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--control-border); border-radius: var(--control-radius);
  background: var(--surface); color: var(--fg);
  min-height: var(--control-h); padding: .3rem .9rem;
  transition: background .15s var(--ease-spring), border-color .15s var(--ease-spring),
              transform .1s var(--ease-spring), box-shadow .15s var(--ease-spring), filter .15s var(--ease-spring);
}
button:active { transform: scale(.97); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-size: .875rem; font-weight: 550; min-width: 5.5rem;
}
.btn:hover { background: var(--surface-2); border-color: var(--control-border-hover); }
.btn-primary {
  background: var(--gold); border-color: var(--gold); color: #1a1206;
  box-shadow: 0 6px 16px -4px rgba(239, 171, 0, .35);
}
.btn-primary:hover { background: var(--gold-dim); border-color: var(--gold-dim); color: #1a1206; transform: translateY(-1px); box-shadow: 0 10px 22px -4px rgba(239, 171, 0, .45); }
.btn-primary:active { transform: translateY(0) scale(.97); }
.btn-primary:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-success { color: var(--accent); border-color: var(--control-border); background: transparent; }
.btn-success:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { min-width: 0; min-height: 0; width: var(--control-h); height: var(--control-h); padding: 0; display: grid; place-items: center; }
.btn-icon svg { width: 16px; height: 16px; transition: transform .2s var(--ease-spring); }
.btn-icon:hover svg { transform: rotate(-14deg); }

/* ---------- chips, badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .3rem; min-height: 0;
  padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--primary-soft); color: var(--gold-dim);
}
.chip-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip-ok { background: var(--accent-soft); color: var(--accent); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
button.chip { border: none; font: inherit; cursor: pointer; }
button.chip.chip-muted { border: 1px solid var(--line); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  background: var(--surface-2); position: sticky; top: 0; z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; white-space: nowrap; }
td select { padding: .25rem 1.7rem .25rem .4rem; font-size: .82rem; min-height: var(--control-h); background-size: 12px; background-position: right .5rem center; }

/* Sortable column header — looks like header text, not a button, until hover. */
th button.th-sort {
  border: 0; border-radius: 0; background: none; padding: 0; margin: 0; min-height: 0;
  font: inherit; font-size: inherit; text-transform: inherit; letter-spacing: inherit;
  color: inherit; cursor: pointer;
}
th button.th-sort:hover { color: var(--fg); }

/* Expandable header-row / detail-row pairs (e.g. Team page): the detail
   cell spans every column so a wide multi-field form doesn't force the
   summary table itself to widen. */
tr.table-detail td { background: var(--surface-2); padding: .9rem 1.1rem; }
tr.table-detail .item { background: var(--surface); }

/* Knowledge table: compact editable rows instead of stacked cards, so a long
   list stays scannable rather than a page of repeated fields. */
table.kb td { vertical-align: top; padding: .4rem .5rem; }
table.kb td:nth-child(4) { width: 45%; }
/* Selection column: batch delete picks rows here, one toolbar button acts on them. */
table.kb th.pick, table.kb td.pick { width: 2.2rem; text-align: center; padding-right: 0; }
table.kb th.pick input[type="checkbox"] { margin: 0; vertical-align: middle; }
/* Unsaved edits stay visible until the toolbar's Simpan is pressed. */
tr.is-dirty td { background: var(--warn-soft); }
tr.is-dirty td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.kb select, table.kb input[type="number"], table.kb input[type="text"], table.kb input:not([type]), table.kb textarea {
  padding: .25rem .4rem; font-size: .82rem; min-height: var(--control-h);
}
table.kb select { padding-right: 1.7rem; background-size: 12px; background-position: right .5rem center; }
table.kb select, table.kb input[type="number"] { min-width: 6.5rem; }
table.kb input[type="text"], table.kb input:not([type]) { min-width: 8rem; }
table.kb textarea {
  resize: vertical; overflow-y: auto; line-height: 1.3;
}
table.kb input[type="checkbox"] { margin-top: .35rem; }

/* ---------- knowledge attachments ---------- */
.att-strip { display: grid; gap: .4rem; margin-top: .45rem; }
.att-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.att-list:empty { display: none; }
.att-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.att-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  max-width: 15rem; padding: .2rem .4rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); font-size: .78rem;
}
.att-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.att-icon { font-size: 1rem; line-height: 1; }
.att-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-remove {
  border: 0; background: none; color: var(--muted); min-height: 0;
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 .1rem;
}
.att-remove:hover { color: var(--danger); }

/* ---------- WhatsApp-formatted value editor ---------- */
/* Toolbar and preview only earn their vertical space while the field is in
   use or actually holds formatting — a long list must stay scannable. */
.wa-editor { display: grid; gap: .25rem; }
.wa-toolbar {
  display: none; align-items: center; gap: .2rem;
}
.wa-editor:focus-within .wa-toolbar { display: flex; }
.wa-btn {
  min-width: 1.6rem; min-height: 0; padding: .1rem .35rem; line-height: 1.4;
  font-size: .75rem; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; cursor: pointer;
}
.wa-btn:hover { color: var(--fg); border-color: var(--accent); }
.wa-bold { font-weight: 700; }
.wa-italic { font-style: italic; }
.wa-strike { text-decoration: line-through; }
.wa-hint { margin-left: auto; font-size: .68rem; color: var(--muted); }
.wa-hint.is-warn { color: var(--warn); font-weight: 600; }
.wa-preview {
  padding: .35rem .55rem; font-size: .82rem; line-height: 1.45;
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0;
  white-space: normal; overflow-wrap: anywhere;
}
.wa-preview[hidden] { display: none; }
.wa-preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95em;
}
tr.is-new-row { background: var(--surface-2); }
tr.is-new-row td { border-top: 1px dashed var(--line); }
.cal td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.cal .is-weekend td:first-child { color: var(--fg); font-weight: 600; }

/* ---------- chat preview ----------
   Bubble sizing mirrors WhatsApp's own thread: a bubble hugs its own text
   (fit-content) instead of stretching to the column width, capped so a long
   message still wraps like WA's does, and the timestamp sits inside the
   bubble's bottom-right corner rather than as a separate header line. */
.chat { display: grid; gap: .3rem; max-height: 65vh; overflow-y: auto; padding-right: .3rem; }
.day-divider { justify-self: center; margin: .4rem 0; }
.day-divider span {
  font-size: .72rem; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: .2rem .75rem;
}
.bubble {
  justify-self: start; width: fit-content; max-width: min(75%, 32rem);
  padding: .4rem .6rem .3rem; border-radius: 12px; font-size: .9rem;
  border: 1px solid var(--line); background: var(--surface-2);
}
.bubble-in { border-bottom-left-radius: 3px; }
.bubble-out {
  justify-self: end; border-bottom-right-radius: 3px;
  background: var(--primary-soft); border-color: transparent; color: var(--fg);
}
.bubble-meta { font-size: .7rem; color: var(--muted); margin-bottom: .15rem; }
.bubble-sender { font-size: .72rem; font-weight: 650; color: var(--accent); margin-bottom: .1rem; }
/* pre-wrap keeps every enter (and run of spaces) the operator or customer
   typed exactly as WA would render it — waToHtml already turns \n into <br>,
   this covers blank lines and leading spaces on their own line too. */
.bubble-body { overflow-wrap: anywhere; white-space: pre-wrap; }
.system-chip {
  display: flex; justify-content: center; gap: .5rem; align-items: baseline;
  margin: .5rem auto; padding: .25rem .75rem; border-radius: 999px; font-size: .8rem;
  max-width: 90%; text-align: center;
}
.system-chip time { opacity: .7; font-size: .75rem; }
.system-chip-warn { background: var(--warn-soft); color: var(--warn); }
.system-chip-info { background: var(--accent-soft); color: var(--accent); }
.system-chip-muted { background: var(--surface-2); color: var(--muted); }
.bubble-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95em;
}
.bubble-time { font-size: .68rem; color: var(--muted); text-align: right; line-height: 1; margin-top: .15rem; }
.attachment-chip, .attachment-preview {
  display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: .3rem .5rem; margin-bottom: .3rem;
}
.attachment-preview { margin-top: .4rem; }
.composer { display: flex; flex-direction: column; gap: .4rem; margin-top: .4rem; }
.composer-toolbar { display: flex; gap: .3rem; }
.composer-row { display: flex; gap: .6rem; align-items: flex-end; }
.composer-row textarea { flex: 1; min-height: 2.6rem; }
pre {
  white-space: pre-wrap; word-break: break-word; margin: 0;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: .7rem; font-size: .8rem;
}
details summary { cursor: pointer; font-size: .85rem; color: var(--muted); }
.tool-call { font-size: .8rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- login ---------- */
#login {
  display: grid; place-items: center; min-height: 100vh; padding: 1rem;
  background: var(--chrome-bg);
}
#login form {
  display: grid; gap: .8rem; width: min(23rem, 100%);
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12); box-shadow: var(--shadow-lg);
  color: var(--chrome-fg);
}
#login form .muted { color: var(--chrome-muted); }
#login form .field > span { color: var(--chrome-fg); }
#login form input {
  background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .16); color: var(--chrome-fg);
}
#login form input::placeholder { color: var(--chrome-muted); }
#login form .btn-primary { background: var(--gold); border-color: var(--gold); color: #1a1509; }
#login form .btn-primary:hover { background: #ffc531; border-color: #ffc531; color: #1a1509; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; }
.toast {
  padding: .6rem .85rem; border-radius: var(--radius); font-size: .875rem;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg); max-width: 24rem;
}
.toast-ok { border-left: 3px solid var(--accent); }
.toast-error { border-left: 3px solid var(--danger); }

/* ---------- handover alerts (a chat was handed to an Agent) ---------- */
.handover-alerts {
  /* Must clear the topbar (z-index: 5, sticky, holds logout/theme-toggle/user
     identity at this same top-right corner) — top: 1rem alone overlapped it,
     so a click meant for those controls was silently swallowed by the banner
     underneath instead, which read as an unwanted jump to Conversations. */
  position: fixed; top: calc(var(--topbar-h, 72px) + .75rem); right: 1rem; display: grid; gap: .6rem;
  z-index: 4; width: min(22rem, calc(100vw - 2rem));
}
.handover-alert {
  display: flex; gap: .65rem; align-items: flex-start;
  padding: .8rem .9rem; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  box-shadow: var(--shadow-lg); cursor: pointer;
}
.handover-alert-icon { font-size: 1.25rem; line-height: 1; }
.handover-alert-body { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.handover-alert-title { font-size: .75rem; font-weight: 600; color: var(--warn); text-transform: uppercase; letter-spacing: .02em; }
.handover-alert-name { font-size: .9rem; font-weight: 600; color: var(--fg); }
.handover-alert-snippet { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handover-alert .btn-icon { flex-shrink: 0; }

@media (max-width: 860px) {
  .handover-alerts { left: 1rem; right: 1rem; width: auto; top: .75rem; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .sidebar-foot { margin-top: .5rem; }
  main, .topbar { padding: 1rem; }
}

/* ---------- motion (vanilla, no framework) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s var(--ease-spring); }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } }

  .handover-alert { animation: slide-in-right .28s var(--ease-spring); }
  @keyframes slide-in-right { from { opacity: 0; transform: translateX(24px); } }

  /* app.js toggles this class on #page each time a route renders */
  #page.page-enter { animation: page-in .32s var(--ease-spring); }
  @keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

  /* staggered reveal for cards within a freshly-rendered page */
  #page.page-enter > .card { animation: card-in .34s var(--ease-spring) both; }
  /* a transform would create a containing block and break position: sticky */
  #page.page-enter > .card-sticky { animation: none; }
  #page.page-enter > .card:nth-child(1) { animation-delay: .02s; }
  #page.page-enter > .card:nth-child(2) { animation-delay: .06s; }
  #page.page-enter > .card:nth-child(3) { animation-delay: .1s; }
  #page.page-enter > .card:nth-child(4) { animation-delay: .14s; }
  @keyframes card-in { from { opacity: 0; transform: translateY(10px) scale(.99); } }
}

.wa-qr { display: block; max-width: 260px; margin: 12px 0; border-radius: 8px; }
