/* styles.css -- call-assist test client. A left-nav shell (Configuration > Stack / Qualifiers /
   Runbooks / Phrases, plus Simulation) around the same bridge-driven panels that used to be
   stacked <details> accordions. Design tokens follow the ui-ux-pro-max "real-time / operations"
   dashboard recommendation: dense spacing, a technical monospace/sans pairing, and a dark-first
   palette with light-mode equivalents (the host already declares color-scheme: light dark). */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
  color-scheme: light dark;
  --font-body: 'Fira Sans', system-ui, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius: 8px;
  --radius-lg: 12px;

  /* Dark defaults (ui-ux-pro-max "Real-Time / Operations Landing", dense dial) */
  --color-background: #0b0f1a;
  --color-surface: #131826;
  --color-surface-alt: #1a2033;
  --color-foreground: #f1f5f9;
  --color-muted-fg: #93a0b4;
  --color-border: #2a3350;
  --color-primary: #3b82f6;
  --color-primary-fg: #ffffff;
  --color-accent: #22c55e;
  --color-destructive: #ef4444;
  --color-warning: #f59e0b;
}

@media (prefers-color-scheme: light) {
  :root {
    --color-background: #f6f7fb;
    --color-surface: #ffffff;
    --color-surface-alt: #eef0f6;
    --color-foreground: #10151f;
    --color-muted-fg: #5b6577;
    --color-border: #d9deea;
    --color-primary: #2563eb;
    --color-primary-fg: #ffffff;
    --color-accent: #16a34a;
    --color-destructive: #dc2626;
    --color-warning: #b45309;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-foreground);
  background: var(--color-background);
}

code, .mono { font-family: var(--font-mono); }

button {
  font-family: inherit;
  cursor: pointer;
}
button:focus-visible, .navItem:focus-visible, .pttBtn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------------------------
   Shell: fixed left nav + scrollable content area.
--------------------------------------------------------------------------------------------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sideNav {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-3);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1rem;
  padding: 0 var(--space-2);
  color: var(--color-foreground);
}
.brandMark { color: var(--color-primary); flex: none; }

.navGroup { display: flex; flex-direction: column; gap: var(--space-1); }
.navGroupLabel {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted-fg);
  padding: 0 var(--space-2);
  margin-bottom: var(--space-1);
}
.navList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.navItem {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem var(--space-3);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-foreground);
  transition: background-color 150ms ease, color 150ms ease;
}
.navItem:hover { background: var(--color-surface-alt); }
.navItem.active {
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-weight: 600;
}

.navFooter {
  margin-top: auto;
  padding: var(--space-2);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--color-muted-fg);
  border-top: 1px solid var(--color-border);
}
.navFooter code { color: var(--color-foreground); font-size: 0.8rem; word-break: break-all; }

.content {
  flex: 1;
  min-width: 0;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
}

.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

.viewHeader { margin-bottom: var(--space-5); }
.viewHeader h1 { margin: 0 0 var(--space-1); font-size: 1.4rem; }
.viewSubtitle { margin: 0; color: var(--color-muted-fg); font-size: 0.92rem; max-width: 70ch; }

.sectionTitle { font-size: 1rem; font-weight: 700; margin: var(--space-5) 0 var(--space-2); }
.sectionTitle:first-of-type { margin-top: 0; }
.muted { color: var(--color-muted-fg); font-size: 0.85rem; }

/* ---------------------------------------------------------------------------------------------
   Stack (config) page
--------------------------------------------------------------------------------------------- */
.configGrid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1.25rem;
  font-size: 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.configGrid dt { font-weight: 600; color: var(--color-muted-fg); }
.configGrid dd { margin: 0; }

.stackForm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  align-items: end;
}
.stackField { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; }
.stackField span { font-weight: 600; color: var(--color-muted-fg); }
.stackField input {
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-foreground);
  min-height: 40px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.stackAdvanced {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.stackAdvanced summary { cursor: pointer; font-size: 0.85rem; color: var(--color-muted-fg); margin-bottom: var(--space-2); }
.stackAdvanced[open] { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stackActions { grid-column: 1 / -1; display: flex; gap: var(--space-3); }

/* ---------------------------------------------------------------------------------------------
   Detection-configuration widgets (qualifiers / phrases / watches / runbooks) -- shared with
   the previous accordion design, unchanged in behaviour.
--------------------------------------------------------------------------------------------- */
.flash { font-size: 0.8rem; min-height: 1.1em; margin: 0.3rem 0; }
.flash.good { color: var(--color-accent); }
.flash.bad { color: var(--color-destructive); font-weight: 600; }
.note {
  font-size: 0.85rem;
  background: var(--color-surface-alt);
  padding: var(--space-3);
  border-radius: var(--radius);
  border-left: 4px solid var(--color-primary);
}
.note .every, .every { color: var(--color-accent); font-weight: 700; }
.note .gated, .gated { color: var(--color-warning); font-weight: 700; }

.createRow, .createCol, .scopeRow, .gatedControls, .qualPick, .itemRow, .membership,
.switches, .list { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.createCol, .switches, .list { flex-direction: column; align-items: stretch; }
.createRow input[type=text], .createCol input[type=text] {
  flex: 1;
  min-width: 140px;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-foreground);
  min-height: 40px;
}
input.ord { width: 5.5rem; flex: none; }
select {
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-foreground);
  min-height: 40px;
}
button.mini {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-foreground);
  min-height: 40px;
}
button.mini:hover { background: var(--color-surface-alt); }
button.mini.danger { color: var(--color-destructive); border-color: var(--color-destructive); }
label.inline { display: inline-flex; gap: 0.35rem; align-items: center; font-size: 0.85rem; }
label.switch { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 0.85rem; margin: 0.35rem 0; }

.item {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.item.block { flex-direction: column; align-items: stretch; }
.item.watchEvery { border-left: 4px solid var(--color-accent); }
.item.watchGated { border-left: 4px solid var(--color-warning); }
.itemMain { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: baseline; flex: 1; min-width: 200px; }
.itemName { font-weight: 700; }
.itemDesc { opacity: 0.8; font-size: 0.85rem; }
.itemId { font-size: 0.7rem; opacity: 0.5; }
.badge { font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.02em; }
.badge.every { background: color-mix(in srgb, var(--color-accent) 20%, transparent); color: var(--color-accent); border: 1px solid var(--color-accent); }
.badge.gated { background: color-mix(in srgb, var(--color-warning) 20%, transparent); color: var(--color-warning); border: 1px solid var(--color-warning); }
.prompts { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px dashed var(--color-border); width: 100%; }
.promptsHead { font-weight: 600; font-size: 0.85rem; opacity: 0.85; margin-bottom: 0.3rem; }
.prompt { padding: 0.45rem 0.65rem; margin: 0.3rem 0; border-radius: var(--radius); background: var(--color-surface-alt); }

/* ---------------------------------------------------------------------------------------------
   Simulation view: header bar + 2/3-1/3 body split.
--------------------------------------------------------------------------------------------- */
.simHeaderBar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}
.simHeaderActions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.sessionLabel { font-size: 0.8rem; color: var(--color-muted-fg); font-family: var(--font-mono); }

.btn {
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-foreground);
  transition: background-color 150ms ease, transform 150ms ease;
}
.btn:hover:not(:disabled) { background: var(--color-border); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btnPrimary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-fg); }
.btnPrimary:hover:not(:disabled) { filter: brightness(1.08); }

.pttBtn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 2px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-foreground);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.pttBtn.active { background: var(--color-destructive); border-color: var(--color-destructive); color: #fff; }
.pttBtn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.simBody {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .simBody { grid-template-columns: 1fr; }
  .app { flex-direction: column; }
  .sideNav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .navGroup { flex: 1 1 auto; }
}

.simTranscript {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.segments {
  flex: 1;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.seg { padding: 0.4rem 0.65rem; border-radius: var(--radius); background: var(--color-surface-alt); }
.seg.caller { border-left: 4px solid var(--color-destructive); }
.seg.telecommunicator, .seg.call-taker { border-left: 4px solid var(--color-primary); }
.seg .who { font-weight: 700; font-size: 0.7rem; text-transform: uppercase; opacity: 0.7; }
.seg.partial { opacity: 0.6; font-style: italic; }

.simDetections {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
}
.detRow {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detRow h3 { margin: 0 0 var(--space-2); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted-fg); }
.detRowGrow { flex: 1; }
.detList { display: flex; flex-direction: column; gap: var(--space-2); overflow-y: auto; }

.detChip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  background: var(--color-surface-alt);
  border-left: 3px solid var(--color-warning);
  font-size: 0.85rem;
}
.detChip .detChipName { font-weight: 700; }
.detChip .detChipQuote { color: var(--color-muted-fg); font-size: 0.8rem; font-style: italic; }
.qualChip { border-left-color: var(--color-primary); }

.runbookGroup { display: flex; flex-direction: column; gap: 0.35rem; }
.runbookGroup + .runbookGroup { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px dashed var(--color-border); }
.runbookGroupName {
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.runbookPrompt {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius);
  background: var(--color-surface-alt);
  font-size: 0.85rem;
}
.runbookPath { display: flex; flex-direction: column; gap: 0.2rem; }
.runbookPathRow { font-size: 0.82rem; padding: 0.15rem 0.4rem; background: var(--color-surface-alt); border-radius: var(--radius); }
.runbookPending { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.4rem 0.55rem; border-radius: var(--radius); background: var(--color-surface-alt); border: 1px solid var(--color-border); }
.runbookPendingQuestion { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 0.4rem; }
.runbookOptions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.auditTrail { font-size: 0.78rem; max-height: 8rem; overflow-y: auto; padding: 0.3rem 0.4rem; background: var(--color-surface-alt); border-radius: var(--radius); }
.auditRow { padding: 0.1rem 0; border-bottom: 1px dashed var(--color-border); }
.runbookPrompt .promptMandatory { font-size: 0.68rem; color: var(--color-muted-fg); text-transform: uppercase; }
.runbookPrompt.satisfied {
  opacity: 0.55;
}
.runbookPrompt.satisfied .promptText {
  text-decoration: line-through;
}

.statusLog { margin-top: var(--space-4); }
.statusLog summary { cursor: pointer; font-size: 0.85rem; color: var(--color-muted-fg); }
#status {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: var(--space-3);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  margin-top: var(--space-2);
}

/* ---- debugEnabled's own switch row (Change: LLM call-history debug view) -- default OFF, so it
   gets a visually distinct, slightly warned treatment, never blended into the on-by-default
   switches above it. ---- */
label.switchOffByDefault {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--color-border);
}

/* ---- Debug pop-out window (public/debug.html + public/debugWindow.js) -------------------------- */
body.debugBody {
  padding: var(--space-4);
}
.debugHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.debugHeader h1 { font-size: 1.05rem; margin: 0; }
.debugHeaderActions { display: flex; align-items: center; gap: var(--space-3); }
.debugEmptyHint { font-size: 0.85rem; }
.debugTurns { display: flex; flex-direction: column; gap: var(--space-2); }
.debugTurn, .debugRound {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.debugTurn > summary, .debugRound > summary {
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}
.debugTurnBody {
  padding: 0 var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.debugRound { margin-left: var(--space-3); background: var(--color-surface-alt); }
.debugRoundBody { padding: 0 var(--space-3) var(--space-3); }
.debugRoundBody h4 { font-size: 0.75rem; text-transform: uppercase; color: var(--color-muted-fg); margin: var(--space-2) 0 var(--space-1); }
.debugJson {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  max-height: 260px;
  overflow-y: auto;
}
.debugBadge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius);
  margin-right: var(--space-2);
}
.debugBadge-success { background: var(--color-success-bg, #163a2b); color: var(--color-success-fg, #7ee2a8); }
.debugBadge-failure { background: var(--color-danger-bg, #3a1616); color: var(--color-danger-fg, #ff9b9b); }
.debugBadge-pending { background: var(--color-warn-bg, #3a3216); color: var(--color-warn-fg, #ffd97e); animation: debugPendingPulse 1.2s ease-in-out infinite; }
@keyframes debugPendingPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.debugTurn-pending > summary { font-style: italic; }

/* ---- Debug tree/message view (Change: parse actual messages into a collapsible tree, never a
   flat JSON dump) ---- */
.debugTreeRoot { font-family: var(--font-mono); font-size: 0.75rem; }
.debugTree, .debugMessage {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  margin: 0.15rem 0;
}
.debugTreeSummary {
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.debugTreeBody { padding: 0.15rem 0.5rem 0.4rem 1rem; }
.debugLeaf { padding: 0.1rem 0; word-break: break-word; }
.debugLeaf.muted { color: var(--color-muted-fg); font-style: italic; }
.debugKey { color: var(--color-muted-fg); }
.debugLeafValue { white-space: pre-wrap; }
.debugParsedBadge {
  font-size: 0.65rem;
  color: var(--color-muted-fg);
  font-style: italic;
}
.debugMessages { display: flex; flex-direction: column; gap: var(--space-1); }
.debugMessage > summary { font-family: var(--font-mono); font-size: 0.78rem; padding: 0.25rem 0.5rem; cursor: pointer; }
.debugRoleBadge {
  display: inline-block;
  font-size: 0.65rem;
  text-transform: uppercase;
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius);
  background: var(--color-surface-alt);
}
.debugRoleBadge-system { background: #2a2a4a; color: #b8b8ff; }
.debugRoleBadge-user { background: #1a3a4a; color: #9fdcff; }
.debugRoleBadge-assistant { background: #2a3a1a; color: #c8e88a; }
.debugRoleBadge-tool { background: #3a2a1a; color: #ffcf9a; }
.debugMessageContent {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  max-height: 220px;
  overflow-y: auto;
  margin: 0.15rem 0;
}
