* {
    box-sizing: border-box;
}

:root {
    --bg: #0b1020;
    --panel: #131a2e;
    --panel-2: #1a2340;
    --line: #2a355d;
    --text: #e8ecff;
    --muted: #9aa7d1;
    --brand: #4f7cff;
    --brand-2: #6f5cff;
    --ok: #20c997;
    --warn: #f59f00;
    --err: #ff6b6b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", sans-serif;
    background: radial-gradient(circle at top right, #18234a 0%, var(--bg) 35%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: #a9beff;
    text-decoration: none;
}

.layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, #0f1630 0%, #0a1126 100%);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 50;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.3px;
    font-size: 18px;
    margin-bottom: 20px;
}

.brand small {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.nav-link {
    display: block;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    margin-bottom: 8px;
    color: #c9d4ff;
}

.nav-link.active,
.nav-link:hover {
    border-color: #3a4a7d;
    background: #151f3e;
}

.sidebar-footer {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

.main {
    padding: 20px;
    min-width: 0;
}

.mobile-header {
    display: none;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    border: 1px solid var(--line);
    background: #111936;
    color: var(--muted);
}

.badge.ok {
    color: #9bf4dd;
    border-color: #2f8f75;
    background: rgba(32, 201, 151, 0.1);
}

.badge.err {
    color: #ffc4c4;
    border-color: #8c3f55;
    background: rgba(255, 107, 107, 0.1);
}

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

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

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

.card {
    background: linear-gradient(180deg, var(--panel) 0%, #111933 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-top: 0;
}

.chart-card {
    min-height: 240px;
}

.chart-card canvas {
    width: 100% !important;
    height: 180px !important;
    max-height: 180px;
}

.label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.value {
    font-size: 30px;
    margin-top: 8px;
    font-weight: 700;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--panel);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

th,
td {
    border-bottom: 1px solid #243057;
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input,
select,
textarea,
button {
    width: 100%;
    background: #101836;
    color: var(--text);
    border: 1px solid #31406e;
    border-radius: 10px;
    padding: 10px 11px;
    outline: none;
}

textarea {
    resize: vertical;
    min-height: 40px;
}

button {
    cursor: pointer;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-2) 100%);
    border: none;
    font-weight: 600;
}

button.secondary {
    background: #1a2548;
    border: 1px solid #31406e;
}

.inline-form {
    display: inline-block;
}

.inline-form button {
    width: auto;
}

.action-btn {
    width: auto;
    padding: 8px 12px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 19, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 98;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-box {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(560px, calc(100vw - 24px));
    background: linear-gradient(180deg, var(--panel) 0%, #0e1730 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 14px;
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.modal-box.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.modal-head h3 {
    margin: 0;
    font-size: 18px;
}

.alerts {
    margin: 8px 0 14px;
}

.alert {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 14px;
}

.alert.ok {
    background: rgba(32, 201, 151, 0.14);
    border: 1px solid #2f8f75;
    color: #9bf4dd;
}

.alert.err {
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid #8c3f55;
    color: #ffc4c4;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-card {
    width: min(420px, 100%);
}

.mobile-nav {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: block;
        position: fixed;
        left: -280px;
        top: 0;
        width: 260px;
        transition: left 0.25s ease;
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
    }

    body.sidebar-open .sidebar {
        left: 0;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(3, 6, 17, 0.72);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 40;
    }

    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-bottom: 10px;
        position: sticky;
        top: 0;
        z-index: 20;
        background: rgba(11, 16, 32, 0.92);
        backdrop-filter: blur(6px);
        padding: 10px 0;
    }

    .menu-btn {
        width: auto;
        padding: 8px 12px;
    }

    .mobile-nav {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        margin-bottom: 10px;
    }

    .grid-3,
    .grid-4,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-wrap: wrap;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .main {
        padding: 14px;
    }

    .card {
        padding: 12px;
        border-radius: 12px;
    }

    .value {
        font-size: 24px;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    tr {
        border-bottom: 1px solid #243057;
        padding: 8px 0;
    }

    td {
        border: none;
        padding: 7px 8px 7px 45%;
        position: relative;
        min-height: 30px;
    }

    td::before {
        content: attr(data-label);
        position: absolute;
        left: 8px;
        top: 7px;
        width: 40%;
        color: var(--muted);
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        font-weight: 600;
    }

    .inline-form {
        display: block;
        margin-bottom: 6px;
    }

    .inline-form button,
    .inline-form .secondary {
        width: 100%;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    .mobile-header {
        position: static;
    }

    .topbar h1 {
        font-size: 19px;
    }

    .card {
        padding: 10px;
    }
}
