:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --line: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-soft: #dbeafe;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --info: #0891b2;
    --shadow: 0 18px 40px rgba(15, 23, 42, .08);
    --radius: 18px;
    --sidebar: #0f172a;
    --sidebar-soft: #172033;
}

body.dark {
    --bg: #0b1120;
    --surface: #111827;
    --surface-soft: #1f2937;
    --line: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary-soft: rgba(37, 99, 235, .15);
    --shadow: 0 18px 40px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 292px;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-soft));
    color: #e5e7eb;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #60a5fa, #2563eb);
    font-weight: 900;
    font-size: 22px;
    color: white;
    box-shadow: 0 12px 28px rgba(37, 99, 235, .35);
}

.brand-title {
    font-size: 17px;
    font-weight: 800;
}

.brand-subtitle {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 2px;
}

.nav {
    display: grid;
    gap: 7px;
}

.nav-item {
    border: 0;
    background: transparent;
    color: #cbd5e1;
    text-align: left;
    border-radius: 14px;
    padding: 12px 13px;
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
    transition: .18s ease;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .08);
    color: white;
}

.nav-item.active {
    background: rgba(37, 99, 235, .95);
    color: white;
    box-shadow: 0 14px 24px rgba(37, 99, 235, .25);
}

.nav-icon {
    width: 22px;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 16px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 11px;
}

.status-dot {
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, .15);
}

.footer-title {
    font-size: 13px;
    font-weight: 800;
}

.footer-subtitle {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 2px;
}

.main {
    flex: 1;
    padding: 26px;
    overflow: auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.topbar h1 {
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.03em;
}

.topbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    gap: 10px;
}

.btn {
    border: 0;
    border-radius: 13px;
    padding: 11px 15px;
    cursor: pointer;
    font-weight: 700;
    transition: .18s ease;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 12px 22px rgba(37, 99, 235, .18);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-light {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
}

.btn-light:hover {
    background: var(--surface-soft);
}

.toolbar {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 15px;
    display: flex;
    gap: 14px;
    align-items: end;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}

.filter-group {
    display: grid;
    gap: 6px;
    min-width: 170px;
}

.filter-grow {
    flex: 1;
}

.filter-group label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 800;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--text);
    border-radius: 12px;
    padding: 11px 12px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.page {
    display: none;
}

.page-active {
    display: block;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.kpi-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.kpi-value {
    font-size: 34px;
    font-weight: 900;
    letter-spacing: -0.05em;
    margin-top: 8px;
}

.kpi-value.small {
    font-size: 20px;
    letter-spacing: -0.02em;
}

.kpi-value.warning {
    color: var(--warning);
}

.kpi-value.info {
    color: var(--info);
}

.kpi-note {
    color: var(--muted);
    font-size: 12px;
    margin-top: 6px;
}

.content-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.card-header h2 {
    margin: 0;
    font-size: 19px;
}

.card-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.table-wrap {
    overflow: auto;
    max-height: 420px;
}

.table-wrap.tall {
    max-height: 650px;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    min-width: 960px;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-soft);
    color: var(--muted);
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
    white-space: nowrap;
}

.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.data-table tr:hover td {
    background: var(--surface-soft);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 800;
}

.badge-normal {
    color: #166534;
    background: #dcfce7;
}

.badge-warning {
    color: #92400e;
    background: #fef3c7;
}

.badge-test {
    color: #075985;
    background: #e0f2fe;
}

.badge-danger {
    color: #991b1b;
    background: #fee2e2;
}

.segmented {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    padding: 4px;
    border-radius: 14px;
    display: flex;
    gap: 4px;
}

.seg {
    border: 0;
    border-radius: 10px;
    padding: 8px 11px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 800;
}

.seg.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 8px 18px rgba(15, 23, 42, .08);
}

.empty-state {
    min-height: 360px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 40px;
}

.empty-icon {
    width: 62px;
    height: 62px;
    border-radius: 22px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 26px;
    margin: 0 auto 14px;
}

.empty-state h3 {
    margin: 0;
}

.empty-state p {
    margin: 8px 0 0;
    color: var(--muted);
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    background: #0f172a;
    color: white;
    padding: 13px 16px;
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
    transform: translateY(120%);
    opacity: 0;
    transition: .2s ease;
    z-index: 50;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 1100px) {
    .sidebar {
        width: 88px;
        padding: 18px 12px;
    }

    .brand div:not(.brand-mark),
    .nav-item:not(.active) {
        font-size: 0;
    }

    .nav-item {
        justify-content: center;
    }

    .sidebar-footer {
        display: none;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: auto;
        height: auto;
        position: relative;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .main {
        padding: 16px;
    }

    .topbar,
    .toolbar,
    .card-header {
        display: grid;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }
}