:root {
  --hue: 55;
  --bg: oklch(0.985 0.004 var(--hue));
  --surface: oklch(0.995 0.003 var(--hue));
  --panel: oklch(0.965 0.006 var(--hue));
  --line: oklch(0.9 0.008 var(--hue));
  --line-strong: oklch(0.82 0.01 var(--hue));
  --ink: oklch(0.24 0.012 var(--hue));
  --ink-2: oklch(0.44 0.012 var(--hue));
  --ink-3: oklch(0.58 0.01 var(--hue));
  --accent: oklch(0.56 0.15 45);
  --accent-ink: oklch(0.98 0.01 45);
  --accent-soft: oklch(0.95 0.03 45);
  --focus: oklch(0.6 0.16 45 / 0.45);
  --danger: oklch(0.52 0.17 25);
  --danger-soft: oklch(0.96 0.025 25);

  --a: oklch(0.52 0.13 150);
  --a-soft: oklch(0.95 0.035 150);
  --b: oklch(0.55 0.12 230);
  --b-soft: oklch(0.95 0.025 230);
  --c: oklch(0.62 0.13 80);
  --c-soft: oklch(0.96 0.04 80);
  --d: oklch(0.55 0.02 var(--hue));
  --d-soft: oklch(0.94 0.006 var(--hue));

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --t-xs: 0.75rem; --t-sm: 0.8125rem; --t-base: 0.9375rem; --t-md: 1.0625rem; --t-xl: 1.75rem;
  --r: 6px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--t-base)/1.5 var(--font); font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: inherit; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--t-xl); font-weight: 650; line-height: 1.15; }
h2 { font-size: var(--t-md); font-weight: 600; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-radius: 3px; }

.shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem;
  padding: 1.25rem 0.875rem; background: var(--panel); border-right: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: -0.01em; padding: 0 0.5rem; }
.brand span { font-weight: 450; color: var(--ink-3); }
.sidebar-cta { justify-content: center; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.125rem; }
.nav-group { margin: 0.875rem 0.5rem 0.25rem; font-size: 0.6875rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.sidebar nav a { padding: 0.4375rem 0.625rem; border-radius: var(--r); text-decoration: none; color: var(--ink-2); font-size: var(--t-sm); transition: background-color 140ms var(--ease); }
.sidebar nav a:hover { background: oklch(0.93 0.008 var(--hue)); color: var(--ink); }
.sidebar nav a[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.subhead { margin: 0.375rem 0 0; color: var(--ink-3); font-size: var(--t-sm); }

main { padding: 1.75rem clamp(1rem, 3vw, 2rem) 4rem; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.back { display: inline-block; font-size: var(--t-sm); color: var(--ink-3); text-decoration: none; margin-bottom: 0.25rem; }
.back::before { content: "← "; }
.back:hover { color: var(--ink); }

.summary { display: flex; margin: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.summary div { padding: 0.375rem 1rem; border-left: 1px solid var(--line); }
.summary div:first-child { border-left: 0; }
.summary dt { font-size: var(--t-xs); color: var(--ink-3); font-weight: 600; }
.summary dd { margin: 0; font-weight: 650; font-size: var(--t-md); }
.summary .s-a dt { color: var(--a); } .summary .s-b dt { color: var(--b); }
.summary .s-c dt { color: var(--c); } .summary .s-d dt { color: var(--d); }

.btn {
  display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.5rem 0.875rem;
  border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface);
  font: 550 var(--t-sm)/1.2 var(--font); color: var(--ink); text-decoration: none; cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--panel); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: oklch(0.5 0.15 45); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-soft); }
.btn-small { padding: 0.3125rem 0.625rem; font-size: var(--t-xs); }
.htmx-request.btn { opacity: 0.6; cursor: progress; }

.field { display: flex; flex-direction: column; gap: 0.3125rem; min-width: 11rem; flex: 1 1 11rem; }
.field.grow { flex: 2 1 16rem; }
.field > span { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
input, select, textarea {
  width: 100%; padding: 0.5rem 0.625rem; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font: inherit; font-size: var(--t-sm);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
textarea { resize: vertical; min-height: 4.5rem; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.hint { color: var(--ink-3); font-size: var(--t-sm); margin: 0.25rem 0 0; max-width: 65ch; }
.alert { padding: 0.625rem 0.875rem; border: 1px solid oklch(0.85 0.06 25); background: var(--danger-soft); color: oklch(0.4 0.14 25); border-radius: var(--r); font-size: var(--t-sm); }

.filters { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.grid { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.grid th { text-align: left; font-weight: 600; font-size: var(--t-xs); color: var(--ink-3); padding: 0.625rem 0.875rem; background: var(--panel); border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 0.625rem 0.875rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: oklch(0.975 0.006 var(--hue)); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid small { display: block; color: var(--ink-3); font-size: var(--t-xs); }
.grid abbr { text-decoration: none; }
.c-prio { width: 2.5rem; }
.clip { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.empty td { text-align: center; padding: 3rem 1rem; color: var(--ink-3); }
.empty a { color: var(--accent); font-weight: 600; }

.prio { display: inline-grid; place-items: center; width: 1.625rem; height: 1.625rem; border-radius: 5px; font-weight: 700; font-size: var(--t-xs); }
.prio-a { background: var(--a-soft); color: var(--a); }
.prio-b { background: var(--b-soft); color: var(--b); }
.prio-c { background: var(--c-soft); color: oklch(0.48 0.11 75); }
.prio-d { background: var(--d-soft); color: var(--d); }
.prio-none { color: var(--line-strong); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 2rem; align-items: start; }
.sheet fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 1.25rem 0 1.75rem; display: grid; gap: 1rem; }
.sheet fieldset:first-child { border-top: 0; padding-top: 0; }
.sheet legend { float: left; width: 100%; font-weight: 650; font-size: var(--t-md); margin-bottom: 0.25rem; padding: 0; }
.actions { display: flex; gap: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }

.criterion { display: grid; grid-template-columns: minmax(12rem, 1fr) auto; gap: 0.25rem 1.5rem; align-items: center; padding: 0.75rem 0; border-bottom: 1px dashed var(--line); }
.criterion-label { display: flex; flex-direction: column; }
.criterion-label strong { font-weight: 600; font-size: var(--t-sm); }
.criterion-label span { font-size: var(--t-xs); color: var(--ink-3); }
.criterion-scale { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 1rem; margin: 0; font-size: var(--t-xs); color: var(--ink-3); }
.scale { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.scale span { display: grid; place-items: center; width: 2.5rem; height: 2.25rem; font-weight: 600; font-size: var(--t-sm); color: var(--ink-2); border-left: 1px solid var(--line); transition: background-color 140ms var(--ease), color 140ms var(--ease); }
.scale label:first-child span { border-left: 0; }
.scale label:hover span { background: var(--panel); }
.scale input:checked + span { background: var(--accent); color: var(--accent-ink); }
.scale input:focus-visible + span { box-shadow: inset 0 0 0 2px var(--focus); }

.side { position: sticky; top: 4.5rem; display: grid; gap: 1rem; }
.score { display: grid; gap: 0.125rem; padding: 1rem 1.125rem; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); transition: background-color 220ms var(--ease); }
.score-label { font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); }
.score-value { font-size: 2.5rem; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.score-value small { font-size: var(--t-sm); color: var(--ink-3); font-weight: 500; margin-left: 0.125rem; }
.score-value.muted { color: var(--line-strong); }
.score-prio { font-weight: 600; font-size: var(--t-sm); color: var(--ink-2); }
.score-a { background: var(--a-soft); border-color: oklch(0.85 0.06 150); } .score-a .score-prio { color: var(--a); }
.score-b { background: var(--b-soft); border-color: oklch(0.86 0.04 230); } .score-b .score-prio { color: var(--b); }
.score-c { background: var(--c-soft); border-color: oklch(0.86 0.07 80); } .score-c .score-prio { color: oklch(0.48 0.11 75); }
.score-d { background: var(--d-soft); }

.panel { padding: 1rem 1.125rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.panel h2 { font-size: var(--t-sm); margin-bottom: 0.5rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.panel-head h2 { margin: 0; }
.panel details { border-top: 1px solid var(--line); padding: 0.5rem 0; }
.panel summary { cursor: pointer; font-size: var(--t-sm); list-style: none; display: flex; gap: 0.5rem; align-items: baseline; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary:hover { color: var(--accent); }
.tag { flex: none; font-size: 0.6875rem; font-weight: 600; padding: 0.0625rem 0.375rem; border-radius: 4px; background: var(--accent-soft); color: oklch(0.45 0.12 45); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.75rem; margin: 0.5rem 0 0; font-size: var(--t-xs); }
.kv dt { color: var(--ink-3); font-weight: 600; text-transform: capitalize; }
.kv dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: 0.5rem 0.75rem; text-decoration: none; color: var(--ink-2); font-size: var(--t-sm); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.ref { margin-bottom: 2.5rem; scroll-margin-top: 5rem; }
.ref h2 { margin-bottom: 0.75rem; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .side { position: static; order: -1; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
}
@media (max-width: 560px) {
  .criterion { grid-template-columns: 1fr; }
  .scale span { width: 2.75rem; height: 2.75rem; }
  .summary { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
