:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #5b6b7c;
  --line: #dde4ec;
  --accent: #0e6ba8;
  --accent-dark: #0a5486;
  --good: #1a7f4f;
  --warn: #b07a1a;
  --bad: #b03030;
  --chip: #eef3f8;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: #12354e; color: #fff;
}
.brand-title { font-size: 1.15rem; font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: .72rem; opacity: .75; }
.topbar-study { flex: 1; font-size: .9rem; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }

/* ---- tabs ---- */
#tabs {
  display: flex; gap: 2px; padding: 0 20px;
  background: #12354e;
}
#tabs[hidden] { display: none; }

#question-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; background: #eaf2f9; border-bottom: 1px solid #cbdeee;
}
#question-bar[hidden] { display: none; }
#question-bar .qb-label { font-size: .8rem; font-weight: 600; color: #12354e; white-space: nowrap; }
#question-bar select { max-width: 900px; font-size: .85rem; }
.tab {
  border: none; background: transparent; color: #b9cbd9;
  padding: 9px 14px; cursor: pointer; font-size: .85rem;
  border-radius: 8px 8px 0 0;
}
.tab:hover { color: #fff; }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 600; }

/* ---- layout ---- */
#content { flex: 1; padding: 18px 20px 40px; max-width: 1500px; width: 100%; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
h2 { margin: 4px 0 6px; font-size: 1.25rem; }
h3 { margin: 0 0 10px; font-size: .98rem; }
.help { color: var(--muted); font-size: .85rem; margin: 4px 0 14px; max-width: 950px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.split { display: flex; gap: 14px; align-items: flex-start; }
.split .grow { flex: 1; min-width: 0; }
#thematic-reader { width: 320px; flex-shrink: 0; }
.row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.row input[type=text] { flex: 1; }

/* ---- controls ---- */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 12px; }
input[type=text], textarea, select {
  width: 100%; padding: 7px 9px; margin-top: 3px;
  border: 1px solid var(--line); border-radius: 7px;
  font: inherit; color: var(--ink); background: #fff;
}
textarea { resize: vertical; }
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: .84rem;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; opacity: .85; }
.btn.ghost:hover { opacity: 1; }
#topbar .btn.ghost { color: #fff; border-color: #ffffff66; }
.btn.primary { background: #2e9e6b; border-color: #2e9e6b; font-weight: 600; }
.btn.primary:hover { background: #24875a; }
.btn.tiny { padding: 2px 8px; font-size: .75rem; }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.pill {
  display: inline-block; background: var(--chip); border-radius: 20px;
  font-size: .72rem; padding: 2px 9px; color: var(--muted); font-weight: 500;
}

/* ---- tables ---- */
.scroll-x { overflow-x: auto; }
.tbl { border-collapse: collapse; width: 100%; font-size: .83rem; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: middle; }
.tbl th { background: #eef3f8; font-weight: 600; position: sticky; top: 0; }
.tbl td.c, .tbl th.c { text-align: center; }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:nth-child(even) { background: #fafbfd; }
.matrix td.cell {
  text-align: center; cursor: pointer; min-width: 34px; padding: 2px;
  user-select: none;
}
.matrix td.cell input {
  width: 40px; border: none; background: transparent; text-align: center; font: inherit; padding: 4px 0;
}
.matrix td.cell input:focus { outline: 2px solid var(--accent); border-radius: 4px; }
.matrix td.cell.nonzero { background: #e4f0e9; font-weight: 600; }
.matrix td.stmt { min-width: 260px; max-width: 380px; }
.matrix tfoot td, .tbl .totalrow td { background: #eef3f8; font-weight: 600; }
.grade { display: inline-block; min-width: 20px; text-align: center; border-radius: 5px; padding: 1px 7px; font-weight: 600; font-size: .78rem; }
.g1 { background: #d2ecdd; color: #14532d; }
.g2 { background: #e2f0d5; color: #365314; }
.g3 { background: #fdf0d2; color: #713f12; }
.g4 { background: #fde0d2; color: #7c2d12; }
.g5 { background: #fbd5d5; color: #7f1d1d; }
.action-utilise { color: var(--good); font-weight: 600; }
.action-investigate { color: var(--warn); font-weight: 600; }
.action-monitor { color: var(--bad); font-weight: 600; }

/* report matrix */
.report th, .report td { text-align: center; }
.report td.desc { text-align: left; font-size: .78rem; color: var(--muted); }
.report .sect { background: #12354e; color: #fff; font-weight: 700; }

/* ---- misc ---- */
.rq-banner {
  background: #eaf2f9; border: 1px solid #cbdeee; border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem;
}
.resp-card { margin-bottom: 10px; }
.resp-card textarea { width: 100%; }
.resp-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.resp-head .who { font-weight: 600; font-size: .88rem; }
.resp-head .meta { font-size: .74rem; color: var(--muted); }
.reader-text {
  white-space: pre-wrap; font-size: .85rem; line-height: 1.5;
  background: #fbfcfe; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin-top: 8px; max-height: 260px; overflow-y: auto;
}

/* thematic coding list */
#coding-list { max-height: 340px; overflow-y: auto; }
.code-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 8px; margin-bottom: 5px; cursor: pointer;
  font-size: .8rem; user-select: none; background: #fff;
}
.code-item:hover { border-color: var(--accent); }
.code-item.on { background: #e4f0e9; border-color: #9fd0b3; }
.code-check {
  width: 18px; height: 18px; flex-shrink: 0; border-radius: 5px;
  border: 1px solid var(--line); background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: #14532d;
}
.code-item.on .code-check { background: #1a7f4f; border-color: #1a7f4f; color: #fff; }
.code-stmt { flex: 1; line-height: 1.3; }
.code-ctrls { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.code-count { min-width: 18px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.code-ctrls .btn { padding: 0 7px; line-height: 1.4; }
.verdict { margin-top: 10px; font-size: .9rem; font-weight: 600; }
.verdict.ok { color: var(--good); }
.verdict.no { color: var(--bad); }
.legend { font-size: .78rem; color: var(--muted); line-height: 1.7; }
.legend b { color: var(--ink); }

#statusbar {
  display: flex; justify-content: space-between;
  padding: 6px 20px; font-size: .75rem; color: var(--muted);
  border-top: 1px solid var(--line); background: #fff;
}
ol#final-items li, ol#excluded-items li { font-size: .85rem; margin-bottom: 4px; }

@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
  .split { flex-direction: column; }
  #thematic-reader { width: 100%; }
}

/* print survey */
@media print {
  #topbar, #tabs, #statusbar, .panel { display: none !important; }
  #print-area { display: block !important; }
}
#print-area { display: none; padding: 30px; font-size: 12pt; }
#print-area table { border-collapse: collapse; width: 100%; margin-top: 14px; }
#print-area th, #print-area td { border: 1px solid #444; padding: 6px 8px; font-size: 10pt; }

/* AI suggestion panel */
#ai-suggest-panel {
  border: 1px solid #cbdeee; background: #f3f8fc; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 12px;
}
#ai-suggest-panel[hidden] { display: none; }
#ai-suggest-panel h4 { margin: 0 0 8px; font-size: .92rem; }
.ai-sugg {
  display: flex; align-items: flex-start; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px;
}
.ai-sugg.rejected { opacity: .45; }
.ai-sugg.rejected input { text-decoration: line-through; }
.ai-sugg .grow { flex: 1; min-width: 0; }
.ai-sugg input.ai-stmt { width: 100%; font-weight: 600; margin-bottom: 4px; }
.ai-sugg input.ai-domain { max-width: 180px; font-size: .8rem; }
.ai-sugg .ai-meta { font-size: .76rem; color: var(--muted); margin-top: 3px; }
.ai-sugg .ai-actions { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }

/* progress timeline */
.tl-tiles { display: flex; gap: 12px; flex-wrap: wrap; }
.tl-tile {
  flex: 1; min-width: 110px; text-align: center;
  background: #f3f8fc; border: 1px solid #cbdeee; border-radius: 10px; padding: 12px 8px;
}
.tl-tile .n { font-size: 1.6rem; font-weight: 700; color: #12354e; }
.tl-tile .l { font-size: .74rem; color: var(--muted); }
.tl-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .78rem; margin-bottom: 8px; }
.tl-legend .swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 5px; vertical-align: baseline;
}
.tl-axis {
  display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted);
  margin: 0 0 6px 130px;
}
.tl-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.tl-name { width: 120px; font-size: .8rem; font-weight: 600; flex-shrink: 0; text-align: right; }
.tl-track {
  position: relative; flex: 1; height: 24px;
  background: #f0f4f8; border-radius: 6px; overflow: visible;
}
.tl-bar {
  position: absolute; top: 50%; height: 8px; transform: translateY(-50%);
  border-radius: 4px; opacity: .3;
}
.tl-dot {
  position: absolute; top: 50%; width: 13px; height: 13px; border-radius: 50%;
  transform: translate(-50%, -50%); border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2); cursor: default;
}

/* CR2 readiness checklist */
input[type=number] {
  padding: 7px 9px; margin-top: 3px; border: 1px solid var(--line);
  border-radius: 7px; font: inherit; color: var(--ink); background: #fff;
}
.ready-check { font-size: .82rem; font-weight: 600; margin: 7px 0; line-height: 1.35; }
.ready-check.ok { color: var(--good); }
.ready-check.no { color: var(--bad); }
.ready-check .rc-detail { font-weight: 400; color: var(--muted); font-size: .78rem; }
