:root {
  --blue: #0B4DA2; --blue-d: #083a7c; --blue-l: #e8f0fb;
  --bg: #f3f5f9; --card: #ffffff; --ink: #172033; --muted: #5d6b82; --line: #dfe5ee;
  --ok: #17794a; --ok-bg: #e2f4ea; --warn: #8a5a00; --warn-bg: #fdf0d3;
  --bad: #b3261e; --bad-bg: #fbe4e2; --info: #0b5aa6; --info-bg: #dfeefc; --mute-bg: #eceff4;
  --shadow: 0 1px 2px rgba(16, 28, 54, .06), 0 2px 8px rgba(16, 28, 54, .05);
  --radius: 10px; --nav-w: 232px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --blue: #5b9bf0; --blue-d: #86b6f6; --blue-l: #17263f;
  --bg: #0f141d; --card: #171e2b; --ink: #e6ebf3; --muted: #93a0b5; --line: #2a3446;
  --ok: #55c58b; --ok-bg: #12301f; --warn: #f0b94a; --warn-bg: #3a2c0c;
  --bad: #ff8a80; --bad-bg: #3d1816; --info: #7fb8f5; --info-bg: #14283f; --mute-bg: #232c3b;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 0 0 8px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--blue); color: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid #f4a62a; outline-offset: 2px; border-radius: 4px; }

/* shell */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav { background: var(--blue); color: #fff; padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
:root[data-theme="dark"] .nav { background: #101a2c; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 700; font-size: 16px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--blue); display: grid; place-items: center; font-weight: 800; }
:root[data-theme="dark"] .logo { color: #0b4da2; }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: #dbe7fa; padding: 8px 10px; border-radius: 8px; margin: 1px 0; }
.nav a:hover { background: rgba(255, 255, 255, .12); text-decoration: none; }
.nav a[aria-current="page"] { background: #fff; color: var(--blue-d); font-weight: 600; }
:root[data-theme="dark"] .nav a[aria-current="page"] { background: #24334f; color: #fff; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #9fb7dc; padding: 12px 10px 4px; }
.nav .count { background: #f4a62a; color: #231600; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.topbar .grow { flex: 1; min-width: 160px; position: relative; }
.search input { width: 100%; max-width: 480px; }
.results { position: absolute; top: 40px; left: 0; width: min(480px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 360px; overflow: auto; z-index: 30; }
.results a { display: block; padding: 8px 12px; color: var(--ink); border-bottom: 1px solid var(--line); }
.results a:hover, .results a:focus { background: var(--blue-l); text-decoration: none; }
.results small { color: var(--muted); display: block; }
.who { text-align: right; line-height: 1.2; }
.who small { color: var(--muted); }
main { padding: 20px; max-width: 1500px; width: 100%; }
.pagehead { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead p { margin: 0; color: var(--muted); }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.btn { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; }
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #08121f; }
.btn.primary:hover:not(:disabled) { background: var(--blue-d); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.link { border: none; background: none; color: var(--blue); padding: 0 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* cards and tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: block; color: var(--ink); box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--blue); text-decoration: none; }
.tile b { font-size: 26px; display: block; line-height: 1.1; }
.tile span { color: var(--muted); font-size: 12.5px; }
.tile.alert b { color: var(--bad); }
.tile.watch b { color: var(--warn); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; background: var(--card); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--blue-l); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.cr { color: var(--ok); } .dr { color: var(--bad); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.toolbar input[type=search] { min-width: 220px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; color: var(--muted); }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.err { border: 1px solid var(--bad); background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 12px; }

/* pills */
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.muted { background: var(--mute-bg); color: var(--muted); }

/* detail */
dl.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--blue); border-color: var(--blue); font-weight: 600; text-decoration: none; }
.notice { background: var(--info-bg); color: var(--info); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.bar { height: 8px; background: var(--mute-bg); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--blue); }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); color: var(--ink); width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 20, 40, .5); }
dialog form { padding: 18px; }
dialog h2 { margin-bottom: 8px; }
.field { margin: 10px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 3px; }
.field input:not([type=checkbox]), .field select { width: 100%; }
.field .hint { color: var(--muted); font-size: 12px; }
.field .fe { color: var(--bad); font-size: 12px; min-height: 14px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200; max-width: min(420px, 92vw); }
.toast { background: #172033; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.3); border-left: 5px solid #5fd08e; }
.toast.error { border-color: #ff6b61; }

/* login */
.loginpage { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, var(--blue), #0a2f66); }
.logincard { background: var(--card); border-radius: 14px; padding: 28px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.logincard .field input { width: 100%; }
.navtoggle { display: none; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; left: 0; top: 0; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; }
  .navtoggle { display: inline-block; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  main { padding: 14px; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dd { margin-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* paging, empty states, dialogs */
.btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.empty.small { padding: 10px 12px; font-size: 12px; text-align: left; }
dialog img { border-radius: 8px; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--mute-bg); padding: 1px 5px; border-radius: 4px; }
