:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8faff;
    --text: #172033;
    --muted: #667085;
    --border: #e4e8f2;
    --primary: #4f46e5;
    --primary-2: #6366f1;
    --primary-soft: #eef0ff;
    --accent: #0ea5e9;
    --ok: #059669;
    --ok-soft: #e7f8f1;
    --warn: #b45309;
    --warn-soft: #fff4e5;
    --bad: #dc2626;
    --bad-soft: #feecec;
    --neutral: #475467;
    --neutral-soft: #eef2f7;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 10px 30px rgba(23, 32, 51, .06);
    --shadow-sm: 0 2px 10px rgba(23, 32, 51, .05);
    --max: 1280px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background:
        radial-gradient(1200px 600px at 85% -10%, rgba(99, 102, 241, .16), transparent 60%),
        radial-gradient(900px 500px at -10% 20%, rgba(14, 165, 233, .10), transparent 55%),
        var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 14.5px;
    line-height: 1.55;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.02em; }
h1 { font-size: 1.65rem; font-weight: 750; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }

.mono { font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .76rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---------------------------------------------------------------- Layout */
.shell { max-width: var(--max); margin: 0 auto; padding: 18px 22px 56px; }

.topbar {
    position: sticky; top: 12px; z-index: 40;
    display: flex; align-items: center; gap: 18px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(228, 232, 242, .9);
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 26px;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none !important; color: var(--text); }
.brand-mark {
    width: 40px; height: 40px; border-radius: 13px;
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 1.05rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 8px 18px rgba(79, 70, 229, .28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: .98rem; letter-spacing: -.01em; }
.brand-text span { font-size: .72rem; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }

.nav { display: flex; align-items: center; gap: 4px; margin-left: 8px; flex: 1; }
.nav a {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 12px; border-radius: 11px;
    color: var(--muted); font-weight: 600; font-size: .86rem;
    text-decoration: none !important;
    transition: .16s ease;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }

.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.menu-toggle { display: none; }

@media (max-width: 980px) {
    .nav {
        display: none; position: absolute; top: 70px; left: 12px; right: 12px;
        flex-direction: column; align-items: stretch; gap: 4px;
        background: #fff; border: 1px solid var(--border); border-radius: 16px;
        padding: 10px; box-shadow: var(--shadow);
    }
    .nav.open { display: flex; }
    .menu-toggle { display: inline-flex; }
}

/* ---------------------------------------------------------------- Header */
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 18px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head .eyebrow {
    text-transform: uppercase; letter-spacing: .13em; font-size: .68rem;
    font-weight: 700; color: var(--primary); margin-bottom: 6px;
}
.page-head p { color: var(--muted); margin-top: 6px; max-width: 720px; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--border);
}
.card-head .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.card-body { padding: 20px; }
.card-body.tight { padding: 14px 20px; }

.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-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-source { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
@media (max-width: 1100px) {
    .grid-4, .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
    .grid-2, .grid-3, .grid-4, .grid-kpi { grid-template-columns: 1fr; }
    .shell { padding: 12px 14px 40px; }
    h1 { font-size: 1.4rem; }
}

/* ---------------------------------------------------------------- KPI */
.kpi {
    position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
}
.kpi::after {
    content: ""; position: absolute; right: -26px; top: -26px;
    width: 96px; height: 96px; border-radius: 50%;
    background: radial-gradient(circle, rgba(79, 70, 229, .10), transparent 70%);
}
.kpi .kpi-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.kpi .kpi-value { font-size: 2rem; font-weight: 780; letter-spacing: -.04em; margin-top: 6px; line-height: 1; }
.kpi .kpi-note { color: var(--muted); font-size: .78rem; margin-top: 8px; }
.kpi.accent { border-color: rgba(79, 70, 229, .22); background: linear-gradient(180deg, #fff, #f7f7ff); }

/* ---------------------------------------------------------------- Badge */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    font-size: .72rem; font-weight: 700; letter-spacing: .02em;
    border: 1px solid transparent; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: rgba(5, 150, 105, .16); }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(180, 83, 9, .16); }
.badge.bad { color: var(--bad); background: var(--bad-soft); border-color: rgba(220, 38, 38, .16); }
.badge.neutral { color: var(--neutral); background: var(--neutral-soft); border-color: rgba(71, 84, 103, .12); }
.badge.outline { background: transparent; border-color: var(--border); color: var(--muted); }

/* ---------------------------------------------------------------- Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 11px;
    border: 1px solid var(--border); background: #fff; color: var(--text);
    font: inherit; font-weight: 650; font-size: .86rem;
    cursor: pointer; text-decoration: none !important;
    transition: .16s ease; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-color: transparent; color: #fff;
    box-shadow: 0 8px 18px rgba(79, 70, 229, .25);
}
.btn-primary:hover { box-shadow: 0 12px 24px rgba(79, 70, 229, .32); }
.btn-soft { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn-sm { padding: 7px 11px; font-size: .78rem; border-radius: 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.btn .spinner {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
    animation: spin .7s linear infinite; display: none;
}
.btn.loading .spinner { display: inline-block; }
.btn.loading .label { opacity: .8; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .78rem; font-weight: 650; color: var(--muted); }
.input, .select, textarea.input {
    width: 100%; padding: 10px 12px; border-radius: 11px;
    border: 1px solid var(--border); background: #fff; color: var(--text);
    font: inherit; font-size: .88rem; outline: none; transition: .16s;
}
.input:focus, .select:focus, textarea.input:focus {
    border-color: var(--primary-2); box-shadow: 0 0 0 4px rgba(99, 102, 241, .12);
}
textarea.input { resize: vertical; min-height: 240px; line-height: 1.65; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filter-bar .field { min-width: 150px; flex: 1; }
.filter-bar .field.grow { flex: 2; }
.filter-bar .btn { margin-bottom: 1px; }

/* ---------------------------------------------------------------- Table */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.data th {
    text-align: left; padding: 11px 14px;
    background: var(--surface-2); color: var(--muted);
    font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .14s; }
table.data tbody tr:hover { background: #fbfcff; }
table.data .primary { font-weight: 650; }
table.data .sub { color: var(--muted); font-size: .78rem; margin-top: 2px; }

/* ---------------------------------------------------------------- Misc */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

.alert {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border);
    background: var(--surface); font-size: .86rem;
}
.alert.ok { background: var(--ok-soft); border-color: rgba(5, 150, 105, .18); }
.alert.warn { background: var(--warn-soft); border-color: rgba(180, 83, 9, .18); }
.alert.bad { background: var(--bad-soft); border-color: rgba(220, 38, 38, .18); }
.alert .ico { font-size: 1.05rem; line-height: 1.2; }
.alert strong { display: block; margin-bottom: 2px; }

.empty {
    padding: 46px 24px; text-align: center; color: var(--muted);
}
.empty .empty-ico {
    width: 62px; height: 62px; margin: 0 auto 14px; border-radius: 18px;
    display: grid; place-items: center; font-size: 1.6rem;
    background: var(--primary-soft); color: var(--primary);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }

.source-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.source-card .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.source-card .name { font-weight: 700; font-size: .9rem; }
.source-card .desc { color: var(--muted); font-size: .78rem; min-height: 2.4em; }
.source-card .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; border-top: 1px dashed var(--border); padding-top: 9px; }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-list .bar-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.bar-list .track { grid-column: 1 / -1; height: 7px; border-radius: 99px; background: var(--neutral-soft); overflow: hidden; }
.bar-list .fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.bar-list .bar-item.warn .fill { background: linear-gradient(90deg, #f59e0b, #f97316); }
.bar-list .bar-item.bad .fill { background: linear-gradient(90deg, #ef4444, #dc2626); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline .item { display: grid; grid-template-columns: 26px 1fr; gap: 12px; padding: 10px 0; }
.timeline .item:not(:last-child) { border-bottom: 1px dashed var(--border); }
.timeline .marker { width: 26px; height: 26px; border-radius: 9px; display: grid; place-items: center; background: var(--neutral-soft); font-size: .8rem; }
.timeline .item.bad .marker { background: var(--bad-soft); }
.timeline .item.warn .marker { background: var(--warn-soft); }
.timeline .item.ok .marker { background: var(--ok-soft); }
.timeline .msg { font-size: .86rem; }
.timeline .time { color: var(--muted); font-size: .72rem; margin-top: 2px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 4px; }
.pagination .page {
    min-width: 34px; height: 34px; padding: 0 10px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); color: var(--muted); font-size: .82rem; font-weight: 600;
    text-decoration: none !important;
}
.pagination .page.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .page:hover:not(.active) { background: var(--surface-2); }

.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 8px 18px; font-size: .88rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }

.evidence { display: flex; flex-direction: column; gap: 0; }
.evidence .ev { display: grid; grid-template-columns: 180px 1fr; gap: 14px; padding: 11px 0; border-bottom: 1px dashed var(--border); font-size: .86rem; }
.evidence .ev:last-child { border-bottom: 0; }
.evidence .ev .k { color: var(--muted); font-weight: 650; }
.evidence .ev .v { word-break: break-word; }
@media (max-width: 720px) {
    .evidence .ev { grid-template-columns: 1fr; gap: 2px; }
}

.copy-box { position: relative; }
.copy-box textarea { font-family: "JetBrains Mono", Consolas, monospace; font-size: .82rem; }
.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 11px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: .76rem; font-weight: 600; color: var(--muted);
    text-decoration: none !important;
}
.chip:hover { border-color: var(--primary-2); color: var(--primary); }
.chip .count { background: var(--neutral-soft); color: var(--neutral); padding: 1px 7px; border-radius: 999px; font-size: .7rem; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
    width: 100%; max-width: 400px; padding: 30px;
    background: rgba(255,255,255,.9); backdrop-filter: blur(14px);
    border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; margin-bottom: 22px; }
.login-card .brand-text { align-items: flex-start; }

.footer { margin-top: 34px; color: var(--muted); font-size: .76rem; text-align: center; }
.footer .sep { margin: 0 7px; opacity: .5; }

.toast {
    position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
    max-width: min(560px, calc(100vw - 32px));
    padding: 12px 18px; border-radius: 12px;
    background: #172033; color: #fff; font-size: .84rem; font-weight: 600;
    box-shadow: 0 16px 40px rgba(23, 32, 51, .28);
    opacity: 0; pointer-events: none; transition: .22s ease; z-index: 90;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #b91c1c; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.span-2 { grid-column: span 2; }
@media (max-width: 720px) { .span-2 { grid-column: span 1; } }
