:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6876;
  --border: #dfe3e8;
  --primary: #1f5fa8;
  --primary-ink: #ffffff;
  --primary-soft: #e8f0fa;
  --ok: #1d7a46;
  --ok-soft: #e3f3e9;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; background: #eef1f4; padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 1.45rem; margin: 0 0 6px; }
h2 { font-size: 1.1rem; margin: 28px 0 10px; }
.lead { color: var(--muted); margin: 0 0 16px; }
.hint, .small { color: var(--muted); font-size: 0.86rem; }
.empty { color: var(--muted); padding: 24px 0; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; padding: 7px 11px; border-radius: 7px; font-size: 0.92rem; }
nav a:hover { background: var(--bg); color: var(--text); }
nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.offline { background: var(--warn-soft); color: var(--warn); text-align: center; padding: 6px 16px; font-size: 0.88rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.chat-page { max-width: 820px; }

/* messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.notice { background: var(--primary-soft); color: #20406a; border-radius: var(--radius); padding: 12px 14px; font-size: 0.9rem; margin-bottom: 16px; }

/* chat */
.chat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; display: flex; flex-direction: column; height: min(68vh, 680px); min-height: 420px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: #eef1f4; border-bottom-left-radius: 4px; }
.msg.pending .bubble { color: var(--muted); font-style: italic; }
.msg.error .bubble { background: var(--bad-soft); color: var(--bad); }
.meta { font-size: 0.78rem; color: var(--muted); margin-top: 4px; padding: 0 4px; }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; min-height: 44px; max-height: 160px; font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.composer textarea:focus, input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.composer-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.config { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: row; align-items: center; gap: 8px; }

/* forms */
button { font: inherit; font-weight: 600; background: var(--primary); color: var(--primary-ink); border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; min-height: 40px; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
select, input[type=text], input[type=password], input[type=file] { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.config select { padding: 5px 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card form, .upload { display: flex; flex-direction: column; gap: 14px; }
.upload { max-width: 560px; }
.upload button, .card button { align-self: flex-start; }
.inline-form { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.run-pick { margin: 10px 0; }
.run-pick label { flex-direction: row; align-items: center; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { background: #f1f3f6; font-weight: 600; color: #3a4552; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
td.answer { max-width: 380px; white-space: pre-wrap; }
details summary { cursor: pointer; color: var(--primary); white-space: nowrap; }
.ctx { white-space: pre-wrap; font-size: 0.8rem; background: #f6f7f9; border-radius: 6px; padding: 8px; margin-top: 6px; max-width: 460px; }
.ctx-head { display: block; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 8px 0 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-label { color: var(--muted); font-size: 0.82rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: 0.78rem; }
.report-table td { font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  .msg { max-width: 95%; }
  .chat { height: 72vh; }
  h1 { font-size: 1.25rem; }
}
td.wide { min-width: 260px; }

/* SUS questionnaire */
.sus { max-width: 880px; margin: 0 auto; }
.sus-block { margin-bottom: 16px; }
.sus-block h2 { font-size: 1.05rem; margin: 0 0 10px; }
.sus-tasks { margin: 10px 0; padding-left: 22px; line-height: 1.7; }
.sus-form { display: block; }
.sus-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.sus-grid input[type=text], .sus-grid select { padding: 8px 10px; font: inherit; border: 1px solid var(--border); border-radius: 8px; }
.sus-inline { border: 0; padding: 0; margin: 0; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.sus-inline legend { font-size: 0.9rem; margin-bottom: 6px; width: 100%; }
.sus-inline label { flex-direction: row; align-items: center; gap: 6px; }
.sus-table td.num, .sus-table th.num { text-align: center; width: 44px; }
.sus-choice { display: flex; justify-content: center; padding: 4px; cursor: pointer; }
.sus-choice input { width: 18px; height: 18px; cursor: pointer; }
.sus-consent { flex-direction: row; align-items: flex-start; gap: 10px; margin-bottom: 14px; font-size: 0.92rem; }
.sus-consent input { margin-top: 3px; }
.button-link { display: inline-block; background: var(--primary); color: var(--primary-ink); text-decoration: none; padding: 9px 16px; border-radius: 10px; font-weight: 600; }
