:root {
  --bg: #f7f8fa; --surface: #ffffff; --surface-2: #f0f2f5; --border: #d8dce3; --text: #1b2230; --muted: #5a6577;
  --accent: #1f5fd1; --accent-text: #ffffff; --accent-soft: #e4edfc;
  --ok: #17693a; --ok-bg: #dff3e6; --warn: #8a5300; --warn-bg: #fdebc8; --bad: #a3202e; --bad-bg: #fbe1e4; --info: #1f5fd1; --info-bg: #e4edfc;
  --focus: #0b3fa8; --radius: 8px; --radius-sm: 5px; --gap: 16px; --shadow: 0 1px 2px rgba(20,30,50,.08), 0 2px 8px rgba(20,30,50,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --side: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131b; --surface: #171c27; --surface-2: #1e2430; --border: #2c3444; --text: #e6e9ef; --muted: #a2acbd;
    --accent: #6fa0ff; --accent-text: #0b1220; --accent-soft: #1b2a47;
    --ok: #6fd69a; --ok-bg: #12301f; --warn: #f0b95c; --warn-bg: #3a2a0c; --bad: #ff8b97; --bad-bg: #3d1820; --info: #6fa0ff; --info-bg: #1b2a47;
    --focus: #9dc0ff; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f131b; --surface: #171c27; --surface-2: #1e2430; --border: #2c3444; --text: #e6e9ef; --muted: #a2acbd;
  --accent: #6fa0ff; --accent-text: #0b1220; --accent-soft: #1b2a47;
  --ok: #6fd69a; --ok-bg: #12301f; --warn: #f0b95c; --warn-bg: #3a2a0c; --bad: #ff8b97; --bad-bg: #3d1820; --info: #6fa0ff; --info-bg: #1b2a47;
  --focus: #9dc0ff; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .25rem; }
h2 { font-size: 1.125rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
code, pre, .mono { font-family: var(--mono); font-size: .875em; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-text); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* shell */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: .01em; color: var(--text); text-decoration: none; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.top .grow { flex: 1; }
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: calc(100vh - 53px); }
.shell.nosidebar { grid-template-columns: 1fr; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 8px; display: flex; flex-direction: column; gap: 14px; }
.side h2 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 10px 4px; }
.side a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
.side a:hover { background: var(--surface-2); }
.side a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .spacer { flex: 1; }
.main { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }
.narrow { max-width: 460px; margin: 40px auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.foot { padding: 16px; color: var(--muted); font-size: .8rem; text-align: center; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: var(--gap); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: var(--gap); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* forms */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=url], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; min-height: 40px; }
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: .9em; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; vertical-align: -3px; margin-right: 6px; accent-color: var(--accent); }
.check { display: flex; align-items: center; font-weight: 400; margin: 6px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
.inline { display: inline; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 180px; margin-bottom: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 0 0 14px; padding: 10px 12px; }
legend { font-weight: 600; padding: 0 6px; }

/* messages */
.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; display: flex; gap: 8px; align-items: flex-start; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.flash.info { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; display: inline-block; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.group td { background: var(--surface-2); font-weight: 600; }
meter { width: 84px; height: 10px; vertical-align: middle; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h2 { color: var(--text); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a[aria-current="page"] { color: var(--accent); border-color: var(--accent); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 18px 18px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline li.k-guardian::before, .timeline li.k-gate::before { border-color: var(--warn); }
.timeline li.k-execution::before, .timeline li.k-rollback::before { border-color: var(--bad); }
.timeline li.k-verification::before { border-color: var(--ok); }
.timeline .meta { color: var(--muted); font-size: .8rem; }
.timeline .quoted { border-left: 3px solid var(--border); padding-left: 10px; color: var(--muted); }

/* dialog */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: min(560px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10,14,22,.55); }
.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox pre { flex: 1; margin: 0; }

/* chart */
.chart { width: 100%; height: 160px; display: block; }
.chart-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }

/* hero */
.hero { text-align: center; padding: 64px 16px 40px; }
.hero h1 { font-size: 2.2rem; }
.hero p { color: var(--muted); max-width: 640px; margin: 0 auto 20px; font-size: 1.05rem; }
.sso-row { display: grid; gap: 8px; margin: 12px 0; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 14px 0; font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

@media (max-width: 900px) {
  .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .side h2 { display: none; }
  .side .spacer { display: none; }
}
@media (max-width: 640px) {
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; }
  .hero h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

[hidden] { display: none !important; }
