:root {
    --primary: #0B1E3D;
    --primary-light: #16305C;
    --accent: #3B82F6;
    --bg: #F5F7FA;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --green: #16A34A;
    --orange: #F59E0B;
    --red: #DC2626;
    --purple: #7C3AED;
    --blue: #3B82F6;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Poppins', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
}

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

/* ===== APP SHELL ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: transform 0.25s ease;
    z-index: 100;
    overflow-x: hidden;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    font-weight: 700;
    font-size: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    min-width: 0;
}
.brand-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent);
    display: inline-block;
}
.sidebar-logo-wrap {
    display: inline-flex;
    align-items: center;
    width: 100%;
    min-width: 0;
}
.sidebar-logo { height: 70px; width: auto; max-width: 100%; object-fit: contain; display: block; }
.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 12px 10px;
    overflow-y: auto;
    flex: 1;
}
.sidebar-nav a {
    padding: 11px 14px;
    border-radius: var(--radius);
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    margin-bottom: 2px;
    transition: background 0.15s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: var(--accent);
    color: #fff;
}
.nav-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.4);
    padding: 14px 14px 4px;
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.5); }
.logout-link {
    display: block;
    font-size: 13px;
    color: #FCA5A5;
    padding: 8px 0 0;
}
.hamburger {
    display: none;
    position: fixed;
    top: 14px; left: 14px;
    z-index: 200;
    background: var(--primary);
    color: #fff;
    border: none;
    width: 40px; height: 40px;
    border-radius: var(--radius);
    font-size: 18px;
    cursor: pointer;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    padding: 24px 28px;
    min-width: 0;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 10px;
}
.topbar h1 { font-size: 22px; margin: 0; color: var(--primary); }
.topbar .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ===== CARDS / GRID ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.grid { display: grid; gap: 18px; }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.line-item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 8px;
    align-items: end;
    background: var(--bg);
    padding: 10px;
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.kpi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    border: 1px solid var(--border);
    transition: box-shadow 0.15s, transform 0.15s;
}
.kpi-card:hover { box-shadow: 0 6px 16px rgba(11,30,61,0.10); transform: translateY(-1px); }
a.kpi-card { display: block; text-decoration: none; color: inherit; }
.kpi-icon {
    width: 36px; height: 36px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px;
    margin-bottom: 12px;
}
.kpi-icon-blue { background: #DBEAFE; }
.kpi-icon-green { background: #DCFCE7; }
.kpi-icon-orange { background: #FEF3C7; }
.kpi-icon-violet { background: #EDE9FE; }
.kpi-icon-pink { background: #FCE7F3; }
.kpi-icon-indigo { background: #E0E7FF; }
.kpi-card .kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 700; color: var(--primary); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-card .kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== CHARTS ===== */
.chart-box { position: relative; width: 100%; }
.chart-box-sm { height: 260px; }
.chart-empty {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 60px 20px;
    background: var(--bg);
    border-radius: var(--radius);
}

/* ===== HOME PAGE ===== */
.section-heading {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    margin: 28px 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-heading::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.home-tile {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    text-decoration: none;
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}
.home-tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 3px;
    background: var(--tile-accent, var(--accent));
    opacity: 0;
    transition: opacity 0.15s;
}
.home-tile:hover {
    box-shadow: 0 8px 20px rgba(11,30,61,0.10);
    transform: translateY(-2px);
    border-color: transparent;
}
.home-tile:hover::before { opacity: 1; }
.home-tile-blue { --tile-accent: #3B82F6; }
.home-tile-green { --tile-accent: #16A34A; }
.home-tile-violet { --tile-accent: #7C3AED; }
.home-tile-orange { --tile-accent: #F59E0B; }
.home-tile-pink { --tile-accent: #DB2777; }
.home-tile-indigo { --tile-accent: #4F46E5; }
.home-tile-icon {
    width: 46px; height: 46px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.home-tile-icon-blue { background: #DBEAFE; }
.home-tile-icon-green { background: #DCFCE7; }
.home-tile-icon-violet { background: #EDE9FE; }
.home-tile-icon-orange { background: #FEF3C7; }
.home-tile-icon-pink { background: #FCE7F3; }
.home-tile-icon-indigo { background: #E0E7FF; }
.home-tile-body { min-width: 0; }
.home-tile h3 { margin: 2px 0 4px; color: var(--primary); font-size: 16px; }
.home-tile p { margin: 0 0 10px; color: var(--text-muted); font-size: 13px; }
.home-tile-link { color: var(--accent); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.home-tile-arrow { transition: transform 0.15s; }
.home-tile:hover .home-tile-arrow { transform: translateX(3px); }
.home-cta {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border-radius: var(--radius);
    padding: 28px 32px;
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    box-shadow: 0 10px 24px rgba(11,30,61,0.18);
}
.home-cta h2 { margin: 0 0 4px; font-size: 20px; }
.home-cta p { margin: 0; opacity: 0.85; font-size: 14px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #2563EB; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    padding: 20px;
    overflow-x: hidden;
}
.auth-card {
    background: #fff;
    border-radius: 12px;
    padding: 36px 32px;
    width: 100%;
    max-width: 400px;
    min-width: 0;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.auth-card h2 { color: var(--primary); margin-top: 0; }
.auth-logo { display: block; max-height: 60px; max-width: 100%; object-fit: contain; margin: 0 auto 20px; }
.auth-card .muted-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error { background: #FEE2E2; color: #991B1B; }
.alert-success { background: #DCFCE7; color: #166534; }
.alert-info { background: #DBEAFE; color: #1E40AF; }

/* ===== TABLES ===== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    border-bottom: 2px solid var(--border);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #FAFBFC; }

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-orange { background: #FEF3C7; color: #92400E; }
.badge-green { background: #DCFCE7; color: #166534; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-purple { background: #EDE9FE; color: #5B21B6; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
.search-box { max-width: 280px; }

/* ===== OCR / DOCUMENT SCAN ===== */
.ocr-upload-box {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--bg);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.ocr-upload-box .ocr-label { font-size: 12px; font-weight: 600; color: var(--text); margin-right: auto; }
.ocr-upload-box .ocr-status { font-size: 12px; width: 100%; }

/* ===== RESPONSIVE ===== */

/* Tablet (portrait/landscape) — collapse the sidebar behind the hamburger since the
   nav list is long, and step KPI/report grids down to 2-3 columns instead of 1. */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        height: 100vh;
    }
    .sidebar.open { transform: translateX(0); }
    .hamburger { display: block; }
    .main-content { padding: 70px 16px 24px; }

    .grid-6 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    .card { padding: 16px; }
    .modal-card, #ocrCameraModal > div { max-width: 92vw; }
}

/* Phone */
@media (max-width: 640px) {
    .grid-6, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .line-item-row { grid-template-columns: 1fr; }
    .line-item-row > div:last-child { justify-self: end; }

    .topbar h1 { font-size: 19px; }
    .auth-card { padding: 28px 22px; }

    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tbody tr {
        margin-bottom: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 8px 0;
    }
    tbody td {
        border: none;
        padding: 6px 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        text-align: right;
    }
    tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 11px;
        text-transform: uppercase;
        text-align: left;
    }

    .ocr-upload-box { flex-direction: column; align-items: stretch; }
    .ocr-upload-box .ocr-label { margin-right: 0; }
    .ocr-upload-box .ocr-upload-trigger, .ocr-upload-box .ocr-camera-trigger { justify-content: center; }
}
