/* Dark panel palette. Every colour comes from here. */
:root {
  color-scheme: dark;
  --bg: #12171d; --surface: #1b222b; --raised: #232c36; --ink: #e6ebf0; --muted: #8b98a6;
  /* brand #B218CA; --accent is a lighter tint of it for text on dark ground */
  --brand: #b218ca; --accent: #cf5fe0; --accent-rgb: 178, 24, 202;
  --line: #2e3844; --danger: #f25a5a; --ok: #4fbf7a; --warn: #e0b04c;
  --side: #0d1117; --side-ink: #b6c2ce; --side-active: rgba(255, 255, 255, .1); --side-hover: rgba(255, 255, 255, .05);
  --side-ink-strong: #fff; --side-line: transparent;
  --user-turn: #283440; --agent-turn: #33223a; --tool-bg: #1e2530;
  --row-alt: #1f2731; --row-hover: #283340; --row-selected: #33223a;
  --badge-connecting-bg: #3a2f14; --badge-live-bg: #16331f; --badge-ended-bg: #262e38; --badge-failed-bg: #3a1f1f;
  --ink-strong: #fff; --brand-span: #fff; --btn-ink: #b6c2ce;
  --login-card-bg: rgba(27, 34, 43, .92); --player-bg: rgba(255, 255, 255, .06); --player-track: rgba(255, 255, 255, .15);
  --login-wave: url("../img/login-wave.svg"); --login-brand-span: #fff;
}

/* Light theme: from the system unless the user forced dark, and always when the user forced light. The sidebar turns light too. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f5f7; --surface: #fff; --raised: #eef1f4; --ink: #1b222b; --muted: #6b7683;
    --accent: #b218ca;
    --line: #d3dae1; --danger: #b23b3b; --ok: #2f7a4a; --warn: #9a6b00;
    --side: #fff; --side-ink: #4a5664; --side-active: rgba(178, 24, 202, .10); --side-hover: rgba(0, 0, 0, .04);
    --side-ink-strong: #1b222b; --side-line: #d3dae1;
    --user-turn: #e9edf1; --agent-turn: #f1e4f5; --tool-bg: #fbfbf6;
    --row-alt: #f6f8fa; --row-hover: #e9edf1; --row-selected: #f1e4f5;
    --badge-connecting-bg: #fff4de; --badge-live-bg: #e3f3e8; --badge-ended-bg: #eef1f4; --badge-failed-bg: #f9e5e5;
    --ink-strong: #000; --brand-span: #1b222b; --btn-ink: #2a333d;
    --login-card-bg: rgba(255, 255, 255, .92); --player-bg: rgba(0, 0, 0, .05); --player-track: rgba(0, 0, 0, .12);
    --login-wave: url("../img/login-wave-light.svg"); --login-brand-span: #1b222b;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f7; --surface: #fff; --raised: #eef1f4; --ink: #1b222b; --muted: #6b7683;
  --accent: #b218ca;
  --line: #d3dae1; --danger: #b23b3b; --ok: #2f7a4a; --warn: #9a6b00;
  --side: #fff; --side-ink: #4a5664; --side-active: rgba(178, 24, 202, .10); --side-hover: rgba(0, 0, 0, .04);
    --side-ink-strong: #1b222b; --side-line: #d3dae1;
  --user-turn: #e9edf1; --agent-turn: #f1e4f5; --tool-bg: #fbfbf6;
  --row-alt: #f6f8fa; --row-hover: #e9edf1; --row-selected: #f1e4f5;
  --badge-connecting-bg: #fff4de; --badge-live-bg: #e3f3e8; --badge-ended-bg: #eef1f4; --badge-failed-bg: #f9e5e5;
  --ink-strong: #000; --brand-span: #1b222b; --btn-ink: #2a333d;
  --login-card-bg: rgba(255, 255, 255, .92); --player-bg: rgba(0, 0, 0, .05); --player-track: rgba(0, 0, 0, .12);
    --login-wave: url("../img/login-wave-light.svg"); --login-brand-span: #1b222b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* thin, dark scrollbars everywhere, in the panel's own colours */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
*::-webkit-scrollbar-corner { background: transparent; }
body { margin: 0; font: 15px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 20px; margin: 0 0 4px; }
h1.title { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 12px 0 4px; }
input, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; font: inherit; background: var(--surface); }
.row { display: flex; gap: 8px; margin-top: 16px; }
/* every button follows one pattern: no background, light text, the icon in colour */
button { padding: 10px 16px; border: 0; border-radius: 4px; font: inherit; font-weight: 600; cursor: pointer; color: var(--btn-ink); background: transparent; }
button:hover { color: var(--ink-strong); }
button .ico { color: var(--accent); }
.row > button { flex: 1; }
button.stop .ico { color: var(--danger); }
button.stop:hover { color: var(--danger); }
.tokenbox summary .ico { color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }

/* login: photo background, brand on the left, the card on the right */
.login {
  position: relative; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 40px 8vw;
  /* our own voice wave in brand colours, a dark or a light one depending on the theme */
  background: var(--bg) var(--login-wave) center / cover no-repeat;
}
/* more specific than the sidebar's .brand rules, which come later in the file */
.login .login-brand { position: absolute; left: 28px; bottom: 28px; font-size: 30px; line-height: 1; padding: 0; }
.login .login-brand span { font-size: 16px; font-weight: 500; }
.login-card { width: 100%; max-width: 400px; padding: 28px; background: var(--login-card-bg); backdrop-filter: blur(6px); }
.login-card h1 { margin-bottom: 6px; }
.login-card .ghost { color: var(--ink-strong); }
.login .login-brand span { color: var(--login-brand-span); }
@media (max-width: 800px) { .login { justify-content: center; padding: 24px 24px 100px; } .login .login-brand { left: 20px; bottom: 20px; font-size: 26px; } .login .login-brand span { font-size: 14px; } }
#loginMsg { margin: 8px 0 0; min-height: 1em; }

/* app shell: full-height sidebar + main column */
.app { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--side-line); }
.brand { color: var(--accent); font-weight: 700; font-size: 19px; padding: 6px 12px 22px; letter-spacing: .01em; }
.brand span { color: var(--brand-span); font-weight: 500; font-size: 14px; }
.sidebar .brand span { color: var(--side-ink-strong); }
nav.menu { display: flex; flex-direction: column; gap: 4px; }
nav.menu button { width: 100%; text-align: left; background: transparent; color: var(--side-ink); font-weight: 500; padding: 10px 12px; border-radius: 6px; }
nav.menu button.active { background: var(--side-active); color: var(--side-ink-strong); font-weight: 600; }
nav.menu button:hover:not(.active) { background: var(--side-hover); }
/* Lucide icons from the local sprite; the stroke takes the text colour. */
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; flex: 0 0 auto; }
button .ico { margin-right: 4px; }
nav.menu button .ico { width: 17px; height: 17px; margin-right: 8px; }
/* limits view: one gauge card per figure, a bar under the big number */
.limits-bar { margin-bottom: 14px; }
.limits-bar .fact > span { font-variant-numeric: tabular-nums; }
.limits-bar .off { color: var(--danger); font-weight: 600; }
.limits-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.card.gauge { display: flex; flex-direction: column; gap: 10px; }
.card.gauge h2 { margin: 0; }
.card.gauge .big { font-size: 26px; font-weight: 600; color: var(--ink-strong); font-variant-numeric: tabular-nums; line-height: 1.1; }
.card.gauge .big small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.card.gauge .kv { margin-top: 2px; }
.lim-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.lim-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .4s ease; }
.lim-bar i.warn { background: var(--warn); }
.lim-bar i.over { background: var(--danger); }
.limits-note { margin: 14px 0 0; }
.side-user { margin-top: auto; padding: 0 6px 4px 12px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.side-user-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.side-user .lbl { text-transform: uppercase; letter-spacing: .05em; font-size: 10px; }
.side-user b { color: var(--side-ink-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .logout { padding: 6px; background: transparent; color: var(--muted); line-height: 0; }
.sidebar .logout:hover { color: var(--danger); background: transparent; }
.sidebar .logout .ico { width: 17px; height: 17px; margin: 0; }
.main { display: flex; flex-direction: column; min-width: 0; }
/* (the phone layout of the shell lives in the responsive block at the end) */

/* top bar: token on the left, who is logged in on the right */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 13px; min-height: 48px; }
.topbar .grow { flex: 1; }
.topbar .left { color: var(--muted); font-weight: 400; }
.topbar .left.warn { color: var(--danger); }
.tokenbox { position: relative; }
.tokenbox summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--btn-ink); padding: 5px 10px; border-radius: 4px; user-select: none; }
.tokenbox summary:hover { color: var(--ink-strong); }
.tokenbox summary::-webkit-details-marker { display: none; }
.tokenbox[open] summary { color: var(--ink-strong); }
.tokenpop { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; width: min(640px, 80vw); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tokenpop .lbl { width: 100%; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }
.tokenpop code { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 11.5px; line-height: 1.4; background: var(--bg); padding: 8px; border-radius: 4px; word-break: break-all; user-select: all; }
.tokenpop .mini { padding: 6px 12px; font-size: 12px; font-weight: 500; background: transparent; color: var(--btn-ink); }
.tokenpop .mini:hover { color: var(--ink-strong); filter: none; }

/* content: centered column */
.content { width: 100%; max-width: 1100px; margin: 0 auto; padding: 28px 24px 40px; }
/* the chat takes the whole width; the other sections stay in the centred column */
.content:has(#viewText:not([hidden])) { max-width: none; }
.view { min-width: 0; }

/* call: setup */
.setup { max-width: 460px; margin: 0 auto; }

/* call: one screen — state bar on top, the conversation below */
.live { display: flex; flex-direction: column; gap: 16px; }
/* One compact line: badge · facts · signals · actions. Nothing wraps; on a
   narrow window the bar scrolls sideways instead of breaking. */
.livebar { display: flex; align-items: center; gap: 22px; padding: 10px 16px; white-space: nowrap; overflow-x: auto; }
.badge { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; background: var(--badge-ended-bg); color: var(--muted); }
.badge i { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.badge span { white-space: nowrap; }
.livebar > * { flex: 0 0 auto; }
.badge.st-connecting { background: var(--badge-connecting-bg); color: var(--warn); }
.badge.st-connecting i { animation: blink 1s infinite; }
.badge.st-live { background: var(--badge-live-bg); color: var(--ok); }
.badge.st-live i { animation: blink 1.6s infinite; }
.badge.st-ended { background: var(--badge-ended-bg); color: var(--muted); }
.badge.st-failed { background: var(--badge-failed-bg); color: var(--danger); }
.facts, .signals { display: flex; align-items: center; gap: 22px; }
.signals { padding-left: 22px; border-left: 1px solid var(--line); }
.fact { display: flex; align-items: center; gap: 7px; min-width: 0; }
.fact > b { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 500; }
.fact > span { font-size: 14px; }
.fact .mono { font-family: ui-monospace, monospace; font-size: 12.5px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.fact .duration { font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 600; }
.who-speaks { display: flex; gap: 6px; align-items: center; }
.pill { font-size: 12px; padding: 1px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); transition: background .15s, color .15s; }
.pill.on { background: var(--ok); border-color: var(--ok); color: #0b1a10; }
.meter { width: 100px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.actions { margin-left: auto; display: flex; gap: 8px; }
@keyframes blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .badge i { animation: none; } }
.panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.feed { height: calc(100vh - 300px); min-height: 440px; }
.feed h2 .session { text-transform: none; letter-spacing: 0; font-family: ui-monospace, monospace; font-weight: 400; margin-left: 6px; }
.feed h2 .session:not(:empty)::before { content: "("; }
.feed h2 .session:not(:empty)::after { content: ")"; }
.scroll { flex: 1; overflow-y: auto; min-height: 0; }
label.check { display: flex; gap: 8px; align-items: flex-start; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); }
label.check input { width: auto; margin-top: 3px; }

/* the story of the call: turns and events in one chronological flow */
.turn { padding: 8px 10px; margin: 0 0 6px; border-radius: 6px; max-width: 80%; }
.turn.user { background: var(--user-turn); margin-left: auto; }
.turn.agent { background: var(--agent-turn); }
.turn small { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--muted); }
.turn small time { font-family: ui-monospace, monospace; }
.turn.partial { opacity: .7; }
.turn.cut::after { content: " — interrumpido"; color: var(--danger); font-size: 11px; }
.ev { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; padding: 3px 2px; margin: 0 0 4px; font-size: 12.5px; color: var(--muted); }
.ev time { font-family: ui-monospace, monospace; font-size: 12px; }
.ev.cut { color: var(--danger); font-weight: 600; }
.ev.err { color: var(--danger); }
.tool { margin: 0 0 6px; border: 1px dashed var(--line); border-radius: 6px; padding: 6px 10px; font-size: 13px; background: var(--tool-bg); }
.tool summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.tool summary time { font-family: ui-monospace, monospace; font-weight: 400; font-size: 12px; margin-right: 8px; }
.tool.running { border-style: solid; border-color: var(--accent); }
.tool.running summary { color: var(--ink); }
.tool pre { margin: 6px 0 0; font-size: 12px; white-space: pre-wrap; word-break: break-word; }

/* registers */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 500; }
tbody tr { cursor: pointer; }
table.striped tbody td { border-bottom: 0; }
table.striped tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--row-selected); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 12px; }
.pager .ghost { padding: 6px 12px; font-size: 13px; }
.pager .ghost .ico { margin: 0 2px; }
.pager .sub { margin: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar h2 { margin: 0; }
.toolbar .sub { margin: 0; flex: 1; }
/* The list grows with its 10 rows; the table never scrolls vertically. */
#registerList .list { max-height: none; overflow-y: hidden; overflow-x: auto; }

/* detail: header, then conversation | side cards, both scrolling on their own */
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.detail-head .ghost { padding: 6px 12px; font-size: 13px; }
.detail-head .title { margin: 0; }
.detail-title b { font-weight: 700; }
.detail-title .meta { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 10px; }
/* One explicit row the height of the grid, so the conversation and the side
   column are exactly that tall and scroll inside, whatever their content. */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: minmax(0, 1fr); gap: 16px; height: calc(100vh - 170px); min-height: 480px; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; } }
.convo { height: 100%; min-height: 0; }
.detail-side { display: flex; flex-direction: column; gap: 12px; height: 100%; min-height: 0; overflow-y: auto; }
.detail-side .card { flex: 0 0 auto; }
.detail-side .card { padding: 12px 14px; }
.detail-side h2 { margin-bottom: 8px; }
.kv { font-size: 13px; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.kv b { color: var(--muted); font-weight: 500; white-space: nowrap; }
.kv span { min-width: 0; overflow-wrap: anywhere; }
.kv span.num { text-align: right; }
.kv .total { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 2px; font-weight: 600; }
.kv .total + span { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 2px; font-weight: 600; }
.summary { margin: 0; font-size: 13.5px; line-height: 1.5; }
.summary:empty::before { content: "Sin resumen"; color: var(--muted); }
h2.with-icon { display: flex; align-items: center; gap: 8px; line-height: 1; }
.sentiment { display: inline-flex; line-height: 1; }
.sentiment .ico { width: 18px; height: 18px; vertical-align: 0; cursor: help; }
.sentiment.positive { color: var(--ok); }
.sentiment.neutral { color: var(--muted); }
.sentiment.negative { color: var(--danger); }

/* a small ring instead of "cargando…" texts */
.loader { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
.loader.center { display: block; margin: 40px auto; width: 24px; height: 24px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loader { animation-duration: 2s; } }

/* the list keeps 10 rows tall while paging: missing rows are blank fillers */
tbody tr.filler { cursor: default; }
tbody tr.filler:hover { background: inherit; }
tbody tr.filler td { color: transparent; }
.recording { width: 100%; height: 36px; margin: 0 0 10px; }

/* Texto: open chats on the left, the selected one on the right */
.chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; height: calc(100vh - 170px); min-height: 520px; }
.chat-feed .turn { max-width: 70%; }
@media (max-width: 1000px) { .chat { grid-template-columns: 1fr; height: auto; } .chat-panel { height: 70vh; } .chat-side { max-height: 40vh; } }
.chat-side { min-height: 0; padding: 12px; }
.chat-side h2 { margin: 14px 0 6px; padding: 0 4px; }
.chat-side .sub { margin: 6px 4px 0; }
.newchat { width: 100%; justify-content: center; display: inline-flex; align-items: center; gap: 4px; padding: 9px 12px; border: 1px dashed var(--line); color: var(--ink); }
.newchat:hover { border-color: var(--accent); }
.newchat-form { padding: 4px 4px 10px; border-bottom: 1px solid var(--line); }
.newchat-form label { margin-top: 10px; }
.newchat-form .row { margin-top: 12px; }
.chat-list { flex: 1; }
.chat-item { padding: 9px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.chat-item:hover { background: var(--row-hover); }
.chat-item.active { background: var(--row-selected); }
.chat-item b { font-weight: 600; font-size: 14px; }
.chat-item small { color: var(--muted); font-size: 12px; }
.chat-panel { min-height: 0; }
.chat-panel.empty { display: grid; place-items: center; }
.chat-head { display: flex; align-items: center; gap: 16px; padding-bottom: 6px; }
.chat-who { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.chat-who b { font-size: 15px; }
.chat-who .session { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
label.check.inline { margin: 0; align-items: center; gap: 6px; white-space: nowrap; }
label.check.inline .ico { color: var(--accent); }
.chat-head .stop { padding: 6px 10px; font-size: 13px; }
.chat-feed { flex: 1; padding: 12px 2px; }
/* voice reply inside the bubble */
.player { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 6px 8px; border-radius: 999px; background: var(--player-bg); }
.player .play { padding: 4px; line-height: 0; }
.player .play .ico { margin: 0; width: 18px; height: 18px; }
.player .bar { flex: 1; height: 4px; border-radius: 2px; background: var(--player-track); cursor: pointer; overflow: hidden; }
.player .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.player .t { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); white-space: nowrap; }
.turn.agent.pending { opacity: .85; }
.turn.user.pending .waiting { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.turn.user.failed { color: var(--danger); }
.typing { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); padding: 4px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; margin-right: 6px; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
.composer { display: flex; align-items: flex-end; gap: 6px; padding-top: 6px; }
.composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 140px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--bg); color: var(--ink); }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button { padding: 9px 10px; }
.composer button .ico { margin: 0; width: 18px; height: 18px; }
.composer button.rec .ico { color: var(--danger); animation: blink 1s infinite; }

/* recording bar, shown instead of the composer while a voice message is recorded */
.recbar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; background: var(--bg); font-size: 13px; color: var(--ink); }
.recbar .grow { flex: 1; }
.recbar .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.recbar button { padding: 6px 10px; font-size: 13px; }
/* the chat's event lines carry a full clock, so their time column is wider */
.chat-feed .ev { grid-template-columns: 66px minmax(0, 1fr); }

/* registers: filters */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.filters select, .filters input { width: auto; min-width: 140px; padding: 6px 8px; font-size: 13px; text-transform: none; letter-spacing: 0; }
.filters button { padding: 7px 10px; font-size: 13px; }

/* responsive: phones and narrow windows */
.topbar-brand, .topbar-logout, .chat-back, .filters-toggle { display: none; }
@media (max-width: 800px) {
  /* shell: bottom tab bar instead of the sidebar; brand and logout in the top bar */
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 20; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  .sidebar .brand, .sidebar .logout, .side-user { display: none; }
  nav.menu { flex: 1; flex-direction: row; gap: 4px; }
  nav.menu button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; font-size: 11px; font-weight: 500; }
  nav.menu button .ico { width: 20px; height: 20px; margin: 0; }
  .main { padding-bottom: 64px; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .topbar-brand { display: block; font-size: 16px; padding: 0; margin-right: auto; }
  .topbar-brand span { font-size: 12px; }
  .topbar-logout { display: inline-flex; padding: 6px; }
  .topbar-logout .ico { margin: 0; }
  .tokenbox { display: none; }  /* the token is a desktop, curl-and-terminal thing */
  h1.title { font-size: 19px; margin-bottom: 12px; }
  .card { padding: 12px; }

  /* audio: the state bar wraps into rows, the feed takes what is left */
  .livebar { flex-wrap: wrap; white-space: normal; overflow: visible; gap: 10px 18px; }
  .livebar .actions { margin-left: 0; width: 100%; }
  .livebar .actions button { flex: 1; }
  .feed { height: calc(100vh - 380px); min-height: 280px; }
  .turn { max-width: 92%; }
  .setup { max-width: none; }

  /* text: list or chat, not both */
  .chat { grid-template-columns: 1fr; height: calc(100vh - 190px); min-height: 0; }
  .chat.chat-open .chat-side, .chat.chat-open #chatEmpty { display: none; }
  .chat:not(.chat-open) .chat-panel { display: none; }
  .chat-side { max-height: none; }
  .chat-panel { height: 100%; }
  .chat-back { display: inline-flex; padding: 4px 6px; }
  .chat-back .ico { margin: 0; }
  .chat-head { gap: 8px; }
  .chat-head label.check.inline span, .chat-head .stop span { display: none; }
  .chat-feed .turn { max-width: 90%; }
  .chat-who .session { display: none; }

  /* registers: filters fold, the table becomes cards */
  .filters-toggle { display: inline-flex; margin-bottom: 8px; padding: 6px 10px; font-size: 13px; }
  .filters { display: none; }
  .filters.open { display: flex; }
  .filters label { flex: 1 1 45%; }
  .filters select, .filters input { min-width: 0; width: 100%; }
  table.striped thead { display: none; }
  table.striped, table.striped tbody, table.striped tr, table.striped td { display: block; }
  table.striped tr { padding: 8px 10px; margin-bottom: 8px; border-radius: 6px; background: var(--row-alt); }
  table.striped tbody tr:nth-child(even) { background: var(--raised); }
  table.striped tr.filler { display: none; }
  table.striped td { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; text-align: left; font-size: 13px; }
  table.striped td::before { content: attr(data-label); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; flex: 0 0 auto; padding-top: 2px; }
  table.striped td:first-child { font-weight: 600; }
  table.striped td.num { text-align: right; }
  .pager { flex-wrap: wrap; gap: 6px; }
  .pager .ghost { padding: 6px 8px; font-size: 12px; }
  .detail-head { flex-wrap: wrap; gap: 8px; }
  .detail-head .title { font-size: 17px; }
  .detail-grid { height: auto; grid-template-rows: none; }
  .convo { height: 55vh; }
  .detail-side { height: auto; overflow: visible; }
}

/* phones: the page itself never scrolls; each section scrolls inside, under the fixed tab bar */
@media (max-width: 800px) {
  html, body { height: 100%; overflow: hidden; }
  .app { height: 100vh; height: 100dvh; min-height: 0; }
  .main { height: 100%; min-height: 0; padding-bottom: 0; }
  /* room for the fixed tab bar (about 64px) plus a real margin above it */
  .content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; padding: 12px 12px calc(78px + env(safe-area-inset-bottom)); }
  .view { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  h1.title, #registersTitle { display: none; }
  /* audio */
  #callSetup { overflow-y: auto; }
  .live { flex: 1; min-height: 0; }
  .feed { flex: 1; height: auto; min-height: 0; }
  /* text */
  .chat { flex: 1; height: auto; min-height: 0; }
  /* registers */
  #registersLoading { flex: 1; }
  #registerList { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  #registerList .list { flex: 1; min-height: 0; overflow-y: auto; }
  .detail { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .detail-head .title { display: block; font-size: 16px; }
  .detail-grid { flex: 1; min-height: 0; overflow-y: auto; height: auto; }
  .convo { height: 55vh; }
}

/* pager: full text on desktop, icons and "page / pages · total" on phones */
.pager .short { display: none; }
@media (max-width: 800px) {
  .pager { justify-content: center; gap: 4px; flex-wrap: nowrap; }
  .pager .sub:not(.short) { display: none; }
  .pager .short { display: inline; margin: 0 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .pager .ghost span { display: none; }
  .pager .ghost { padding: 8px; }
  .pager .ghost .ico { margin: 0; width: 18px; height: 18px; }
}

/* recording on phones: dot, time and two icon buttons */
@media (max-width: 800px) {
  .recbar { gap: 8px; padding: 6px 8px; }
  .recbar .rec-label, .recbar button span { display: none; }
  .recbar .duration { font-size: 15px; }
  .recbar button { padding: 8px; }
  .recbar button .ico { margin: 0; width: 20px; height: 20px; }
  .composer textarea { min-height: 38px; font-size: 14px; }
  .composer button { padding: 8px; }
}

/* theme button in the top bar: just the icon */
.topbar .theme { padding: 6px; }
.topbar .theme .ico { margin: 0; width: 17px; height: 17px; }

/* tooltips: one fixed element hung from <body> that app.js moves next to the
   hovered [data-tip] control. Fixed, so no scroll container or overflow can
   clip it, wherever the control sits. */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none;
  padding: 5px 9px; border-radius: 6px; background: var(--raised); color: var(--ink); border: 1px solid var(--line);
  font-size: 12px; font-weight: 500; line-height: 1.3; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  opacity: 0; transform: translateY(4px); transition: opacity .12s ease, transform .12s ease;
}
.tooltip.below { transform: translateY(-4px); }
.tooltip.show { opacity: 1; transform: translateY(0); }
@media (max-width: 800px) { .tooltip { display: none; } }
