:root {
  --bg: oklch(1 0 0);
  --surface: oklch(.97 .006 250);
  --ink: oklch(.22 .025 255);
  --muted: oklch(.48 .025 255);
  --line: oklch(.89 .012 250);
  --structure: oklch(.27 .055 250);
  --structure-2: oklch(.33 .06 250);
  --action: oklch(.48 .105 190);
  --action-dark: oklch(.39 .09 190);
  --risk: oklch(.45 .15 330);
  --success: oklch(.94 .045 165);
  --warning: oklch(.95 .055 85);
  --radius: 10px;
  --shadow: 0 12px 35px oklch(.22 .025 255/.08);
  --sidebar-w: 252px;
  --sidebar-w-collapsed: 78px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); color: var(--ink); font-size: 14px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }

/* ── Shell & sidebar ─────────────────────────────── */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  padding: 22px 16px;
  background: var(--structure);
  color: oklch(.97 .006 250);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 200ms ease;
  z-index: 30;
}
.main { margin-left: var(--sidebar-w); transition: margin-left 200ms ease; min-height: 100vh; display: flex; flex-direction: column; }
.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

/* Brand */
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 0 6px 24px; white-space: nowrap; }
.brand-mark { width: 38px; height: 38px; flex: none; display: grid; place-items: center; background: var(--action); color: white; border-radius: 9px; font-weight: 800; letter-spacing: -.03em; }
.brand-mark.large { width: 56px; height: 56px; font-size: 18px; }
.brand-text { display: grid; min-width: 0; }
.brand-text strong { font-size: 16px; line-height: 1.25; }
.brand-text small { margin-top: 2px; color: oklch(.79 .02 250); font-size: 11px; }
.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar-collapsed .brand-text { display: none; }

/* Nav groups */
.nav { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; }
.nav-label {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: oklch(.7 .02 250); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; cursor: pointer;
}
.nav-label:hover { color: white; }
.nav-label .chev { transition: transform 180ms ease; }
.nav-group.open .nav-label .chev { transform: rotate(180deg); }
.nav-children { display: grid; gap: 3px; overflow: hidden; transition: max-height 200ms ease; }
.nav-children a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 8px; text-decoration: none;
  color: oklch(.82 .02 250); white-space: nowrap; transition: background 160ms ease, color 160ms ease;
}
.nav-children a:hover, .nav-children a:focus-visible { background: oklch(.34 .055 250); color: white; }
.nav-children a.active { background: var(--action); color: white; font-weight: 700; }

/* Collapsed rail mode */
.sidebar-collapsed .nav-label { justify-content: center; padding: 8px 4px; }
.sidebar-collapsed .nav-label span, .sidebar-collapsed .nav-label .chev { display: none; }
.sidebar-collapsed .nav-children { max-height: none !important; display: grid; gap: 3px; }
.sidebar-collapsed .nav-children a { justify-content: center; padding: 11px; }
.sidebar-collapsed .nav-children a span { display: none; }
.sidebar-collapsed .nav-children a { margin: 0 0 2px; }

/* Sidebar foot / user */
.sidebar-foot { margin-top: auto; padding: 18px 6px 0; border-top: 1px solid oklch(.44 .04 250); display: grid; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--structure-2); color: white; font-weight: 800; }
.user-meta { display: grid; min-width: 0; }
.user-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: oklch(.76 .025 250); margin-top: 1px; text-transform: capitalize; }
.sidebar-collapsed .user-chip { justify-content: center; }
.sidebar-collapsed .user-meta { display: none; }
.link-button { border: 0; background: none; color: oklch(.82 .06 190); padding: 0; cursor: pointer; text-align: left; }
.link-button:hover { text-decoration: underline; }
.sidebar-collapsed .sidebar-foot form { display: none; }

/* ── Topbar ──────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: 66px; padding: 12px 26px;
  background: oklch(.995 .004 250/.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
}
.icon-button {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 9px; background: white;
  color: var(--muted); cursor: pointer; transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.icon-button:hover { background: var(--surface); color: var(--ink); border-color: oklch(.8 .012 250); }
.topbar-title { display: grid; }
.topbar-title strong { font-size: 18px; line-height: 1.3; }
.topbar-title span { margin-top: 1px; color: var(--muted); font-size: 13px; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; }
.period { padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 12px; background: white; white-space: nowrap; }

.content { width: 100%; max-width: 1440px; padding: 26px; margin: 0 auto; }

/* ── Metrics ─────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 22px; }
.metrics > div { padding: 19px 22px; }
.metrics > div + div { border-left: 1px solid var(--line); }
.metrics span, .metrics small { display: block; color: var(--muted); }
.metrics strong { display: block; margin: 4px 0 2px; font-size: 28px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

.split { display: grid; grid-template-columns: minmax(0, 2.25fr) minmax(270px, .75fr); gap: 22px; }
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px oklch(.22 .025 255/.03); }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.panel h2 { font-size: 16px; margin: 0; }
.panel p { color: var(--muted); margin: 4px 0 0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: var(--surface); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .055em; }
tbody tr:hover { background: oklch(.985 .004 250); }
tbody tr:last-child td { border-bottom: 0; }
.rank { display: inline-grid; place-items: center; width: 27px; height: 27px; border-radius: 8px; background: var(--structure); color: white; font-weight: 800; }

.method { padding: 20px; }
.method ol { list-style: none; padding: 0; margin: 18px 0; display: grid; }
.method li { display: grid; grid-template-columns: 36px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.method li strong { color: var(--action-dark); }
.method li span { color: var(--muted); }
.audit-note { padding: 12px; background: var(--success); border-radius: 8px; color: oklch(.31 .06 165) !important; }

/* ── Controls ────────────────────────────────────── */
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent; text-decoration: none; font-weight: 700; cursor: pointer; transition: background 160ms ease, border-color 160ms ease; }
.button.primary { background: var(--action); color: white; }
.button.primary:hover { background: var(--action-dark); }
.button.secondary { background: white; border-color: var(--line); color: var(--ink); }
.button.secondary:hover { background: var(--surface); }
.button.danger { background: oklch(.93 .04 330); border-color: oklch(.86 .06 330); color: oklch(.36 .12 330); }
.button.danger:hover { background: oklch(.9 .05 330); }
.button.small { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid oklch(.74 .11 190); outline-offset: 2px; }

.badge { display: inline-flex; padding: 4px 9px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; }
.badge.success { background: var(--success); border-color: oklch(.83 .07 165); color: oklch(.3 .07 165); }
.badge.error { background: oklch(.94 .045 330); border-color: oklch(.86 .06 330); color: oklch(.34 .13 330); }
.badge.warning { background: var(--warning); border-color: oklch(.85 .07 85); color: oklch(.38 .08 85); }

.control-row { display: grid; grid-template-columns: 1fr 1.25fr; gap: 22px; margin-bottom: 22px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.filter-row label { min-width: 190px; }
.inline-form { padding: 18px 20px; display: flex; align-items: end; gap: 12px; }
.inline-form h2 { align-self: center; margin-right: auto; }
.inline-form label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }

input, select, textarea { min-height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); background: white; }
input:focus, select:focus, textarea:focus { border-color: oklch(.7 .1 190); outline: none; }
label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
label input, label select, label textarea { font-size: 14px; color: var(--ink); }
select { min-width: 0; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; }
.alert.success { background: var(--success); color: oklch(.28 .07 165); }
.alert.error { background: oklch(.94 .045 330); color: oklch(.34 .13 330); }
.pagination { padding: 16px 20px; }
.pagination svg { width: 18px; }

.record summary { cursor: pointer; color: var(--action-dark); font-weight: 700; font-size: 12px; }
.record form { display: grid; gap: 10px; padding: 12px 0; max-width: 420px; }
.record label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.wide-form { flex-direction: column; align-items: stretch; }
.wide-form label { align-self: stretch; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions details > form { display: grid; gap: 8px; padding: 10px 0; min-width: 260px; }

.pssuq-grid { display: grid; gap: 14px; width: 100%; }
.pssuq-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.pssuq-label { color: var(--ink); font-weight: 700; font-size: 13px; }
.scale { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.scale label { display: grid; place-items: center; gap: 2px; color: var(--muted); font-size: 11px; cursor: pointer; }
.scale input { width: 18px; min-height: auto; accent-color: var(--action); }
.scale span { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; }
.scale input:checked + span { background: var(--action); border-color: var(--action); color: white; font-weight: 700; }

/* ── Login ───────────────────────────────────────── */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: oklch(.18 .035 255); }
.login-shell { width: min(100%, 860px); min-height: 560px; display: grid; grid-template-columns: 1fr .92fr; background: white; border-radius: 14px; overflow: hidden; box-shadow: 0 32px 100px oklch(.05 0 0/.35); }
.login-context { padding: 54px 48px; background: var(--structure); color: white; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.login-context:after { content: ""; position: absolute; width: 320px; height: 320px; border: 80px solid oklch(.48 .105 190/.13); border-radius: 50%; right: -170px; bottom: -170px; }
.login-context h1 { max-width: 14ch; font-size: 36px; line-height: 1.08; letter-spacing: -.04em; text-wrap: balance; margin: 30px 0 18px; }
.login-context p { max-width: 46ch; color: oklch(.82 .025 250); line-height: 1.65; }
.login-form { padding: 54px 46px; display: flex; flex-direction: column; justify-content: center; }
.login-heading > span { color: var(--action-dark); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.login-heading h2 { font-size: 27px; margin: 8px 0; }
.login-heading p, .login-note { color: var(--muted); }
.login-form form { display: grid; gap: 17px; margin: 28px 0 20px; }
.login-form label:not(.check) { display: grid; gap: 7px; font-weight: 700; }
.login-form input { width: 100%; min-height: 44px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: 16px; min-height: auto; }
.login-note { font-size: 12px; line-height: 1.5; }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 62px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--action-dark, #2f5aa8);
  font-weight: 700; font-size: 13px; cursor: pointer; padding: 8px 10px;
  border-radius: 6px; min-height: auto;
}
.pw-toggle:hover { background: rgba(47,90,168,.1); text-decoration: underline; }
.login-help { font-size: 12px; color: var(--muted); margin-top: -10px; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { position: static; width: auto; padding: 14px 18px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; }
  .main { margin-left: 0; }
  .brand { padding: 0; }
  .nav { flex-direction: row; overflow: auto; padding: 0 14px; }
  .nav-group { min-width: max-content; }
  .nav-children { display: flex; flex-direction: row; gap: 4px; overflow: visible; max-height: none !important; }
  .nav-label { display: none; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; grid-auto-flow: column; align-items: center; }
  .user-meta { display: none; }
  .sidebar-toggle { display: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .metrics > div:nth-child(4) { border-top: 1px solid var(--line); }
  .split, .control-row { grid-template-columns: 1fr; }
  .login-shell { grid-template-columns: 1fr; }
  .login-context { display: none; }
}
@media (max-width: 640px) {
  .sidebar { grid-template-columns: 1fr; }
  .nav { padding: 12px 0 0; }
  .sidebar-foot { display: grid; grid-auto-flow: column; justify-content: space-between; align-items: center; padding-top: 12px; }
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .period { display: none; }
  .content { padding: 16px; }
  .metrics { grid-template-columns: 1fr; }
  .metrics > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .inline-form { align-items: stretch; flex-direction: column; }
  .login-page { padding: 0; }
  .login-shell { min-height: 100vh; border-radius: 0; }
  .login-form { padding: 36px 24px; }
  .control-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
