:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #14202b;
  --muted: #5c6b7a;
  --line: #dde3e9;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f52;
  --warn: #a15c00;
  --warn-soft: #fdf3e2;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The UA stylesheet gives [hidden] display:none, but any author `display` rule beats
   it. `.widget { display: flex }` therefore kept the panel on screen permanently: it
   could not be closed, and it was usable before anything had initialised. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  padding: 7px 13px;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #1a5fd0; color: #fff; }
button.danger { color: var(--danger); border-color: #f0c4c0; }

/* ---------- shared chrome ---------- */

header.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header.bar h1 { font-size: 16px; margin: 0; font-weight: 650; }
header.bar .sub { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 8px; }

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.pill.human { background: var(--warn-soft); color: var(--warn); }
.pill.closed { background: #eceff2; color: var(--muted); }
.pill.urgent { background: var(--danger-soft); color: var(--danger); }

/* ---------- public site ---------- */

body.site { background: var(--bg); }

.site-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.site-bar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.site-bar nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-bar nav a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 550; }
.site-bar nav a:hover { color: var(--accent); }
.site-bar nav a.staff-link { color: var(--accent); }

.site-main { max-width: 1080px; margin: 0 auto; padding: 26px 22px 90px; }
.site-main section { margin-bottom: 40px; scroll-margin-top: 76px; }
.site-main h2 { font-size: 26px; margin: 0 0 10px; }
.site-main h3 { font-size: 17px; margin: 0 0 6px; }
.section-note { color: var(--muted); font-size: 14px; margin: 0 0 16px; max-width: 78ch; }

.hero p { color: var(--muted); max-width: 70ch; margin: 0 0 18px; }
.stat-row { display: flex; gap: 22px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 110px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h4 { margin: 0 0 5px; font-size: 15px; }
.card p { margin: 0 0 8px; font-size: 14px; }
.card-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; margin: 12px 0 5px;
}
ul.plain { list-style: none; margin: 0; padding: 0; font-size: 14px; }
ul.plain li { padding: 3px 0; border-bottom: 1px solid var(--bg); }
ul.plain li:last-child { border-bottom: none; }
ul.hours li { display: flex; gap: 8px; align-items: baseline; }
ul.hours .day { min-width: 84px; color: var(--muted); }
ul.hours .note { flex-basis: 100%; font-size: 12px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.chip.warn { color: var(--warn); border-color: #f0dcb8; margin-left: 6px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tbody tr:last-child td { border-bottom: none; }

.kb-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
#kb-search {
  font: inherit; padding: 9px 12px; min-width: 260px; flex: 1;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
}
#kb-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.kb-filters { display: flex; gap: 6px; flex-wrap: wrap; }
button.filter { font-size: 12px; padding: 5px 11px; }
button.filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.kb-list { display: flex; flex-direction: column; gap: 8px; }
.kb-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.kb-item summary { cursor: pointer; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kb-item .kb-title { font-weight: 600; }
.kb-body { margin: 10px 0 6px; font-size: 14px; line-height: 1.6; }
.kb-source { margin: 0; font-size: 12px; color: var(--muted); font-style: italic; }

.site-foot { border-top: 1px solid var(--line); background: var(--panel); padding: 16px 22px; }
.site-foot p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- chat widget ---------- */

.widget-launcher {
  position: fixed; right: 22px; bottom: 22px; z-index: 20;
  background: var(--accent); border-color: var(--accent); color: #fff;
  padding: 12px 20px; border-radius: 999px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(31, 111, 235, .3);
}
.widget-launcher:hover:not(:disabled) { background: #1a5fd0; color: #fff; border-color: #1a5fd0; }
.widget-launcher.human { background: var(--warn); border-color: var(--warn); box-shadow: 0 6px 20px rgba(161, 92, 0, .3); }

.widget {
  position: fixed; right: 22px; bottom: 22px; z-index: 25;
  width: 390px; max-width: calc(100vw - 32px);
  height: 580px; max-height: calc(100vh - 44px);
  display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(20, 32, 43, .22); overflow: hidden;
}
.widget.expanded { width: 760px; height: calc(100vh - 44px); }

.widget-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.widget-title { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.widget-actions { display: flex; gap: 5px; }
.widget-actions button { padding: 3px 9px; font-size: 13px; }

#transcript { flex: 1; overflow-y: auto; padding: 14px; }
.widget #action-slot:not(:empty) { padding: 0 14px; }

/* Persona picker: always visible. It was a collapsed <details> and testers simply
   did not find it, which defeated the point of shipping examples at all. */
.widget-persona {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 9px 14px; font-size: 12px; max-height: 44%; overflow-y: auto;
}
.persona-row { display: flex; align-items: center; gap: 8px; }
.persona-row label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); white-space: nowrap;
}
.persona-row select {
  flex: 1; font: inherit; font-size: 12px; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink);
}
.persona-details { margin: 7px 0 0; color: var(--muted); line-height: 1.45; }
.persona-facts { margin-top: 4px; color: var(--ink); font-weight: 600; }
button.link {
  border: none; background: none; color: var(--accent); padding: 2px 0;
  font-size: 12px; font-weight: 600; text-decoration: underline;
}
button.link:hover { color: #1a5fd0; }

.samples { display: grid; gap: 5px; margin-top: 8px; }
.samples button.try {
  display: block; width: 100%; text-align: left; font-size: 12px;
  padding: 6px 9px; margin: 0;
}

.widget .composer { padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }

.msg { margin-bottom: 16px; display: flex; flex-direction: column; }
.msg .who { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  max-width: 88%;
}
.msg.ai .bubble { background: var(--panel); }
.msg.human_agent .bubble { background: var(--warn-soft); border-color: #f0dcb8; }
.msg.system .bubble { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; }
.msg.emergency .bubble { background: var(--danger-soft); border-color: #f3c2be; color: #7a1a15; max-width: 100%; }

/* Alignment follows the viewer, not the role. Whoever is typing on this screen
   is `.mine` and sits on the right: the patient's own messages on /, the agent's
   own replies on /agent/{id}. Declared last so it wins over the role colours above. */
.msg.mine { align-items: flex-end; }
.msg.mine .bubble { background: var(--accent); border-color: var(--accent); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel);
}
.chip.grounded { color: var(--ok); border-color: #bfe0ce; }
.chip.general_information { color: var(--warn); border-color: #f0dcb8; }
.chip.unverified { color: var(--danger); border-color: #f3c2be; background: var(--danger-soft); }
.chip.src::before { content: "source: "; opacity: .65; }

.action-card {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin: 4px 0 16px;
}
.action-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.action-card .summary { margin: 6px 0 11px; font-weight: 550; }
.action-card .row { display: flex; gap: 8px; }
.action-card.done { border-color: #bfe0ce; background: #eef7f2; }
.action-card.done .label { color: var(--ok); }

.composer { display: flex; gap: 9px; padding-top: 12px; border-top: 1px solid var(--line); }
.composer input, .composer textarea {
  flex: 1; font: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
  resize: none;
}
.composer input:focus, .composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.hint { color: var(--muted); font-size: 12px; margin: 8px 2px 0; }
.hint button { padding: 3px 9px; font-size: 12px; margin: 3px 5px 0 0; }



/* ---------- agent workspace ---------- */

.workspace { display: grid; grid-template-rows: auto 1fr; height: 100vh; }

/* ---------- queue page (/agent) ---------- */

.queue-page { max-width: 1240px; margin: 24px auto; padding: 0 18px; }
.queue-intro { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

.queue-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }

.queue-column { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.queue-column-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.queue-column-head .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
.queue-column-head .count {
  font-size: 12px; font-weight: 700; min-width: 22px; text-align: center;
  border-radius: 999px; padding: 2px 7px; background: var(--bg); color: var(--muted);
}
.queue-column .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.queue-column-body { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* One accent per column, so urgency reads at a glance without a legend. */
.queue-column.p0 { border-top: 3px solid var(--danger); }
.queue-column.p0 .label, .queue-column.p0 .order { color: var(--danger); }
.queue-column.p0 .count { background: var(--danger-soft); color: var(--danger); }
.queue-column.p1 { border-top: 3px solid var(--warn); }
.queue-column.p1 .label, .queue-column.p1 .order { color: var(--warn); }
.queue-column.p1 .count { background: var(--warn-soft); color: var(--warn); }
.queue-column.p2 { border-top: 3px solid var(--accent); }
.queue-column.p2 .label, .queue-column.p2 .order { color: var(--accent); }
.queue-column.p2 .count { background: var(--accent-soft); color: var(--accent); }

.queue-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px;
}
.queue-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.queue-card.claimed { opacity: .72; }

.queue-card-head { display: flex; align-items: center; gap: 8px; }
.queue-card-head .order {
  font-weight: 800; font-size: 13px; min-width: 20px;
  border: 1px solid currentColor; border-radius: 6px; text-align: center; padding: 0 4px;
}
.queue-card-head .id { font-weight: 650; font-size: 13px; }
.queue-card-head .chip { margin-left: auto; }
.queue-card .intent { margin-top: 8px; font-weight: 550; font-size: 14px; }
.queue-card .reason { margin-top: 4px; font-size: 12px; color: var(--muted); }
.queue-card-foot {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}

.queue-empty {
  color: var(--muted); font-size: 13px; padding: 18px 8px;
  text-align: center; border: 1px dashed var(--line); border-radius: 8px;
}

.bar-left { display: flex; align-items: baseline; gap: 12px; }
.back { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600; }
.back:hover { text-decoration: underline; }

.panes { display: grid; grid-template-columns: 270px 1fr 320px; gap: 1px; background: var(--line); min-height: 0; }
.pane { background: var(--panel); padding: 15px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }
.pane h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 12px; font-weight: 700;
}

.field { margin-bottom: 11px; }
.field .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field .v { font-weight: 500; word-break: break-word; }
.field .v.empty { color: var(--muted); font-weight: 400; font-style: italic; }

.pane .transcript { flex: 1; overflow-y: auto; margin-bottom: 12px; }
.pane .composer { border-top: 1px solid var(--line); }

.suggestion {
  border: 1px dashed var(--accent); background: var(--accent-soft);
  border-radius: 8px; padding: 11px; margin-bottom: 11px; font-size: 14px;
}
.suggestion .label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.suggestion p { margin: 6px 0 9px; white-space: pre-wrap; }

.stack { display: flex; flex-direction: column; gap: 7px; margin-top: auto; padding-top: 13px; border-top: 1px solid var(--line); }
.stack .row { display: flex; gap: 7px; }
.stack .row button { flex: 1; }

ul.points { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

.ask-ai { display: grid; gap: 6px; margin: 4px 0 12px; }
.ask-ai label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ask-ai input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel); color: var(--ink);
}
.ask-ai input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.suggestion .draft {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 10px; white-space: pre-wrap;
}
.suggestion .warn-note { color: var(--warn); font-weight: 550; }

.prepared {
  border: 1px solid var(--accent); background: var(--accent-soft);
  border-radius: 8px; padding: 10px 11px; margin-top: 4px;
}
.prepared .label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.prepared .summary { margin: 6px 0 9px; font-weight: 550; font-size: 14px; }
.prepared .row { display: flex; gap: 7px; }

button.needs-more { border-color: #f0dcb8; color: var(--warn); }

/* Shown only when index.html and chat.js are from different builds. */
.build-mismatch {
  position: fixed; inset: 0 0 auto 0; z-index: 100;
  background: var(--danger-soft); color: #7a1a15;
  border-bottom: 2px solid var(--danger);
  padding: 14px 20px; font-size: 14px; line-height: 1.5;
}
.build-mismatch kbd {
  background: var(--panel); border: 1px solid #f3c2be; border-radius: 4px;
  padding: 1px 5px; font-size: 12px;
}
