/*
 * VoiceDemo screens. Everything visual comes from the tokens below (the approach of NORMA's
 * src/Norma.Web/wwwroot/css/tokens.css: surfaces, ink, one accent, status colours never used alone).
 * Agent, client and the raw microphone each have one colour, used the same way everywhere.
 */
:root {
  color-scheme: light;
  --page: #f5f6f8;
  --surface: #ffffff;
  --surface-sunken: #eef0f4;
  --surface-hover: #f4f6fb;
  --sidebar: #0f1729;
  --sidebar-ink: #c8d0e0;
  --sidebar-active: #1d2a45;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #e3e6ec;
  --line-strong: #cfd4dd;
  --accent: #2554c7;
  --accent-hover: #1e46a8;
  --accent-subtle: #e8eefc;
  --agent: #2554c7;
  --agent-subtle: #eaf0fd;
  --client: #0b8a6b;
  --client-subtle: #e4f5ef;
  --raw: #c0661a;
  --raw-subtle: #fbefe3;
  --live: #d6303b;
  --live-subtle: #fdebec;
  --ok: #138a3c;
  --ok-subtle: #e5f5ea;
  --warn: #b36b00;
  --warn-subtle: #fdf2dc;
  --down: #c62f2f;
  --down-subtle: #fbe7e7;
  --neutral: #6b7280;
  --neutral-subtle: #eef0f3;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", ui-monospace, Consolas, monospace;
  --radius: 10px;
  --radius-small: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 41, 0.06), 0 4px 16px rgba(15, 23, 41, 0.05);
  --fast: 150ms;
  --medium: 250ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.25rem 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-3); }
.small { font-size: 0.8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Headings receive the focus after navigation (for screen readers), not a visible frame. */
h1:focus, h1:focus-visible, [tabindex="-1"]:focus { outline: none; }
#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--down-subtle); color: var(--down); padding: 10px 20px; font-weight: 600; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--sidebar) 236px, var(--page) 236px); }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 1.1rem; padding: 4px 8px 22px; text-decoration: none !important; }
.brand__mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-ink); text-decoration: none !important; transition: background var(--fast) var(--ease); }
.nav__link svg { width: 18px; height: 18px; fill: currentColor; opacity: 0.85; }
.nav__link:hover { background: var(--sidebar-active); color: #fff; }
.nav__link.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav__count { margin-left: auto; background: var(--live); color: #fff; border-radius: 999px; font-size: 0.75rem; padding: 0 7px; font-weight: 600; }
.sidebar__footer { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding: 0 8px; }
.service-status { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; }
.user { display: flex; align-items: center; gap: 10px; }
.user__avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--sidebar-active); display: grid; place-items: center; color: #fff; font-size: 0.75rem; font-weight: 600; }
.user__name { color: #fff; font-size: 0.88rem; }
.sidebar .btn--ghost { color: var(--sidebar-ink); border-color: #2b3958; }
.content { padding: 28px 36px 48px; min-width: 0; }

/* ---- page structure ---- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.section { margin-bottom: 26px; }
.section > h2 { margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card > h2 { margin-bottom: 12px; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
.grid-2 > .card { margin-top: 0; }
.breadcrumb { font-size: 0.85rem; color: var(--ink-3); margin-bottom: 8px; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 8px; border: 1px solid transparent; padding: 9px 16px; font-weight: 600; cursor: pointer; text-decoration: none !important; transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-hover); }
.btn--ghost:disabled { opacity: 0.45; cursor: default; }
.btn--small { padding: 5px 11px; font-size: 0.82rem; }
.btn--block { width: 100%; }

/* ---- status: dots, badges, chips ---- */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: var(--neutral); }
.dot--ok { background: var(--ok); }
.dot--warn { background: var(--warn); }
.dot--down { background: var(--down); }
.dot--live { background: var(--live); animation: pulse 1.6s infinite; }
.dot--neutral { background: var(--neutral); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; border-radius: 999px; padding: 3px 10px; }
.badge--live { background: var(--live-subtle); color: var(--live); }
.badge--neutral { background: var(--neutral-subtle); color: var(--ink-2); }
.badge--warning { background: var(--warn-subtle); color: var(--warn); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--live); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(214, 48, 59, 0.55); } 70% { box-shadow: 0 0 0 8px rgba(214, 48, 59, 0); } 100% { box-shadow: 0 0 0 0 rgba(214, 48, 59, 0); } }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.chip__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }
.chip__value { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip__detail { font-size: 0.8rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip--ok { border-left: 3px solid var(--ok); }
.chip--warn { border-left: 3px solid var(--warn); }
.chip--down { border-left: 3px solid var(--down); }
.notice { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 0.9rem; }
.notice--danger { background: var(--down-subtle); color: var(--down); }
.notice--info { background: var(--accent-subtle); color: var(--accent-hover); }

/* ---- dashboard ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.kpi__label { font-size: 0.8rem; color: var(--ink-3); font-weight: 600; }
.kpi__value { font-size: 2rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 10px; }
.kpi__hint { font-size: 0.78rem; color: var(--ink-3); }
.kpi--live { border-color: #f3c3c6; background: linear-gradient(180deg, #fff 0%, #fff7f7 100%); }
.kpi--live .kpi__value { color: var(--live); }
.live-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.live-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid #f0c9cc; border-radius: var(--radius); padding: 16px 18px; color: inherit; text-decoration: none !important; box-shadow: var(--shadow); transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.live-card:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(15, 23, 41, 0.1); }
.live-card__top { display: flex; justify-content: space-between; align-items: center; }
.live-card__duration { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); }
.live-card__agent { font-size: 1.1rem; font-weight: 650; }
.live-card__meta { color: var(--ink-3); font-size: 0.85rem; margin-bottom: 4px; }
.live-card__open { color: var(--accent); font-weight: 600; font-size: 0.88rem; margin-top: 4px; }
.presence { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.presence__item { display: flex; align-items: center; gap: 12px; }
.presence__name { font-weight: 600; }

/* ---- tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); }
.table__row { cursor: pointer; transition: background var(--fast) var(--ease); }
.table__row:hover { background: var(--surface-hover); }
.pager { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; }
.pager__buttons { display: flex; align-items: center; gap: 12px; }
.empty-inline { color: var(--ink-3); padding: 12px 0; }

/* ---- forms & filters ---- */
.filters { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }
.field--grow { flex: 1; min-width: 260px; }
.field input, .field select { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 12px; min-width: 150px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

/* ---- level meters ---- */
.level { margin: 10px 0; }
.level__head { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 4px; }
.level__label { font-weight: 600; color: var(--ink-2); }
.level__value { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.level__track { height: 10px; background: var(--surface-sunken); border-radius: 999px; overflow: hidden; }
.level__fill { height: 100%; border-radius: 999px; transition: width 90ms linear; }
.level--agent .level__fill { background: linear-gradient(90deg, #7a9cf0, var(--agent)); }
.level--client .level__fill { background: linear-gradient(90deg, #5cc7a8, var(--client)); }
.level--raw .level__fill { background: linear-gradient(90deg, #eeb27a, var(--raw)); }

/* ---- live call ---- */
.live-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.live-head__line { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.live-head__timer { font-size: 2.6rem; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: var(--ink-2); }
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.live-side .card + .card { margin-top: 16px; }
.transcript-card { display: flex; flex-direction: column; }
.transcript { height: calc(100vh - 330px); min-height: 360px; overflow-y: auto; padding: 4px 4px 12px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.transcript--static { height: auto; max-height: 70vh; min-height: 0; }
.transcript__empty { color: var(--ink-3); margin: auto; text-align: center; padding: 40px 0; }
.legend { font-size: 0.78rem; color: var(--ink-3); }
.legend__agent { color: var(--agent); font-weight: 700; }
.legend__client { color: var(--client); font-weight: 700; }
.utterance { max-width: 78%; border-radius: 14px; padding: 9px 14px 11px; animation: arrive var(--medium) var(--ease); }
.utterance--agent { align-self: flex-start; background: var(--agent-subtle); border-top-left-radius: 4px; }
.utterance--client { align-self: flex-end; background: var(--client-subtle); border-top-right-radius: 4px; }
.utterance__meta { display: flex; gap: 10px; align-items: center; font-size: 0.72rem; margin-bottom: 2px; }
.utterance__speaker { font-weight: 800; letter-spacing: 0.06em; }
.utterance--agent .utterance__speaker { color: var(--agent); }
.utterance--client .utterance__speaker { color: var(--client); }
.utterance__time { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.utterance__text { font-size: 1rem; line-height: 1.45; display: block; }
.utterance--partial .utterance__text { color: var(--ink-2); font-style: italic; }
.utterance--button { border: 0; text-align: left; cursor: pointer; font: inherit; color: inherit; display: block; }
.utterance--button:hover { filter: brightness(0.97); }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.typing { display: inline-flex; gap: 3px; }
.typing i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); animation: typing 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }
.floor { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.floor__title { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.floor__values { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; flex-wrap: wrap; }
.floor__gain { color: var(--ok); font-weight: 700; margin-top: 4px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 0.86rem; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.command { font-family: var(--mono); font-size: 0.85rem; background: var(--surface-hover); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 6px 0 14px; overflow-x: auto; white-space: pre; }
.hash { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-3); }

/* ---- call detail: A/B comparison ---- */
.compare { margin-bottom: 20px; }
.compare__intro { margin-bottom: 16px; }
.compare__sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: stretch; }
.compare__side { position: relative; border-radius: var(--radius); padding: 18px; text-align: center; border: 2px solid transparent; transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.compare__side--raw { background: var(--raw-subtle); }
.compare__side--clean { background: var(--agent-subtle); }
.compare__side.is-active { border-color: currentColor; box-shadow: 0 6px 20px rgba(15, 23, 41, 0.08); }
.compare__side--raw.is-active { color: var(--raw); }
.compare__side--clean.is-active { color: var(--agent); }
.compare__side h3 { color: var(--ink); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.85rem; }
.compare__tag { position: absolute; top: 10px; left: 12px; font-weight: 800; font-size: 0.75rem; color: var(--ink-3); }
.play-big { margin-top: 12px; width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer; display: inline-grid; place-items: center; color: #fff; transition: transform var(--fast) var(--ease); }
.play-big svg { width: 28px; height: 28px; fill: currentColor; margin-left: 3px; }
.play-big:hover { transform: scale(1.05); }
.compare__side--raw .play-big { background: var(--raw); }
.compare__side--clean .play-big { background: var(--agent); }
.compare__side.is-active .play-big svg path { d: path("M7 5h4v14H7zm6 0h4v14h-4z"); }
.compare__middle { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px; text-align: center; }
.compare__gain { font-size: 1.4rem; font-weight: 700; color: var(--ok); line-height: 1.2; }
.compare__progress { display: flex; align-items: center; gap: 12px; margin-top: 16px; cursor: pointer; }
.compare__bar { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.compare__fill { height: 100%; width: 0; background: var(--ink-2); }
.compare__time { font-variant-numeric: tabular-nums; font-size: 0.82rem; color: var(--ink-3); min-width: 96px; text-align: right; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.detail-side .card + .card { margin-top: 16px; }
.detail-side audio, .card > audio { width: 100%; margin-top: 8px; }

/* ---- timeline ---- */
.timeline { margin: 4px 0 16px; display: flex; flex-direction: column; gap: 6px; }
.timeline__lane { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 8px; }
.timeline__name { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.06em; color: var(--ink-3); }
.timeline__track { position: relative; height: 16px; background: var(--surface-sunken); border-radius: 4px; }
.timeline__seg { position: absolute; top: 2px; bottom: 2px; border: 0; border-radius: 3px; cursor: pointer; padding: 0; min-width: 3px; }
.timeline__seg--agent { background: var(--agent); }
.timeline__seg--client { background: var(--client); }
.timeline__seg:hover { filter: brightness(1.2); }

/* ---- sign-in ---- */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 10% -10%, #dfe7fb 0%, transparent 60%), var(--page); padding: 24px; }
.login__card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(15, 23, 41, 0.12); padding: 32px; }
.login__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; margin-bottom: 24px; }
.login h1 { font-size: 1.35rem; margin-bottom: 4px; }

/* ---- empty states, loading ---- */
.empty { max-width: 560px; margin: 80px auto; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty__icon { width: 72px; height: 72px; border-radius: 50%; background: var(--accent-subtle); color: var(--accent); display: grid; place-items: center; }
.page-loading { display: grid; place-items: center; padding: 48px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.reconnect { display: none; position: fixed; inset: 0; background: rgba(15, 23, 41, 0.35); z-index: 1000; place-items: center; }
.reconnect.components-reconnect-show, .reconnect.components-reconnect-failed, .reconnect.components-reconnect-rejected { display: grid; }
.reconnect__box { background: var(--surface); border-radius: 10px; padding: 18px 22px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); }

@media (max-width: 1200px) {
  .live-grid, .detail-grid, .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .transcript { height: 60vh; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; background: var(--page); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
  .brand { padding: 0 8px 0 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__footer { display: none; }
  .content { padding: 18px 16px 40px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .compare__sides { grid-template-columns: 1fr; }
  .utterance { max-width: 92%; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(7), .table td:nth-child(7) { display: none; }
}
