:root {
    --sidebar-width: 268px;
    --sidebar-bg: #101c2c;
    --sidebar-bg-soft: #16263a;
    --sidebar-text: #a9b8cb;
    --sidebar-text-active: #ffffff;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --surface: #f4f6fb;
    --border: #e5e9f2;
    --text: #182230;
    --muted: #667085;
    --radius: 14px;
}

* { -webkit-font-smoothing: antialiased; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: var(--surface);
    color: var(--text);
    font-size: .925rem;
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

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

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.brand-link { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    color: #fff; font-size: 1.1rem; flex: 0 0 auto;
}
.brand-mark-lg { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 15px; }
.brand-text strong { display: block; font-size: .98rem; letter-spacing: .04em; }
.brand-text small { display: block; color: var(--sidebar-text); font-size: .68rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 10px 20px; scrollbar-width: thin; }
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 20px; }

.nav-section {
    text-transform: uppercase;
    letter-spacing: .09em;
    font-size: .63rem;
    font-weight: 700;
    color: #61758f;
    padding: 16px 12px 6px;
}

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 12px; margin-bottom: 2px;
    border-radius: 9px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .855rem;
    transition: background .15s, color .15s;
}
.nav-item i { font-size: 1rem; width: 18px; text-align: center; opacity: .9; }
.nav-item:hover { background: var(--sidebar-bg-soft); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(37,99,235,.95), rgba(37,99,235,.72)); color: #fff; box-shadow: 0 6px 16px rgba(37,99,235,.25); }

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.06); }
.license-chip { display: flex; align-items: center; gap: 10px; background: var(--sidebar-bg-soft); border-radius: 10px; padding: 10px 12px; font-size: .78rem; color: #d5dfec; }
.license-chip i { color: #34d399; font-size: 1.05rem; }
.license-chip small { color: #7c8fa8; display: block; font-size: .7rem; }

.sidebar-backdrop { display: none; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1020;
}
.page-heading h1 { font-size: 1.08rem; font-weight: 700; margin: 0 0 2px; }
.page-heading .breadcrumb { font-size: .74rem; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.company-select { max-width: 230px; }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: #e0e9ff; color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8rem;
}
.notif-dot {
    position: absolute; top: -4px; right: -4px;
    background: #ef4444; color: #fff; border-radius: 10px;
    font-size: .6rem; padding: 1px 5px; font-weight: 700;
}

.content-area { padding: 24px; flex: 1; }
.app-footer {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 14px 24px; border-top: 1px solid var(--border);
    font-size: .75rem; color: var(--muted); background: #fff;
}

.flash-stack { position: relative; z-index: 1080; }
.flash-stack .alert { border: 0; border-left: 4px solid currentColor; }

/* ---------- Cards & tables ---------- */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.card-header { background: #fff; border-bottom: 1px solid var(--border); padding: 14px 18px; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-title { font-size: .95rem; font-weight: 700; }
.card-body { padding: 18px; }

.kpi-card .card-body { padding: 18px; }
.kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.kpi-value { font-size: 1.32rem; font-weight: 700; letter-spacing: -.01em; }
.kpi-sub { font-size: .75rem; margin-top: 4px; }
.kpi-icon { width: 40px; height: 40px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; }

.aging-legend { font-size: .76rem; display: grid; gap: 6px; }
.aging-legend > div { display: flex; align-items: center; gap: 7px; }
.aging-legend strong { margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.bg-orange { background: #f97316; }

.low-stock-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.low-stock-list li:last-child { border-bottom: 0; }

.mini-stat { display: flex; align-items: center; gap: 10px; background: #f8faff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.mini-stat i { font-size: 1.15rem; color: var(--brand); }
.mini-stat span { display: block; font-size: .7rem; color: var(--muted); }
.mini-stat strong { font-size: .9rem; }

.table { font-size: .84rem; }
.table > thead th {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); font-weight: 700; background: #fafbff;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table > tbody > tr > td { vertical-align: middle; border-color: #eef1f7; }
.table-hover > tbody > tr:hover > * { background: #f8faff; }

/* ---------- Forms ---------- */
.form-label { font-size: .79rem; font-weight: 600; color: #344054; margin-bottom: 4px; }
.form-control, .form-select { border-color: #d5dbe7; font-size: .87rem; border-radius: 9px; }
.form-control:focus, .form-select:focus { border-color: #93b4fb; box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .1); }
.input-group-text { background: #f7f9fd; border-color: #d5dbe7; color: var(--muted); }
.form-section { border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; background: #fff; }
.form-section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 14px; }
.required::after { content: " *"; color: #dc2626; }

.btn { border-radius: 9px; font-size: .85rem; font-weight: 600; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-sm { font-size: .78rem; padding: .3rem .6rem; }
.btn-icon { padding: .28rem .45rem; line-height: 1; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 150px; }

/* ---------- Documents ---------- */
.line-table { width: 100%; font-size: .83rem; }
.line-table th { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: #fafbff; padding: 8px; border-bottom: 1px solid var(--border); }
.line-table td { padding: 6px; border-bottom: 1px solid #f0f3f9; vertical-align: middle; }
.line-table .form-control, .line-table .form-select { font-size: .8rem; padding: .3rem .45rem; }
.line-table input[type="number"] { text-align: right; }
.doc-totals { width: 320px; margin-left: auto; font-size: .85rem; }
.doc-totals .row-line { display: flex; justify-content: space-between; padding: 6px 0; }
.doc-totals .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: .98rem; }
.doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.doc-timeline { list-style: none; padding: 0; margin: 0; }
.doc-timeline li { padding: 0 0 14px 24px; border-left: 2px solid var(--border); position: relative; }
.doc-timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.doc-timeline li:last-child { border-left-color: transparent; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.info-grid dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.info-grid dd { margin: 2px 0 0; font-weight: 600; }

/* ---------- Auth ---------- */
.auth-body { background: #eef2f9; min-height: 100vh; }
.auth-shell { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.auth-visual {
    background: radial-gradient(circle at 20% 10%, #1e3a8a 0, transparent 45%),
                radial-gradient(circle at 90% 80%, #0e7490 0, transparent 45%),
                linear-gradient(150deg, #0b1424, #132742 60%, #0f2438);
    color: #e6eefc; padding: 54px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.auth-visual::after {
    content: ""; position: absolute; inset: 0;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 42px 42px; pointer-events: none;
}
.auth-visual-inner { position: relative; z-index: 1; max-width: 480px; }
.auth-visual h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.15; margin-bottom: 18px; letter-spacing: -.02em; }
.auth-visual .lead { color: #a9bcd8; font-size: 1rem; }
.auth-modules { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.auth-modules span { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: 999px; padding: 6px 12px; font-size: .78rem; }
.auth-modules i { margin-right: 5px; color: #5eead4; }
.auth-visual-footer { display: flex; justify-content: space-between; font-size: .75rem; color: #7e93b3; position: relative; z-index: 1; }
.auth-form-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: #fff; }
.auth-form-wrap { width: 100%; max-width: 400px; }
.demo-credentials { background: #f6f8fd; border: 1px dashed #cdd8ea; border-radius: 12px; padding: 14px 16px; font-size: .75rem; color: #475467; }
.demo-credentials strong { font-size: .78rem; }
.credential-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.credential-row span { color: var(--muted); }
.credential-row code { font-size: .7rem; color: #1e40af; }

/* ---------- Misc ---------- */
.error-page { max-width: 460px; margin: 8vh auto; text-align: center; padding: 24px; }
.error-page .display-1 { letter-spacing: -.04em; }
.empty-state { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty-state i { font-size: 2rem; display: block; margin-bottom: 8px; opacity: .5; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-heading h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.badge { font-weight: 600; letter-spacing: .01em; }
.text-bg-light { border: 1px solid var(--border); }
.amount { font-variant-numeric: tabular-nums; }
.total-row { font-weight: 700; background: #f8faff; }
.table-actions { display: flex; gap: 4px; justify-content: flex-end; }
.pagination { --bs-pagination-font-size: .78rem; }
.stat-tile { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: #fff; }
.stat-tile .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-tile .value { font-size: 1.1rem; font-weight: 700; }
.nav-tabs .nav-link { font-size: .82rem; font-weight: 600; color: var(--muted); }
.nav-tabs .nav-link.active { color: var(--brand); }
.progress { background: #eef2f8; border-radius: 20px; }
.progress-bar { border-radius: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 1199.98px) {
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); }
    .app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .app-shell.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(8, 15, 26, .5); z-index: 1030;
    }
}
@media (max-width: 991.98px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .content-area { padding: 16px; }
    .topbar { padding: 12px 16px; }
}
@media (max-width: 575.98px) {
    .kpi-value { font-size: 1.1rem; }
    .doc-totals { width: 100%; }
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .app-footer, .no-print, .flash-stack { display: none !important; }
    .app-shell { display: block; }
    .content-area { padding: 0; }
    body { background: #fff; font-size: .85rem; }
    .card { border: 0; box-shadow: none; }
    a { color: #000; text-decoration: none; }
}
