:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --surface-3: #edf2f8;
    --text: #111827;
    --muted: #647084;
    --line: #d9e1ec;
    --line-strong: #c4cfdd;
    --primary: #2155d9;
    --primary-ink: #ffffff;
    --accent: #0f8b8d;
    --success: #12805c;
    --danger: #c24136;
    --warning: #b7791f;
    --sidebar: #101723;
    --sidebar-2: #151f2d;
    --sidebar-line: rgba(255, 255, 255, .08);
    --shadow: 0 16px 36px rgba(15, 23, 42, .08);
    --shadow-soft: 0 1px 2px rgba(15, 23, 42, .06);
    --radius: 8px;
}

html[data-theme="dark"] {
    --bg: #0d1118;
    --surface: #151b25;
    --surface-2: #111822;
    --surface-3: #1c2633;
    --text: #e8edf6;
    --muted: #9aa7b8;
    --line: #2a3648;
    --line-strong: #3a4960;
    --primary: #84a7ff;
    --primary-ink: #0c1321;
    --accent: #4fb7b9;
    --success: #4fbf8f;
    --danger: #f0786f;
    --warning: #f0b85b;
    --sidebar: #080d14;
    --sidebar-2: #101722;
    --shadow: 0 16px 42px rgba(0, 0, 0, .32);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    text-rendering: optimizeLegibility;
}

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

a:hover { color: var(--accent); }

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 304px;
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    background: var(--sidebar);
    color: #eef4ff;
    border-right: 1px solid var(--sidebar-line);
}

.brand {
    min-height: 82px;
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 20px;
    color: #fff;
    border-bottom: 1px solid var(--sidebar-line);
}

.brand:hover { color: #fff; }

.brand strong {
    display: block;
    font-size: 17px;
    line-height: 1.1;
}

.brand small {
    display: block;
    margin-top: 4px;
    max-width: 190px;
    color: #aab6c8;
    font-size: 11px;
    line-height: 1.25;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 8px;
    background: #f4c542;
    color: #101723;
    font-weight: 900;
    letter-spacing: 0;
}

.sidebar-context {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px;
    padding: 12px;
    border: 1px solid var(--sidebar-line);
    border-radius: var(--radius);
    background: var(--sidebar-2);
}

.sidebar-context strong {
    display: block;
    font-size: 13px;
}

.sidebar-context small {
    color: #94a3b8;
    font-size: 11px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #2dd4bf;
    box-shadow: 0 0 0 4px rgba(45, 212, 191, .14);
}

.sidebar-nav {
    padding: 4px 12px 22px;
}

.nav-section {
    margin-top: 12px;
}

.nav-group {
    margin: 16px 8px 7px;
    color: #7f8da3;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    margin-bottom: 2px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #d7e0ee;
    font-weight: 650;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, .045);
    color: #fff;
}

.sidebar .nav-link.active {
    background: #eef4ff;
    color: #122033;
    border-color: rgba(255, 255, 255, .25);
}

.nav-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #536178;
    flex: 0 0 7px;
}

.nav-link.active .nav-dot { background: var(--accent); }

.main-area {
    flex: 1;
    min-width: 0;
    margin-left: 304px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 68px;
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.icon-button.nav-toggle { display: none; }

.global-search {
    flex: 1;
    max-width: 760px;
    min-width: 180px;
    display: flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.global-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 10px 12px;
    outline: none;
}

.global-search input::placeholder { color: var(--muted); }

.global-search button {
    width: 78px;
    border: 0;
    border-left: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.icon-button {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-soft);
}

.btn {
    border-radius: 7px;
    font-weight: 700;
}

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-color: var(--primary-ink);
    --bs-btn-hover-bg: var(--accent);
    --bs-btn-hover-border-color: var(--accent);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: color-mix(in srgb, var(--primary) 70%, var(--line));
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-hover-color: var(--primary-ink);
}

.content {
    width: min(100%, 1680px);
    padding: 28px;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 22px;
}

.page-heading h1 {
    margin: 5px 0 0;
    font-size: 28px;
    line-height: 1.15;
    font-weight: 800;
    letter-spacing: 0;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.user-chip {
    min-width: 230px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.avatar {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border-radius: 7px;
    background: var(--surface-3);
    color: var(--primary);
    font-weight: 900;
}

.user-chip span:not(.avatar) {
    display: block;
    font-weight: 760;
}

.user-chip small {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.alert {
    border-radius: var(--radius);
    border-width: 1px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.panel-header {
    min-height: 64px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-header h2,
.panel-header h3 {
    color: var(--text);
}

.panel-body {
    padding: 17px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.metric-card {
    min-height: 116px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.metric-card small {
    color: var(--muted);
    font-weight: 750;
}

.metric-card strong {
    display: block;
    margin-top: 9px;
    color: var(--text);
    font-size: 26px;
    line-height: 1.05;
}

.metric-card span {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.chart-box { min-height: 306px; }

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--line);
    margin-bottom: 0;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
    color: var(--text);
}

.table-hover > tbody > tr:hover > * {
    background: color-mix(in srgb, var(--surface-3) 70%, transparent);
}

.table-responsive {
    overflow: auto;
}

.badge {
    border-radius: 999px;
    font-weight: 750;
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 10px;
}

.form-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 780;
}

.form-control,
.form-select {
    min-height: 40px;
    border-color: var(--line);
    border-radius: 7px;
    background-color: var(--surface);
    color: var(--text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--primary) 18%, transparent);
}

.form-text,
.text-muted {
    color: var(--muted) !important;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid.dense { gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }

.empty-state {
    padding: 30px;
    text-align: center;
    color: var(--muted);
}

.json-block {
    max-height: 420px;
    overflow: auto;
    padding: 14px;
    border-radius: var(--radius);
    background: #0b1220;
    color: #dce8ff;
    font-size: 12px;
}

.dashboard-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 430px;
    gap: 18px;
    align-items: stretch;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.dashboard-hero-copy {
    min-height: 210px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.dashboard-hero h2 {
    max-width: 760px;
    margin: 0;
    font-size: 30px;
    line-height: 1.08;
    font-weight: 880;
    letter-spacing: 0;
}

.dashboard-hero p {
    max-width: 760px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 15px;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.dashboard-health {
    display: grid;
    gap: 12px;
}

.health-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.health-list div {
    min-height: 78px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.health-list span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 820;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.health-list strong {
    display: block;
    margin-top: 7px;
    color: var(--text);
    word-break: break-word;
}

.section-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 2px 0;
}

.ops-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: stretch;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.eyebrow {
    display: inline-flex;
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.ops-hero h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 850;
    letter-spacing: 0;
}

.ops-hero p {
    margin: 9px 0 0;
    max-width: 760px;
    color: var(--muted);
}

.ops-status {
    min-height: 118px;
    display: grid;
    align-content: center;
    gap: 6px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.ops-status > span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning);
}

.ops-status.is-online > span { background: var(--success); }
.ops-status strong { font-size: 15px; }
.ops-status small { color: var(--muted); word-break: break-word; }

.manual-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 16px;
    align-items: start;
}

.upload-zone {
    position: relative;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 16px;
}

.upload-zone input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-zone label {
    display: grid;
    gap: 5px;
    margin: 0;
    pointer-events: none;
}

.upload-zone strong {
    color: var(--text);
    font-size: 15px;
}

.upload-zone span,
.upload-zone small {
    color: var(--muted);
}

.contract-list {
    display: grid;
    gap: 10px;
}

.contract-list div {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.contract-list div:last-child { border-bottom: 0; }
.contract-list span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 800;
}
.contract-list strong { display: block; margin-top: 3px; }

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #101723;
}

.auth-card {
    width: min(940px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 28px 90px rgba(0, 0, 0, .34);
}

.auth-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 52px;
    background: #121d2c;
    color: #fff;
}

.auth-copy h1 {
    margin: 18px 0 8px;
    font-size: 34px;
}

.auth-copy p {
    max-width: 360px;
    color: #aeb9cc;
}

.login-form {
    padding: 48px;
    background: #fff;
}

.login-form h2 {
    margin-bottom: 24px;
    font-size: 22px;
}

.visual-canvas {
    position: relative;
    min-height: 440px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.bbox {
    position: absolute;
    border: 2px solid var(--label-color, #f4c542);
    background: color-mix(in srgb, var(--label-color, #f4c542) 12%, transparent);
}

.bbox span {
    position: absolute;
    top: -24px;
    left: -2px;
    padding: 3px 6px;
    border-radius: 4px;
    background: var(--label-color, #f4c542);
    color: #101723;
    font-size: 11px;
    white-space: nowrap;
}

.error-panel {
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

body.nav-open .sidebar {
    transform: translateX(0);
}

@media (max-width: 1280px) {
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .manual-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
    .sidebar {
        width: 292px;
        transform: translateX(-100%);
        transition: transform .18s ease;
        z-index: 50;
        box-shadow: var(--shadow);
    }

    .main-area {
        margin-left: 0;
    }

    .icon-button.nav-toggle { display: inline-grid; }

    .content { padding: 22px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-grid { grid-template-columns: 1fr; }
    .dashboard-hero { grid-template-columns: 1fr; }
    .ops-hero { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .topbar {
        align-items: stretch;
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .global-search {
        order: 3;
        flex-basis: 100%;
        max-width: none;
    }

    .topbar-actions {
        margin-left: auto;
    }

    .page-heading {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-hero {
        padding: 18px;
    }

    .dashboard-hero h2 {
        font-size: 24px;
    }

    .health-list {
        grid-template-columns: 1fr;
    }

    .section-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-chip {
        min-width: 0;
        width: 100%;
    }

    .filters,
    .form-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .form-grid .span-2 { grid-column: auto; }

    .auth-card {
        grid-template-columns: 1fr;
    }

    .auth-copy,
    .login-form {
        padding: 34px;
    }
}
