:root {
    --bg: #f6f8fc;
    --card: #ffffff;
    --text: #162033;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --red: #dc2626;
    --yellow: #ca8a04;
    --border: #e5e7eb;
    --shadow: 0 18px 50px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #dbeafe 0, transparent 34%), var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 270px; padding: 26px 18px; background: rgba(255,255,255,.84);
    backdrop-filter: blur(16px); border-right: 1px solid var(--border); position: sticky; top:0; height:100vh;
}
.brand { font-size: 22px; font-weight: 850; margin-bottom: 28px; letter-spacing: -.5px; }
.brand span { color: var(--primary); }
.nav a {
    display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-radius: 16px;
    color: #334155; font-weight: 650; margin-bottom: 8px;
}
.nav a:hover, .nav a.active { background: #eff6ff; color: var(--primary); }
.main { flex: 1; padding: 30px; }
.topbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:24px; }
h1 { margin:0; font-size: 30px; letter-spacing:-.8px; }
.subtitle { color: var(--muted); margin-top: 6px; }
.grid { display:grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap:18px; }
.card {
    background: rgba(255,255,255,.9); border: 1px solid var(--border); border-radius: 24px;
    box-shadow: var(--shadow); padding: 20px;
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat .value { font-size: 26px; font-weight: 850; margin-top: 8px; }
.row { display:flex; gap:18px; align-items:flex-start; }
.col { flex:1; }
.table { width:100%; border-collapse: collapse; }
.table th { text-align:left; font-size:12px; color:var(--muted); padding:12px; border-bottom:1px solid var(--border); }
.table td { padding:14px 12px; border-bottom:1px solid #f1f5f9; font-size:14px; }
.badge { display:inline-flex; padding:6px 10px; border-radius:999px; font-size:12px; font-weight:800; background:#eef2ff; color:#3730a3; }
.badge.green { background:#dcfce7; color:#166534; }
.badge.red { background:#fee2e2; color:#991b1b; }
.badge.yellow { background:#fef9c3; color:#854d0e; }
.btn {
    border:0; background:var(--primary); color:white; padding:11px 15px; border-radius:14px;
    font-weight:800; cursor:pointer; display:inline-flex; align-items:center; justify-content:center;
}
.btn:hover { background:var(--primary-dark); }
.btn.secondary { background:#e2e8f0; color:#0f172a; }
.form-grid { display:grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap:12px; }
.form-grid.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
label { display:block; font-size:13px; color:var(--muted); font-weight:800; margin: 8px 0 6px; }
input, select, textarea {
    width:100%; padding:12px 13px; border:1px solid var(--border); border-radius:14px; background:white;
    outline:none; font:inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow:0 0 0 4px #dbeafe; }
.actions { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.item-row { display:grid; grid-template-columns: 2fr .7fr 1fr .8fr; gap:10px; margin-bottom:10px; }
.total-box { display:flex; justify-content:flex-end; margin-top:16px; }
.total-box div { min-width:280px; background:#f8fafc; border-radius:18px; padding:16px; }
.kv { display:flex; justify-content:space-between; padding:7px 0; color:#334155; }
.kv.strong { font-weight:900; font-size:20px; color:#0f172a; border-top:1px solid var(--border); margin-top:8px; padding-top:12px; }
.search { max-width:380px; display:flex; gap:8px; }
@media (max-width: 1050px) {
    .layout { display:block; }
    .sidebar { width:100%; height:auto; position:relative; }
    .nav { display:flex; flex-wrap:wrap; }
    .grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .row { flex-direction:column; }
}
@media (max-width: 650px) {
    .main { padding:18px; }
    .grid, .form-grid, .form-grid.three, .item-row { grid-template-columns:1fr; }
}


/* Mobile-first improvements */
.mobile-header {
    display: none;
}

.sidebar-close {
    display: none;
}

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

.btn {
    min-height: 42px;
}

@media (max-width: 820px) {
    body {
        background: #f6f8fc;
    }

    .mobile-header {
        position: sticky;
        top: 0;
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 14px;
        background: rgba(255,255,255,.94);
        backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--border);
    }

    .mobile-brand {
        margin: 0;
        font-size: 18px;
    }

    .mobile-menu-btn {
        border: 0;
        background: var(--primary);
        color: #fff;
        font-weight: 800;
        padding: 10px 13px;
        border-radius: 13px;
    }

    .layout {
        display: block;
        min-height: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -290px;
        width: 280px;
        height: 100vh;
        z-index: 1200;
        transition: left .22s ease;
        box-shadow: 20px 0 60px rgba(15,23,42,.22);
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-close {
        display: inline-flex;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 38px;
        height: 38px;
        border: 0;
        border-radius: 12px;
        align-items: center;
        justify-content: center;
        background: #e2e8f0;
        font-size: 24px;
        font-weight: 800;
        color: #0f172a;
    }

    .sidebar .brand {
        margin-right: 42px;
    }

    .nav {
        display: block;
    }

    .nav a {
        padding: 12px 13px;
        margin-bottom: 7px;
        border-radius: 14px;
    }

    .main {
        padding: 14px;
    }

    .topbar {
        display: block;
        margin-bottom: 14px;
    }

    .topbar .search,
    .topbar form {
        margin-top: 12px;
        width: 100%;
        max-width: none;
    }

    h1 {
        font-size: 24px;
        line-height: 1.15;
    }

    h2 {
        font-size: 18px;
    }

    .subtitle {
        font-size: 13px;
    }

    .grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .card {
        border-radius: 18px;
        padding: 14px;
        box-shadow: 0 10px 28px rgba(15,23,42,.07);
    }

    .stat .label {
        font-size: 11px;
    }

    .stat .value {
        font-size: 18px;
        word-break: break-word;
    }

    .row {
        flex-direction: column;
        gap: 12px;
    }

    .col {
        width: 100%;
        flex: none;
    }

    .form-grid,
    .form-grid.three,
    .item-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    input, select, textarea {
        padding: 12px;
        border-radius: 12px;
        font-size: 16px;
    }

    .actions {
        gap: 8px;
    }

    .actions .btn,
    td .btn,
    form .btn {
        width: 100%;
    }

    .search {
        display: grid;
        grid-template-columns: 1fr auto;
    }

    .table {
        border-collapse: separate;
        border-spacing: 0 10px;
    }

    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }

    .table tr:first-child {
        display: none;
    }

    .table tr {
        background: #fff;
        border: 1px solid var(--border);
        border-radius: 16px;
        padding: 10px;
        box-shadow: 0 8px 20px rgba(15,23,42,.05);
    }

    .table td {
        border-bottom: 1px solid #f1f5f9;
        padding: 9px 4px;
        font-size: 14px;
        display: grid;
        grid-template-columns: 110px 1fr;
        gap: 10px;
        align-items: start;
    }

    .table td:last-child {
        border-bottom: 0;
    }

    .table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 850;
    }

    .total-box {
        justify-content: stretch;
    }

    .total-box div {
        min-width: 0;
        width: 100%;
    }

    .kv.strong {
        font-size: 17px;
    }
}

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

    .main {
        padding: 10px;
    }

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

    h1 {
        font-size: 22px;
    }

    .table td {
        grid-template-columns: 95px 1fr;
    }

    .brand {
        font-size: 19px;
    }
}


/* Prevent accidental huge logo/image overflow in content */
.main > img[src="/static/logo.png"],
.main img
