/* CallXAI - dashboard styles. No framework, no build step. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e7ee;
  --text: #18202b;
  --muted: #5d6878;
  --primary: #2453d6;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefc;
  --danger: #c2372f;
  --danger-soft: #fdecea;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --ok: #1d7a4a;
  --ok-soft: #e4f5ec;
  --agent: #2453d6;
  --customer: #7b3fc4;
  --nav-bg: #111827;
  --nav-text: #cbd2dd;
  --nav-active: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171d26;
    --surface-2: #1c2330;
    --border: #2a3342;
    --text: #e6eaf0;
    --muted: #97a3b4;
    --primary: #6b8ff0;
    --primary-ink: #0b1220;
    --primary-soft: #1f2b47;
    --danger: #f07167;
    --danger-soft: #3a1f1f;
    --warn: #f2b84b;
    --warn-soft: #3a2f17;
    --ok: #4fc58a;
    --ok-soft: #173326;
    --agent: #7d9ef3;
    --customer: #b88cf0;
    --nav-bg: #0b0f15;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.9em; }
.error { color: var(--danger); }
.noscript { padding: 2rem; text-align: center; }
.pre { white-space: pre-wrap; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; letter-spacing: 0.01em; }
.brand-lg { font-size: 1.35rem; margin-bottom: 0.25rem; }
.logo {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--primary), #7b3fc4);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.25);
}

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 1.5rem 1rem; }
.login-card { width: 100%; max-width: 380px; padding: 1.75rem; }

/* ---------- shell ---------- */
.shell {
  display: grid; grid-template-columns: 232px 1fr; min-height: 100%;
  background: linear-gradient(to right, var(--nav-bg) 232px, var(--bg) 232px);
}
.topbar { display: none; }
.nav {
  background: var(--nav-bg); color: var(--nav-text);
  display: flex; flex-direction: column; padding: 1.1rem 0.75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.nav-brand { color: #fff; padding: 0 0.5rem 1.1rem; }
.nav nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: var(--nav-text); padding: 0.55rem 0.75rem; border-radius: 8px;
  display: flex; align-items: center; gap: 0.6rem; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: var(--nav-active); }
.nav a.active { background: rgba(255, 255, 255, 0.12); color: var(--nav-active); }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; }
.nav a.active .dot { opacity: 1; background: #7d9ef3; }
.nav-foot { border-top: 1px solid rgba(255, 255, 255, 0.08); padding: 0.9rem 0.5rem 0; display: grid; gap: 0.5rem; }
.who { font-size: 0.85rem; line-height: 1.3; }
.who strong { color: #fff; display: block; }
.nav .btn.ghost { color: var(--nav-text); border-color: rgba(255, 255, 255, 0.18); }
.nav .btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
main { padding: 1.5rem 1.75rem 3rem; min-width: 0; outline: none; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 19; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1.1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; }

/* ---------- cards & layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; min-width: 0;
}
.card > h2 { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.live { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.15rem; }
.stat.alert .value { color: var(--danger); }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end; }
.row > label { flex: 1 1 160px; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 0.75rem; }

/* ---------- forms ---------- */
label { display: grid; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 0.75rem; }
.row > label { margin-bottom: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.65rem; width: 100%; min-width: 0;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; color: var(--text); }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem 0.25rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 0.35rem; }
.list-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 0.5rem; margin-bottom: 0.5rem; align-items: start; }
.list-row.rubric { grid-template-columns: 1fr 110px auto; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 0.5rem 0.9rem; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn.block { width: 100%; }
.icon-btn { background: transparent; border: 0; padding: 0.4rem; cursor: pointer; color: inherit; }
.burger, .burger::before, .burger::after { display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; position: relative; }
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0.5rem; }

/* ---------- chips ---------- */
.chip {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score.good { color: var(--ok); }
.score.mid { color: var(--warn); }
.score.bad { color: var(--danger); }

/* ---------- live call ---------- */
.live-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.timer { font: 700 1.4rem/1 var(--mono); }
.transcript { max-height: 52vh; min-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.45rem; padding: 0.25rem 0; }
.seg { padding: 0.45rem 0.7rem; border-radius: 8px; background: var(--surface-2); border-left: 3px solid var(--border); max-width: 92%; }
.seg .who-tag { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; display: block; }
.seg.agent { border-left-color: var(--agent); }
.seg.agent .who-tag { color: var(--agent); }
.seg.customer { border-left-color: var(--customer); align-self: flex-end; }
.seg.customer .who-tag { color: var(--customer); }
.composer { display: grid; grid-template-columns: 130px 1fr; gap: 0.5rem; margin-top: 0.75rem; }
.composer textarea { min-height: 88px; grid-column: 1 / -1; }
.tips { display: flex; flex-direction: column; gap: 0.5rem; }
.tip { border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem; background: var(--surface-2); }
.tip .kind { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.tip.compliance { border-color: var(--danger); background: var(--danger-soft); }
.tip.compliance .kind { color: var(--danger); }
.tip.objection .kind { color: var(--warn); }
.tip.next_question .kind { color: var(--primary); }
.tip.close .kind { color: var(--ok); }
.tip.fresh { animation: pop 0.6s ease-out; }
@keyframes pop { from { transform: scale(0.97); box-shadow: 0 0 0 3px var(--primary-soft); } to { transform: none; box-shadow: none; } }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.off { background: var(--danger); }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.summary-score { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- modal & toast ---------- */
.modal {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 2rem));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(10, 15, 25, 0.5); }
.modal-head { padding: 1rem 1.2rem 0; }
.modal-body { padding: 0.5rem 1.2rem 0.5rem; max-height: 65vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.75rem 1.2rem 1rem; }
.reveal-box { font: 600 1.25rem/1.4 var(--mono); padding: 0.75rem; background: var(--surface-2); border-radius: 8px; display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; word-break: break-all; margin-bottom: 0.5rem; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.88rem; margin-bottom: 0.75rem; }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; font-weight: 600; font-size: 0.9rem;
  max-width: calc(100vw - 2rem); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .grid.two, .grid.live { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: var(--bg); }
  .topbar {
    display: flex; align-items: center; gap: 0.5rem; position: sticky; top: 0; z-index: 10;
    background: var(--nav-bg); color: #fff; padding: 0.6rem 0.75rem;
  }
  .nav {
    position: fixed; z-index: 20; left: 0; top: 0; bottom: 0; width: 260px; height: auto;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .nav.open { transform: none; }
  main { padding: 1rem 1rem 3rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .card { padding: 1rem; }
  .composer { grid-template-columns: 1fr; }
  .list-row, .list-row.rubric { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
