:root {
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --indigo: #4f46e5;
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50: #f8fafc;
    --green: #059669;
    --red: #dc2626;
    --amber: #d97706;
    --orange: #ea580c;
    --sidebar-w: 250px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; background: var(--slate-100); color: var(--slate-900); font-size: 14px; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); background: var(--slate-900); color: #cbd5e1;
    position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto; z-index: 50;
    display: flex; flex-direction: column;
}
.sidebar .brand { padding: 1.25rem 1.5rem; display: flex; align-items: center; gap: 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar .brand .logo { width: 38px; height: 38px; background: linear-gradient(135deg, var(--primary), var(--indigo)); border-radius: 0.6rem; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 1rem; flex-shrink: 0; }
.sidebar .brand .name { font-weight: 800; font-size: 0.95rem; color: #fff; line-height: 1.15; }
.sidebar .brand .sub { font-size: 0.65rem; color: var(--slate-400); text-transform: uppercase; letter-spacing: 0.05em; }
.sidebar nav { padding: 0.75rem 0; flex: 1; }
.sidebar .nav-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--slate-500); padding: 0.9rem 1.5rem 0.4rem; font-weight: 700; }
.sidebar .nav-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 1.5rem; color: var(--slate-300); font-weight: 500; transition: all 0.15s; border-left: 3px solid transparent; }
.sidebar .nav-item i { width: 18px; text-align: center; font-size: 0.95rem; opacity: 0.8; }
.sidebar .nav-item:hover { background: rgba(255,255,255,0.04); color: #fff; text-decoration: none; }
.sidebar .nav-item.active { background: rgba(14,165,233,0.12); color: #fff; border-left-color: var(--primary); }
.sidebar .nav-item.active i { color: var(--primary); opacity: 1; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--slate-200); display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; position: sticky; top: 0; z-index: 40; }
.topbar .title { font-weight: 700; font-size: 1.05rem; }
.topbar .user { display: flex; align-items: center; gap: 0.6rem; }
.topbar .user .avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--indigo)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; }
.topbar .user .meta { line-height: 1.15; }
.topbar .user .meta .n { font-weight: 700; font-size: 0.82rem; }
.topbar .user .meta .r { font-size: 0.7rem; color: var(--slate-500); text-transform: capitalize; }

.content { padding: 1.5rem; flex: 1; }

/* ---- Cards & grids ---- */
.card { background: #fff; border: 1px solid var(--slate-200); border-radius: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.card .card-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--slate-100); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card .card-head h3 { margin: 0; font-size: 0.95rem; font-weight: 700; }
.card .card-body { padding: 1.25rem; }
.card .card-body.no-pad { padding: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid-4, .grid-3 { grid-template-columns: 1fr; } }

/* ---- KPI stat cards ---- */
.stat { background: #fff; border: 1px solid var(--slate-200); border-radius: 1rem; padding: 1.25rem; display: flex; align-items: flex-start; gap: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.stat .icon { width: 44px; height: 44px; border-radius: 0.75rem; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0; }
.stat .v { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .l { font-size: 0.78rem; color: var(--slate-500); font-weight: 600; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--slate-500); font-weight: 700; padding: 0.7rem 1rem; border-bottom: 1px solid var(--slate-200); white-space: nowrap; }
table.data td { padding: 0.7rem 1rem; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.data tbody tr:hover { background: var(--slate-50); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.55rem 1rem; border-radius: 0.6rem; font-weight: 600; font-size: 0.82rem; border: 1px solid transparent; cursor: pointer; transition: all 0.15s; line-height: 1.2; }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 10px -3px rgba(14,165,233,0.4); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-dark { background: var(--slate-900); color: #fff; }
.btn-dark:hover { background: var(--slate-800); color: #fff; }
.btn-outline { background: #fff; border-color: var(--slate-300); color: var(--slate-700); }
.btn-outline:hover { border-color: var(--slate-400); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--slate-600); margin-bottom: 0.35rem; }
.field input, .field select, .field textarea {
    width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--slate-300); border-radius: 0.55rem;
    font-size: 0.9rem; font-family: inherit; background: #fff; color: var(--slate-900); transition: border 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.12); }
.field .hint { font-size: 0.7rem; color: var(--slate-400); margin-top: 0.25rem; }

/* ---- Alerts ---- */
.alert { padding: 0.9rem 1rem; border-radius: 0.7rem; font-size: 0.85rem; font-weight: 600; margin-bottom: 1.25rem; display: flex; align-items: center; gap: 0.6rem; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ---- Pills & misc ---- */
.pill { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.pill.muted { background: var(--slate-100); color: var(--slate-500); border: 1px solid var(--slate-200); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }
.page-head .sub { color: var(--slate-500); font-size: 0.85rem; margin-top: 0.2rem; }
.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.muted { color: var(--slate-500); }
.small { font-size: 0.78rem; }
.mt { margin-top: 1.25rem; }
.mb { margin-bottom: 1.25rem; }
.tac { text-align: center; }
.right { text-align: right; }
.flex { display: flex; }
.between { justify-content: space-between; }
.gap { gap: 0.75rem; }
.wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.bold { font-weight: 700; }

/* ---- Charts ---- */
.chart-box { background: #fff; border: 1px solid var(--slate-200); border-radius: 1rem; padding: 1.25rem; }
.chart-box h3 { margin: 0 0 1rem; font-size: 0.9rem; font-weight: 700; }
.bars { display: flex; align-items: flex-end; gap: 0.5rem; height: 160px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; height: 100%; justify-content: flex-end; }
.bars .bar .col { width: 100%; max-width: 40px; background: linear-gradient(180deg, var(--primary), var(--indigo)); border-radius: 0.4rem 0.4rem 0 0; min-height: 2px; }
.bars .bar .x { font-size: 0.65rem; color: var(--slate-500); }

/* ---- Filter bar ---- */
.filters { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filters .field { min-width: 160px; }

/* ---- Login page ---- */
.login-wrap { min-height: 100vh; display: flex; background: var(--slate-900); }
.login-left { flex: 1.2; background: linear-gradient(135deg, #0c4a6e, #1e1b4b); color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 4rem; position: relative; overflow: hidden; }
.login-left h1 { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.04em; margin-bottom: 1rem; }
.login-left p { color: #93c5fd; max-width: 460px; line-height: 1.7; }
.login-right { flex: 0.8; background: #fff; display: flex; align-items: center; justify-content: center; padding: 4rem; }
.login-card { width: 100%; max-width: 400px; }
@media (max-width: 900px) { .login-left { display: none; } .login-right { flex: 1; } }

/* ---- Invoice print ---- */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { margin-left: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff !important; }
}
.invoice-sheet { background: #fff; border: 1px solid var(--slate-200); border-radius: 1rem; padding: 2rem; max-width: 850px; margin: 0 auto; }
.invoice-sheet .head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--slate-900); padding-bottom: 1rem; margin-bottom: 1rem; }
.invoice-sheet table { width: 100%; border-collapse: collapse; }
.invoice-sheet table th, .invoice-sheet table td { border: 1px solid var(--slate-300); padding: 0.5rem 0.6rem; font-size: 0.82rem; }
.invoice-sheet table th { background: var(--slate-100); }
