:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --text: #17212b;
  --muted: #5f6f7c;
  --primary: #0f766e;
  --primary-soft: #e6f4f2;
  --primary-ink: #ffffff;
  --sidebar: #0f2a33;
  --sidebar-text: #c9d6dc;
  --sidebar-active: #1d4450;
  --ok: #15803d;      --ok-soft: #e8f6ec;
  --warn: #b45309;    --warn-soft: #fdf3e2;
  --bad: #b91c1c;     --bad-soft: #fdecec;
  --info: #1d4ed8;    --info-soft: #e9effd;
  --neutral-soft: #eef1f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 700; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; font-size: 13px; }
.brand small { display: block; color: var(--sidebar-text); font-weight: 400; font-size: 11px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d949e; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); }
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.nav svg { width: 16px; height: 16px; flex: none; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar form.search { flex: 1; max-width: 460px; }
.topbar input[type=search] { width: 100%; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar:hover { text-decoration: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.btn.menu-btn { display: none; }
.content { padding: 22px 24px 40px; max-width: 1360px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.demo-banner { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #f3d9ad; padding: 6px 24px; font-size: 12.5px; }

/* ---------- components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .kpis > * { margin-top: 0; }
.grid > *, .stack > * { min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 12px; display: block; }
.kpi strong { font-size: 22px; display: block; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi small { font-size: 11.5px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.kpi.warn { border-top: 3px solid var(--warn); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); }
td.num, th.num { text-align: right; }
tbody td:first-child { white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }

input, select, textarea { font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label { display: block; font-weight: 600; font-size: 12.5px; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 5px; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.progress { height: 7px; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; min-width: 90px; }
.progress > i { display: block; height: 100%; background: var(--primary); }
.progress.warn > i { background: var(--warn); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: -6px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 1px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline li.done::after { background: var(--primary); }
.timeline li.pending::after { border-color: var(--border); }
.timeline time { display: block; color: var(--muted); font-size: 12px; }

.alert-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.alert-item:last-child { border-bottom: 0; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.alert-dot.bad { background: var(--bad); } .alert-dot.warn { background: var(--warn); } .alert-dot.info { background: var(--info); }
.alert-item strong { display: block; }
.alert-item .num { margin-left: auto; font-weight: 700; }

.tree details { border-bottom: 1px solid var(--border); }
.tree summary { list-style: none; display: grid; grid-template-columns: 1fr repeat(4, 110px); gap: 8px; padding: 9px 10px; cursor: pointer; align-items: center; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary .name::before { content: "▸"; display: inline-block; width: 16px; color: var(--muted); transition: transform .15s; }
.tree details[open] > summary .name::before { transform: rotate(90deg); }
.tree details details summary { padding-left: 34px; background: var(--surface-2); }
.tree details details details summary { padding-left: 58px; }
.tree .row-head { display: grid; grid-template-columns: 1fr repeat(4, 110px); gap: 8px; padding: 9px 10px; font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.tree .leaf { display: grid; grid-template-columns: 1fr repeat(4, 110px); gap: 8px; padding: 7px 10px 7px 82px; border-top: 1px solid var(--border); color: var(--muted); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; background: var(--surface-2); color: var(--muted); }
.chart { width: 100%; height: 180px; }
.chart rect { fill: var(--primary); opacity: .85; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart line { stroke: var(--border); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.steps { display: flex; gap: 0; margin: 4px 0 18px; }
.steps span { flex: 1; text-align: center; padding: 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 3px solid var(--border); }
.steps span.done { color: var(--primary); border-color: var(--primary); }
.steps span.current { color: var(--text); border-color: var(--warn); }

/* ---------- login */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0f2a33, #0f766e); padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { margin: 10px 0 4px; }
.auth form { display: grid; gap: 14px; margin-top: 20px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  body.nav-open .sidebar { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar .user span { display: none; }
  .content { padding: 16px 16px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 110px 1fr; }
  .tree summary, .tree .row-head, .tree .leaf { grid-template-columns: 1fr 80px 80px; }
  .tree .hide-sm { display: none; }
  .tree .leaf { padding-left: 40px; }
}

.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; border: 1px solid; }
.notice.bad { background: var(--bad-soft); color: var(--bad); border-color: #f5c6c6; }
.notice.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3c9; }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: #f3d9ad; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 700; user-select: all; background: #fff; border: 1px dashed currentColor; border-radius: 6px; padding: 2px 8px; }
.inline-form { display: inline; }
.narrow { max-width: 520px; }
