/* Admin panel (SPEC §10.2): mobile first, one column; the thread page gets a rail on wide screens. */
:root {
  --bg: #f4f5f7; --card: #fff; --text: #1b1f24; --muted: #6b7280; --line: #e3e6ea;
  --accent: #2563eb; --accent-ink: #fff; --ok: #15803d; --warn: #b45309; --danger: #b91c1c;
  --info: #0e7490; --lead: #f1f5f9; --agent: #e0ecff; --human: #fef3c7; --automation: #ede9fe;
  --radius: 12px; --pad: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #171b21; --text: #e6e8eb; --muted: #9aa3ad; --line: #2a3038;
    --accent: #3b82f6; --lead: #1f252d; --agent: #1b2a44; --human: #3a2e12; --automation: #2b2440;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: 0.9rem; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
code { font-size: .9em; background: var(--lead); padding: 1px 5px; border-radius: 5px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0; font-size: .85rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.bad { color: var(--danger); }
.empty { padding: 24px 0; text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px var(--pad); background: var(--card); border-bottom: 1px solid var(--line);
  padding-top: calc(8px + env(safe-area-inset-top));
}
.nav { display: flex; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; min-width: 0; scrollbar-width: none; }
.nav::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 10px; border-radius: 999px; color: var(--text); white-space: nowrap; font-weight: 500; }
.nav a.active { background: var(--accent); color: var(--accent-ink); }
.topbar-right { display: flex; align-items: center; gap: 4px; flex: none; }
.mode-pill { font-size: .75rem; font-weight: 700; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--lead); }
body.mode-live .mode-pill { background: var(--danger); color: #fff; }
.mode-text-live { color: var(--danger); } .mode-text-shadow { color: var(--ok); }
button.link { background: none; border: 0; color: var(--muted); padding: 6px 4px; font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap; min-height: 0; }

.page { max-width: 1100px; margin: 0 auto; padding: var(--pad); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); margin: 0 0 12px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: .95rem; }
.flash.ok { background: #dcfce7; color: #14532d; }
.flash.bad { background: #fee2e2; color: #7f1d1d; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], textarea {
  width: 100%; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
textarea.editor { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 240px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
button, .button {
  font: inherit; font-weight: 600; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer; min-height: 44px; display: inline-block;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.danger-outline, .button.danger-outline { color: var(--danger); border-color: var(--danger); }
button[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: flex-start; }
.actions form { margin: 0; }
details.inline { flex: 1 1 100%; }
details.inline > summary { list-style: none; width: max-content; }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline[open] > summary { margin-bottom: 10px; }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-button { min-height: 36px; padding: 6px 10px; border-radius: 999px; font-weight: 500; font-size: .9rem; }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 2px; scrollbar-width: none; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); white-space: nowrap; font-size: .9rem; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--lead); color: var(--muted); text-transform: lowercase; vertical-align: middle; }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-warn { background: #fef3c7; color: var(--warn); }
.badge-info { background: #cffafe; color: var(--info); }
.badge-ok { background: #dcfce7; color: var(--ok); }
.badge-draft { background: var(--accent); color: var(--accent-ink); }
.badge-stage { background: transparent; border: 1px solid var(--line); }

.threads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.thread-row { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px var(--pad); color: var(--text); }
.thread-top { display: flex; justify-content: space-between; gap: 8px; }
.thread-top .name { font-weight: 600; }
.thread-top .when, .msg-meta .when { color: var(--muted); font-size: .8rem; }
.thread-mid { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.preview { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.who { font-weight: 600; font-size: .8rem; text-transform: capitalize; }
.who-lead { color: var(--info); } .who-agent { color: var(--accent); } .who-human { color: var(--warn); } .who-automation { color: #7c3aed; }

.thread-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; margin-bottom: 10px; }
.thread-head h1 { margin: 0; }
.back { font-size: .9rem; }
.status { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1 1 100%; }
.thread-layout { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .thread-layout { grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); align-items: start; } }

.transcript { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 14px; background: var(--lead); }
.msg-lead { align-self: flex-start; background: var(--lead); border-bottom-left-radius: 4px; }
.msg-agent { align-self: flex-end; background: var(--agent); border-bottom-right-radius: 4px; }
.msg-human { align-self: flex-end; background: var(--human); border-bottom-right-radius: 4px; }
.msg-automation { align-self: flex-end; background: var(--automation); border-bottom-right-radius: 4px; }
.msg-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-attachment { font-size: .85rem; color: var(--muted); font-style: italic; }

.draft { border-color: var(--accent); }
.chunk { margin: 0 0 8px; padding: 8px 12px; background: var(--agent); border-radius: 12px; white-space: pre-wrap; }
.chunk.small { padding: 6px 10px; }
.decided { padding: 8px 0; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 4px 10px; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.brief { font-size: .85rem; background: var(--lead); padding: 10px; border-radius: 10px; }
.tools { padding-left: 18px; } .tools li { margin-bottom: 8px; }
.verdicts { padding-left: 18px; }
summary { cursor: pointer; }
details.card > summary { margin: -2px 0; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
table.stats { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.stats th, table.stats td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.stats thead th { color: var(--muted); font-weight: 600; }
table.stats tbody th { font-weight: 500; }
table.stats td { white-space: nowrap; }

.replay-row { border-top: 1px solid var(--line); padding: 10px 0; }
.replay-step { margin: 8px 0; }
.replay-step .inbound { font-size: .9rem; margin-bottom: 4px; }
.side-by-side { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 700px) { .side-by-side { grid-template-columns: 1fr 1fr; } }
.side-by-side .label { font-size: .7rem; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.mode-card { border-color: var(--warn); }
