:root {
    --ink: #172033;
    --muted: #687386;
    --paper: #f5f7fa;
    --card: #ffffff;
    --line: #e1e6ed;
    --sidebar: #17233c;
    --sidebar-text: #cbd5e1;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --ok: #16845b;
    --bad: #dc3545;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
    --radius: 8px;
    --font: "Segoe UI", Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }

.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 5px 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 18px;
}
.brand small {
    display: block;
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 4px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.nav a {
    display: block;
    text-decoration: none;
    color: var(--sidebar-text);
    padding: 11px 12px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 4px;
}
.nav a:hover, .nav a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
}
.nav a.active { background: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 0.85rem; color: #94a3b8; }

.main { flex: 1; padding: 28px 30px 90px; min-width: 0; max-width: 1600px; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.menu-btn {
    display: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
}
h1, h2, h3 { font-family: var(--font); color: var(--ink); margin: 0 0 8px; }
h1 { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
.lede { color: var(--muted); margin: 0 0 22px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.kpi label {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.kpi {
    position: relative;
    overflow: hidden;
    min-height: 132px;
    border-top: 3px solid #cbd5e1;
}
.kpi::after {
    content: "";
    position: absolute;
    width: 76px;
    height: 76px;
    right: -28px;
    bottom: -34px;
    border-radius: 50%;
    background: currentColor;
    opacity: .06;
}
.kpi strong { font-size: 1.65rem; font-weight: 700; display: block; color: var(--ink); }
.kpi span { display: block; color: var(--muted); font-size: .82rem; margin-top: 8px; }
.kpi-revenue { border-top-color: #2563eb; color: #2563eb; }
.kpi-expense { border-top-color: #dc3545; color: #dc3545; }
.kpi-net { border-top-color: #16845b; color: #16845b; }
.kpi-stock { border-top-color: #7c3aed; color: #7c3aed; }
.kpi.profit strong { color: var(--ok); }
.kpi.loss strong { color: var(--bad); }

.analysis-card {
    position: relative;
    min-height: 128px;
    border-left: 4px solid #64748b;
}
.analysis-card label {
    display: block;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin-bottom: 8px;
}
.analysis-card strong {
    display: block;
    color: var(--ink);
    font-size: 1.45rem;
    font-weight: 700;
}
.analysis-card span {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    margin-top: 7px;
}
.analysis-card.personnel { border-left-color: #2563eb; }
.analysis-card.meat { border-left-color: #dc3545; }
.analysis-card.other { border-left-color: #f59e0b; }
.analysis-card.ratio { border-left-color: #7c3aed; }
.chart-wrap { position: relative; height: 330px; margin-top: 12px; }
.percentage-line {
    width: 100%;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf3;
    margin-bottom: 4px;
}
.percentage-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}
.payroll-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 16px 0;
}
.payroll-stats > div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}
.payroll-stats label {
    display: block;
    color: var(--muted);
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 4px;
}
.payroll-stats strong { font-size: 1.15rem; }
.payroll-status {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
}
.payroll-status.paid { color: #08734d; background: #e6f7f0; }
.payroll-status.pending { color: #9a5b00; background: #fff5db; }
.subpanel {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}
.receipt-scanner {
    padding: 16px;
    margin: 18px 0;
    border: 1px dashed #94a3b8;
    border-radius: 8px;
    background: #f8fafc;
}
.receipt-preview-image {
    display: block;
    width: min(280px, 100%);
    height: auto;
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}
.ocr-debug {
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: #475569;
    font: 12px/1.45 Consolas, monospace;
}
.expense-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    margin: 12px 0;
    border: 1px solid #bfdbfe;
    border-radius: 7px;
    background: #eff6ff;
    color: #1e3a8a;
}
.expense-total span { font-weight: 600; }
.expense-total strong { font-size: 1.25rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    min-height: 42px;
    transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #fff; color: #344054; border: 1px solid #cfd6df; }
.btn.secondary:hover { background: #f8fafc; border-color: #aeb8c5; }
.btn.ghost { background: transparent; color: var(--bad); border: 0; padding: 8px; min-height: 0; }
.btn.block { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.88rem; color: #344054; }
input, select, textarea {
    width: 100%;
    font: inherit;
    padding: 10px 12px;
    border: 1px solid #cfd6df;
    border-radius: 6px;
    background: #fff;
    min-height: 42px;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { min-height: 80px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: 8px; align-items: end; }

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.76rem; letter-spacing: 0.04em; text-transform: uppercase; padding: 10px 8px; border-bottom: 1px solid var(--line); background: #f8fafc; }
td { padding: 12px 8px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
.right { text-align: right; }
.flash { background: #eaf8f2; color: var(--ok); border: 1px solid #bfe8d7; padding: 11px 13px; border-radius: 6px; margin-bottom: 16px; }
.errors { background: #fff1f2; color: var(--bad); border: 1px solid #fecdd3; padding: 11px 13px; border-radius: 6px; margin-bottom: 16px; }
.expense-row { background: #f8fafc; border: 1px solid var(--line); padding: 12px; border-radius: 6px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.overlay { display: none; }
.pager { margin-top: 12px; }

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eef2f7;
}
.auth-card { width: min(410px, 100%); padding: 28px; box-shadow: 0 8px 24px rgba(16, 24, 40, .08); }

@media (max-width: 980px) {
    .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
    .row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .sidebar {
        position: fixed;
        z-index: 30;
        transform: translateX(-105%);
        transition: transform .2s ease;
    }
    .sidebar.open { transform: none; }
    .overlay.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(28,22,18,.45);
        z-index: 20;
    }
    .menu-btn { display: inline-flex; }
    .main { padding: 16px 14px 100px; }
    .grid-4, .grid-3, .grid-2, .row { grid-template-columns: 1fr; }
    .payroll-stats { grid-template-columns: 1fr; }
    table { display: block; overflow-x: auto; }
}

@media print {
    .sidebar, .menu-btn, .btn, form { display: none !important; }
    .main { padding: 0; }
    .app { display: block; }
}
