:root {
  color-scheme: light;
  --bg: #f4f5fa; --surface: #fff; --surface-2: #f8f9fc; --border: #e3e5ef; --text: #111427; --muted: #4a5068;
  --brand: #4c4ad6; --brand-strong: #3f3bbd; --brand-soft: #eef0ff; --focus: #1d4ed8;
  --good: #116b35; --good-bg: #e3f5e9; --warning: #8a4b00; --warning-bg: #fff2d6;
  --critical: #b3261e; --critical-bg: #fde8e7; --neutral: #4a5068; --neutral-bg: #eceef5;
  --radius: 14px; --shadow: 0 1px 2px rgba(17, 20, 39, .06), 0 1px 3px rgba(17, 20, 39, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1020; --surface: #171a2e; --surface-2: #1d2038; --border: #2b2f4d; --text: #eef0fb; --muted: #b6bad4;
    --brand: #9ea7fb; --brand-strong: #c2c9ff; --brand-soft: #262a5a; --focus: #93b4ff;
    --good: #7fdc9f; --good-bg: rgba(127, 220, 159, .12); --warning: #ffc66b; --warning-bg: rgba(255, 198, 107, .12);
    --critical: #ff9a93; --critical-bg: rgba(255, 154, 147, .12); --neutral: #b6bad4; --neutral-bg: rgba(182, 186, 212, .12);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -60px; padding: 10px 14px; background: var(--brand); color: #fff; border-radius: 8px; z-index: 10; }
.skip-link:focus { top: 12px; }
.muted { color: var(--muted); }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .9em; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, #7c83f2, #4c4ad6 55%, #0f766e); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #15173a; } }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--critical); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; margin-top: 8px; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--brand); background: var(--brand-soft); }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #c9ccdb; background: var(--surface);
  color: var(--text); font: inherit; }
.form-error { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--critical-bg); color: var(--critical); font-weight: 600; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 0% 0%, rgba(95, 98, 230, .25), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 32px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(17, 20, 39, .08); }
.login-card h1 { margin: 18px 0 2px; font-size: 1.5rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.page { max-width: 1400px; margin: 0 auto; padding: 24px; outline: none; }
.page-title { margin: 0 0 14px; font-size: 1.5rem; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-value { font-size: 1.6rem; font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { padding: 10px 16px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { max-width: 380px; }
.toolbar select { max-width: 220px; }
.spacer { flex: 1; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--surface-2); color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
.sub { display: block; color: var(--muted); font-size: .8rem; }
.sub-cell { color: var(--muted); font-size: .82rem; max-width: 380px; }
.key { white-space: nowrap; font-weight: 600; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn + .btn { margin-left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip.good { color: var(--good); background: var(--good-bg); }
.chip.warning { color: var(--warning); background: var(--warning-bg); }
.chip.critical { color: var(--critical); background: var(--critical-bg); }
.chip.neutral { color: var(--neutral); background: var(--neutral-bg); }

dialog { width: min(620px, 92vw); border: 1px solid var(--border); border-radius: 18px; padding: 24px; background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(10, 12, 30, .45); }
dialog h2 { margin: 0 0 6px; font-size: 1.25rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.key-big { margin: 18px 0; padding: 16px; border-radius: 12px; background: var(--brand-soft); text-align: center;
  font: 700 1.35rem/1.3 Consolas, "Cascadia Mono", monospace; letter-spacing: .06em; user-select: all; word-break: break-all; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: #116b35; color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.error { background: #b3261e; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border); font-weight: 500; }
.banner.warning { background: var(--warning-bg); color: var(--text); }

.warn-text { color: var(--warning); font-weight: 600; }
