:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --ink: #1c1f26;
    --ink-soft: #5b616e;
    --line: #e4e6eb;
    --brand: #2f5bea;
    --brand-ink: #fff;
    --ok: #1a8f4c;
    --warn: #b26a00;
    --bad: #c0392b;
    --sidebar: #171a21;
    --sidebar-ink: #c9ccd3;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
code { background: #eef0f4; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }

/* ---- Shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 236px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
    display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.brand-mark.lg { width: 52px; height: 52px; font-size: 18px; border-radius: 14px; margin: 0 auto 8px; }
.brand-name { font-weight: 600; color: #fff; }
.brand-sub { font-size: 11px; opacity: .6; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
    color: var(--sidebar-ink); font-size: 13.5px;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--brand); color: #fff; }
.ni-icon { width: 16px; text-align: center; opacity: .8; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.who-name { color: #fff; font-weight: 600; font-size: 13px; }
.who-role { font-size: 11px; opacity: .6; margin-bottom: 8px; }

.content { flex: 1; padding: 28px 34px; max-width: 1180px; }

/* ---- Page head ---- */
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-actions { display: flex; gap: 8px; }

/* ---- Cards ---- */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 18px; }
.form-card { max-width: 720px; }

/* ---- KPIs ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--ink-soft); }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi-value.ok { color: var(--ok); }
.kpi-value.warn { color: var(--warn); }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-soft); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }

/* ---- Forms ---- */
label { display: block; margin-bottom: 12px; }
label > span { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
    font: inherit; background: #fff; color: var(--ink);
}
input[type=checkbox] { width: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.inline-form select, .inline-form input { width: auto; }
.inline { display: inline; }
.filter-row { margin-bottom: 12px; }
.filter-row select { width: auto; }
.upload-form { border: 1px dashed var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; background: #fafbfc; }
fieldset.modules { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
fieldset.modules legend { font-size: 12px; color: var(--ink-soft); padding: 0 6px; }
.chk { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.module-list { display: flex; flex-direction: column; gap: 4px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #274fd0; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn.danger, .btn-ghost.danger { color: var(--bad); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
button:disabled { opacity: .5; cursor: default; }

/* ---- Misc ---- */
.muted { color: var(--ink-soft); }
.note { background: #fbfbe8; border: 1px solid #ecebc0; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--ink-soft); font-size: 12.5px; }
.kv dd { margin: 0; }
.license-key {
    font: 700 20px/1.3 "Consolas", "Cascadia Mono", monospace; letter-spacing: 1px;
    background: #eef2ff; border: 1px solid #d6def8; border-radius: 10px; padding: 14px; text-align: center; margin-bottom: 12px;
}
.pill {
    display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; margin-right: 4px;
}
.pill-ok { background: #e3f5ea; color: var(--ok); }
.pill-warn { background: #fdf0dd; color: var(--warn); }
.pill-bad { background: #fbe5e2; color: var(--bad); }
.pill-mut { background: #eef0f4; color: var(--ink-soft); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
.alert-error { background: #fbe5e2; color: var(--bad); border: 1px solid #f2c4bd; }
.alert-ok { background: #e3f5ea; color: var(--ok); border: 1px solid #bfe6cd; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--sidebar); }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.35); text-align: center; }
.login-card h1 { margin: 4px 0; }
.login-card .stack { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; text-align: left; }
.login-card .stack label { margin-bottom: 8px; }
.login-card .btn { justify-content: center; margin-top: 6px; }

@media (max-width: 900px) {
    .detail-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .sidebar { width: 200px; }
}
