:root {
  --bg: #0D1117;
  --surface: #1E293B;
  --surface-2: #162032;
  --border: #2D3B50;
  --text: #E6EDF3;
  --muted: #94A3B8;
  --faint: #64748B;
  --q1: #7DD3FC;
  --q2: #3B82F6;
  --q3: #F87171;
  --c: #3B82F6;
  --a: #10B981;
  --r: #F59E0B;
  --yes: #34D399;
  --partial: #FBBF24;
  --no: #F87171;
  --unknown: #64748B;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--q1); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.narrow { max-width: 820px; }

header.top {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between;
  margin-bottom: 20px;
}
header.top p { margin: 4px 0 0; }
.top-meta { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  background: none; border: 0; color: var(--muted); padding: 10px 14px; font: inherit; font-weight: 550;
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--q2); }

/* ---- Cards & grids ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stack > * + * { margin-top: 16px; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.8rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 1px; }

.chart-box { position: relative; height: 340px; }
.chart-box.sm { height: 190px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); }
.legend span::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px;
  background: var(--sw); vertical-align: -1px;
}

.construct-card { border-top: 3px solid var(--cc); }

/* ---- Alignment badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; border: 1px solid; white-space: nowrap;
}
.badge.yes     { color: var(--yes);     border-color: color-mix(in srgb, var(--yes) 45%, transparent);     background: color-mix(in srgb, var(--yes) 12%, transparent); }
.badge.partial { color: var(--partial); border-color: color-mix(in srgb, var(--partial) 45%, transparent); background: color-mix(in srgb, var(--partial) 12%, transparent); }
.badge.no      { color: var(--no);      border-color: color-mix(in srgb, var(--no) 45%, transparent);      background: color-mix(in srgb, var(--no) 12%, transparent); }
.badge.unknown { color: var(--muted);   border-color: var(--border); background: transparent; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.align-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.align-row:last-child { border-bottom: 0; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.C { color: var(--c); } .pill.A { color: var(--a); } .pill.R { color: var(--r); }
.star { color: var(--partial); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
tr.inactive td { opacity: .5; }

/* ---- Forms ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; font: inherit; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--q2); outline-offset: 1px; }

.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 14px; font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--q2); border-color: var(--q2); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--no); }
.btn.sm { padding: 3px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.notice.error { border-color: color-mix(in srgb, var(--no) 50%, transparent); color: var(--no); }
.notice.ok { border-color: color-mix(in srgb, var(--yes) 50%, transparent); color: var(--yes); }

/* ---- Survey ---- */
.survey-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.survey-meta label { display: block; font-weight: 600; margin-bottom: 6px; }
.survey-meta select { width: 100%; }
.q { padding: 16px 0; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q.missing .q-text { color: var(--no); }
.q-text { margin: 0 0 10px; font-weight: 500; }
.q-num { color: var(--faint); margin-right: 6px; font-variant-numeric: tabular-nums; }
.likert { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.likert label {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; text-align: center; font-size: .78rem; color: var(--muted);
}
.likert label:hover { border-color: var(--muted); }
.likert input { position: absolute; opacity: 0; pointer-events: none; }
.likert label:has(input:checked) { border-color: var(--q2); background: color-mix(in srgb, var(--q2) 22%, var(--surface-2)); color: var(--text); }
.likert label:has(input:focus-visible) { outline: 2px solid var(--q2); outline-offset: 1px; }
.likert .v { font-size: 1rem; font-weight: 650; color: var(--text); }
.progress { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0; }
.progress-bar { height: 4px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.progress-bar > div { height: 100%; width: 0; background: var(--q2); transition: width .2s; }

/* ---- Admin ---- */
.admin-table td { padding: 6px; }
.admin-table input[type="text"], .admin-table textarea, .admin-table select { width: 100%; font-size: .85rem; padding: 5px 7px; }
.admin-table input[type="number"] { width: 64px; font-size: .85rem; padding: 5px 7px; }
.admin-table textarea { min-width: 260px; min-height: 76px; }
.admin-table tr.dirty td { background: color-mix(in srgb, var(--partial) 7%, transparent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }

@media (max-width: 560px) {
  .likert { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .likert .lbl { display: none; }
  .chart-box { height: 280px; }
}

/* ---- Survey chooser / segmented switch ---- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.choice {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left;
  padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font: inherit; cursor: pointer;
}
.choice strong { font-size: 1.05rem; }
.choice:hover { border-color: var(--q2); background: color-mix(in srgb, var(--q2) 12%, var(--surface-2)); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { background: none; border: 0; color: var(--muted); padding: 7px 14px; font: inherit; font-weight: 550; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--q2); color: #fff; }
