:root {
    --primary: #3bacf0;
    --primary-dark: #0f7fc4;
    --bg-dark: #121212;
    --sidebar: #151a24;
    --surface: #f7f9fb;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #191c1e;
    --muted: #64748b;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background: var(--surface);
    line-height: 1.45;
}

body.no-scroll {
    overflow: hidden;
}

h1, h2, h3, h4, h5 {
    margin: 0;
    font-family: 'Manrope', sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.sidebar-overlay {
    display: none;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1b2331, var(--bg-dark));
    color: #fff;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.08);
}

.brand-block {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 24px 18px;
    position: relative;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #6cc9ff);
}

.brand-block h1 {
    font-size: 21px;
    letter-spacing: -0.02em;
}

.brand-block p {
    margin: 2px 0 0;
    color: #94a3b8;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.sidebar-close {
    margin-left: auto;
    border: none;
    background: rgba(255,255,255,0.08);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #cbd5e1;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.menu-item.active {
    background: rgba(59, 172, 240, 0.18);
    border-left-color: var(--primary);
    color: #fff;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    gap: 10px;
    align-items: center;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(59,172,240,0.25);
    display: grid;
    place-items: center;
    font-weight: 700;
}

.sidebar-footer strong {
    display: block;
    font-size: 14px;
}

.sidebar-footer small {
    color: #94a3b8;
    font-size: 12px;
}

.app-main {
    margin-left: 260px;
    width: calc(100% - 260px);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 26px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar h2 {
    font-size: 22px;
}

.topbar p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.topbar-menu-btn {
    display: none;
}

.btn.icon-only {
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
}

.content-area {
    padding: 26px;
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.ghost {
    background: #edf2f7;
    color: #334155;
}

.btn.danger {
    background: #fee2e2;
    color: #991b1b;
}

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

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

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(30, 41, 59, 0.05);
}

.kpi-value {
    margin-top: 10px;
    font-size: 30px;
    letter-spacing: -0.02em;
    font-family: 'Manrope', sans-serif;
}

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

.kpi-foot {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
}

.positive { color: var(--success); }
.negative { color: var(--danger); }

.section-title {
    margin-bottom: 16px;
    font-size: 21px;
}

.chart-card {
    min-height: 350px;
    overflow: hidden;
}

.chart-area {
    position: relative;
    height: 290px;
    width: 100%;
}

.chart-area canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tr:hover td {
    background: #f8fafc;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

input, select {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    width: 100%;
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,172,240,0.15);
}

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

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.insight-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.insight-pill {
    padding: 10px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.insight-pill.warning { background: #fef3c7; color: #92400e; }
.insight-pill.danger { background: #fee2e2; color: #991b1b; }
.insight-pill.success { background: #dcfce7; color: #166534; }
.insight-pill.info { background: #dbeafe; color: #1e40af; }

.login-page {
    min-height: 100vh;
    background: radial-gradient(circle at top left, #1e293b, #121212 70%);
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 20px 45px rgba(0,0,0,0.3);
}

.space-y > * + * {
    margin-top: 12px;
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
    color: #fff;
}

.login-brand .badge {
    width: 68px;
    height: 68px;
    border-radius: 18px;
    background: #fff;
    color: #0f172a;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
}

.login-brand h1 {
    font-size: 33px;
}

.login-brand p {
    margin: 8px 0 0;
    color: #cbd5e1;
}

.upload-area {
    border: 2px dashed #bfdbfe;
    border-radius: 16px;
    padding: 26px;
    background: #f8fbff;
    text-align: center;
}

.upload-area h3 {
    font-size: 24px;
    margin: 8px 0;
}

.upload-area p {
    color: var(--muted);
    max-width: 480px;
    margin: 0 auto 16px;
}

.badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge.ok { background: #dcfce7; color: #166534; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.fail { background: #fee2e2; color: #991b1b; }

@media (max-width: 1200px) {
    .card-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid-3 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid-3 > .card[style*="grid-column"] { grid-column: span 1 !important; }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }

    .app-main {
        margin-left: 240px;
        width: calc(100% - 240px);
    }

    .topbar {
        padding: 14px 18px;
    }

    .content-area {
        padding: 20px 18px;
    }
}

@media (max-width: 960px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(82vw, 300px);
        max-width: 300px;
        height: 100vh;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 95;
        box-shadow: 0 20px 45px rgba(2, 6, 23, 0.45);
    }

    .app-shell.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        border: none;
        background: rgba(15, 23, 42, 0.52);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 80;
    }

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

    .sidebar-close {
        display: inline-flex;
    }

    .app-main {
        margin: 0;
        width: 100%;
    }

    .topbar {
        padding: 12px 14px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .topbar-left {
        align-items: flex-start;
        width: 100%;
    }

    .topbar h2 {
        font-size: 20px;
    }

    .topbar-menu-btn {
        display: inline-flex;
    }

    .topbar-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .topbar-actions .btn {
        justify-content: center;
    }

    .content-area {
        padding: 14px;
    }

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

    .form-grid .field[style*="grid-column"] {
        grid-column: span 1 !important;
    }

    .section-title {
        font-size: 18px;
    }

    .kpi-value {
        font-size: 24px;
    }

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

    .chart-area {
        height: 240px;
    }

    .card {
        padding: 16px;
    }

    table {
        min-width: 560px;
    }
}

@media (max-width: 640px) {
    .topbar h2 {
        font-size: 18px;
    }

    .topbar p {
        font-size: 12px;
    }

    .topbar-actions {
        grid-template-columns: 1fr;
    }

    .topbar-actions .btn {
        width: 100%;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .sidebar-footer {
        padding: 14px;
    }

    .login-card {
        padding: 22px;
    }

    .login-brand h1 {
        font-size: 28px;
    }

    .upload-area {
        padding: 18px;
    }

    table {
        min-width: 520px;
    }
}
