/* Admin dashboard (dashboard.py). Served from this server only; the CSP forbids inline styles and scripts. */
:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #5d6677; --line: #dde1e8;
  --accent: #b8862b; --accent-text: #fff; --ok: #1f7a4d; --error: #b42318; --changed: #fff4d6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Noto Sans Thai", "Sarabun", system-ui, sans-serif; }
header { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
header nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
header nav a { padding: 6px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
header nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
main { max-width: 1280px; margin: 0 auto; padding: 16px 20px 48px; }
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
a { color: #7a5614; }
.hint { color: var(--muted); font-size: 0.9rem; }
.ok { color: var(--ok); font-weight: 600; }
.error { color: var(--error); font-weight: 600; }
.changed { background: var(--changed); font-weight: 700; padding: 0 4px; }
.scroll { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { background: #eef0f4; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); text-align: center; }
form.filters, form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 8px; }
form.inline { margin: 2px 0; }
form.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 10px; }
form.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
form.grid .hint, form.grid button { grid-column: 1 / -1; justify-self: start; margin: 0; }
input, select, button { font: inherit; padding: 5px 8px; border: 1px solid #c3c9d4; border-radius: 6px; background: #fff; }
button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); cursor: pointer; }
button.secondary { background: #fff; color: var(--text); border-color: #c3c9d4; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }
meter { width: 120px; vertical-align: middle; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-top: 20px; }
figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
figcaption { font-weight: 600; margin-bottom: 4px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .bar { fill: var(--accent); }
svg.chart .bar:hover { fill: #8c641c; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .base { stroke: var(--line); }
section.login { max-width: 360px; margin: 10vh auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 24px; }
section.login form { display: flex; flex-direction: column; gap: 12px; }
section.login label { display: flex; flex-direction: column; gap: 4px; }
dl.lead { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; }
dl.lead dt { color: var(--muted); }
dl.lead dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
code { font-size: 0.85em; background: #eef0f4; padding: 0 4px; border-radius: 4px; }
.tip { border-bottom: 1px dotted var(--muted); cursor: help; }
.chip { display: inline-block; background: #f3ead8; border-radius: 10px; padding: 0 8px; margin: 1px 0; font-size: 0.85rem; }
details.legend { margin: 10px 0 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
details.legend summary { cursor: pointer; font-weight: 600; }
details.legend dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 0; font-size: 0.9rem; }
details.legend dd { margin: 0; color: var(--muted); }
.msg { white-space: pre-wrap; word-break: break-word; max-width: 560px; }
td .msg { white-space: pre-wrap; }
.who-in { font-weight: 700; color: #7a5614; }
.who-out { color: var(--muted); }
textarea { font: inherit; padding: 6px 8px; border: 1px solid #c3c9d4; border-radius: 6px; width: 100%; }
form.grid label:has(input[type=checkbox]) { flex-direction: row; align-items: center; gap: 8px; }
p.result { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
ul.tree, ul.tree ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px solid var(--line); }
ul.tree { padding-left: 0; border-left: none; }
ul.tree li { margin: 4px 0; }
section.flow { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 16px 12px; margin: 14px 0; }
.node { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.node .name { min-width: 180px; }
svg.pct .track { fill: #eef0f4; }
svg.pct .bar { fill: var(--accent); }
a.drill { font-size: 0.85rem; }
ol.path { margin: 0; padding-left: 18px; font-size: 0.85rem; }
ol.path li { margin: 1px 0; }
/* Rule page (2026-11-04): prompt sections and the horizontal decision tree. Collapse uses a checkbox + label,
   no script. Colours: green = answered by the bot, amber = asked back / lead, red = handed off / blocked / error. */
nav.toc { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 8px; }
h3 { font-size: 1rem; margin: 18px 0 6px; }
pre.prompt { white-space: pre-wrap; word-break: break-word; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: 0.85rem; margin: 6px 0; max-height: 420px; overflow: auto; }
details.psec { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin: 6px 0; }
details.psec summary { cursor: pointer; font-weight: 600; }
p.warn { background: #fff4d6; border: 1px solid #e8c56b; border-radius: 8px; padding: 8px 12px; }
.chip.tone-good { background: #dcf3e6; } .chip.tone-ask { background: #fdf0c8; }
.chip.tone-handoff, .chip.tone-bad { background: #fde2df; } .chip.tone-neutral { background: #eef0f4; }
p.legend { font-size: 0.85rem; color: var(--muted); }
p.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 4px 0 10px; vertical-align: -1px; }
.htree { overflow-x: auto; padding: 8px 2px 16px; }
.hn { display: flex; align-items: flex-start; gap: 0; position: relative; }
.hn > .tg { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.hn > .tg:not(:checked) ~ .kids { display: none; }
.hn > .tg:checked ~ .card .cl, .hn > .tg:not(:checked) ~ .card .op { display: none; }
.hn > .tg:focus-visible + .card { outline: 2px solid var(--accent); outline-offset: 2px; }
.kids { display: flex; flex-direction: column; gap: 8px; padding-left: 28px; margin-left: 0;
  border-left: 2px solid var(--line); position: relative; }
.kids > .hn::before { content: ""; position: absolute; left: -28px; top: 28px; width: 26px; border-top: 2px solid var(--line); }
.card { width: 230px; flex: none; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid #9aa3b2;
  border-radius: 8px; padding: 8px 10px; margin-right: 0; font-size: 0.85rem; }
.hn > .card { margin-right: 0; }
.card .ct { font-weight: 700; font-size: 0.92rem; }
.card .cn strong { font-size: 1.35rem; }
.card .recent { color: #c2410c; font-weight: 600; }
.card .pc { float: right; font-weight: 700; font-size: 1.05rem; }
.card .cd { color: var(--muted); margin-top: 2px; }
.card .cm { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.card .ca { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.card .tgl { cursor: pointer; border: 1px solid #c3c9d4; border-radius: 12px; padding: 0 9px; font-weight: 700;
  background: #fff; user-select: none; margin-left: auto; }
.card.tone-good, .sw.tone-good { border-left-color: var(--ok); } .sw.tone-good { background: var(--ok); }
.card.tone-good .pc { color: var(--ok); }
.card.tone-ask { border-left-color: #c58a00; } .sw.tone-ask { background: #c58a00; } .card.tone-ask .pc { color: #9a6b00; }
.card.tone-bad { border-left-color: var(--error); } .sw.tone-bad { background: var(--error); } .card.tone-bad .pc { color: var(--error); }
.sw.tone-neutral { background: #9aa3b2; }
.card.tone-root { border-left-color: #3b5ba9; background: #eef2fb; }


/* chat page: bot on/off per customer */
.bot-on { color: #1a7f37; font-weight: 600; }
.bot-off { color: #b42318; font-weight: 600; }
td form.inline { display: inline-flex; margin: 2px 2px 2px 0; }

/* chat view: rows while a ticket is open (tk0..tk3 by opening order, tk-dry = DRY_RUN test ticket) */
.tk0 { --tk: #2f6fdb; --tk-bg: #eaf1fd; }
.tk1 { --tk: #b26200; --tk-bg: #fdf1e1; }
.tk2 { --tk: #17805a; --tk-bg: #e5f4ed; }
.tk3 { --tk: #8a3ffc; --tk-bg: #f1eafe; }
.tk-dry { --tk: #9aa3b2; --tk-bg: transparent; }
table.timeline tr[class^="tk"] td { background: var(--tk-bg); }
table.timeline tr[class^="tk"] td:first-child { box-shadow: inset 4px 0 0 var(--tk); }
table.timeline tr.tk-dry td:first-child { box-shadow: inset 4px 0 0 transparent; border-left: 4px dashed var(--tk); }
table.timeline tr.tk-mark td { font-weight: 600; color: var(--tk); white-space: normal; }
table.timeline tr.tk-mark.tk-dry td { font-weight: 400; }
.tk-key { display: inline-block; padding: 1px 8px; margin: 2px; border-radius: 10px; color: var(--tk);
  background: var(--tk-bg); border: 1px solid var(--tk); font-weight: 600; }
.tk-key.tk-dry { border-style: dashed; font-weight: 400; }

/* Ticket / CSAT page: SLA due soon / overdue */
.sla-near { color: #9a5b00; font-weight: 600; }
.sla-over { color: #b42318; font-weight: 700; }
