/* ============================================================
   AMGOMED PHARMACEUTICALS — Healthcare Sky-Blue + Poppins
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --stone-50:  #f8fafc;
    --stone-100: #f1f5f9;
    --stone-200: #e2e8f0;
    --stone-300: #cbd5e1;
    --stone-400: #94a3b8;
    --stone-500: #64748b;
    --stone-600: #475569;
    --stone-700: #334155;
    --stone-800: #1e293b;
    --stone-900: #0f172a;

    /* Sky blue — primary brand color */
    --emerald-50:  #f0f9ff;
    --emerald-100: #e0f2fe;
    --emerald-600: #0284c7;
    --emerald-700: #0369a1;
    --emerald-800: #075985;

    /* Real sky for highlights */
    --sky-50:  #f0f9ff;
    --sky-100: #e0f2fe;
    --sky-200: #bae6fd;
    --sky-400: #38bdf8;
    --sky-500: #0ea5e9;
    --sky-600: #0284c7;
    --sky-700: #0369a1;
    --sky-800: #075985;

    --rose-50:  #fff1f2;
    --rose-100: #ffe4e6;
    --rose-500: #f43f5e;
    --rose-600: #e11d48;
    --rose-700: #be123c;

    --amber-50:  #fffbeb;
    --amber-100: #fef3c7;
    --amber-200: #fde68a;
    --amber-500: #f59e0b;
    --amber-700: #b45309;
    --amber-800: #92400e;

    --blue-50:  #eff6ff;
    --blue-100: #dbeafe;
    --blue-500: #3b82f6;
    --blue-700: #1d4ed8;
    --blue-800: #1e40af;

    --violet-50: #f5f3ff;
    --violet-700: #6d28d9;
    --teal-50: #f0fdfa;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --font-display: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font-body);
    background: var(--stone-50);
    color: var(--stone-800);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

.font-display { font-family: var(--font-display); }
.font-mono { font-family: var(--font-mono); }
.italic { font-style: italic; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 256px;
    background: #fff;
    border-right: 1px solid var(--stone-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--stone-200);
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-mark {
    width: 44px; height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--emerald-600), var(--emerald-700));
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    flex-shrink: 0;
}
/* Wider logo box when image is present (handles wide logos like Amgomed) */
.logo-mark:has(img) {
    width: 120px;
    height: 44px;
    background: #fff;
    border: 1px solid var(--stone-200);
    border-radius: 6px;
}
.logo-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
}
.logo-text .name {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--stone-900);
    font-size: 17px;
    line-height: 1.2;
}
.logo-text .tag {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--stone-500);
    font-weight: 500;
}

.sidebar-create {
    padding: 12px;
    border-bottom: 1px solid var(--stone-200);
}
.btn-create {
    width: 100%;
    background: var(--stone-900);
    color: #fff;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s;
}
.btn-create:hover { background: var(--stone-800); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    color: var(--stone-600);
    font-size: 13px;
    transition: all 0.15s;
    border-right: 2px solid transparent;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: var(--stone-50); color: var(--stone-900); }
.nav-item.active {
    background: var(--emerald-50);
    color: var(--emerald-800);
    border-right-color: var(--emerald-700);
    font-weight: 500;
}
.nav-item .icon { color: var(--stone-400); flex-shrink: 0; }
.nav-item.active .icon { color: var(--emerald-700); }

.nav-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--stone-400);
    padding: 12px 16px 4px;
    font-weight: 600;
}

/* ============== TreeView Sidebar Nav ============== */
.sidebar-controls {
    padding: 0 12px 8px;
    border-bottom: 1px solid var(--stone-200);
    margin-bottom: 4px;
}
.nav-search-wrap {
    position: relative;
    margin-bottom: 8px;
}
.nav-search-wrap svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--stone-400);
    pointer-events: none;
}
.nav-search {
    width: 100%;
    padding: 7px 10px 7px 30px;
    font-size: 12px;
    border: 1px solid var(--stone-200);
    border-radius: var(--radius-sm);
    background: var(--stone-50);
    color: var(--stone-700);
    font-family: inherit;
    transition: all 0.15s;
}
.nav-search:focus {
    outline: none;
    border-color: var(--sky-500, var(--emerald-600));
    background: white;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.1);
}
.nav-control-buttons {
    display: flex;
    gap: 4px;
}
.nav-control-buttons button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid var(--stone-200);
    background: white;
    color: var(--stone-500);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.nav-control-buttons button:hover {
    background: var(--stone-50);
    color: var(--stone-700);
    border-color: var(--stone-300);
}

.nav-group {
    margin-bottom: 1px;
}
.nav-group-toggle-row {
    display: flex;
    align-items: center;
    gap: 0;
    padding-left: 8px;
}
.nav-group-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    color: var(--stone-500);
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.nav-group-icon-link:hover {
    background: var(--sky-50);
    color: var(--sky-700);
}
.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    padding: 9px 8px 5px 8px;
    background: transparent;
    border: none;
    color: var(--stone-400);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s;
    text-decoration: none;
}
.nav-group-toggle:hover,
.nav-group-toggle-link:hover {
    color: var(--sky-700);
}
.nav-group-toggle-link {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 9px 4px 5px 8px;
    color: var(--stone-400);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 600;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    border-radius: 4px;
}
.nav-group-toggle-link:hover {
    background: var(--sky-50);
}
.nav-group-chevron-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--stone-400);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    margin-right: 4px;
}
.nav-group-chevron-btn:hover {
    background: var(--stone-100);
    color: var(--stone-700);
}
.nav-group-label {
    text-align: left;
}
.nav-group-chevron {
    transition: transform 0.2s ease;
    color: var(--stone-400);
}
.nav-group.collapsed .nav-group-chevron {
    transform: rotate(-90deg);
}
.nav-group-items {
    max-height: 1500px;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.nav-group.collapsed .nav-group-items {
    max-height: 0;
}
.nav-group.expanded .nav-group-items {
    max-height: 1500px;
}

.sidebar-footer { padding: 12px; border-top: 1px solid var(--stone-200); }
.user-card {
    background: var(--stone-50);
    border: 1px solid var(--stone-200);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-card .avatar { width: 32px; height: 32px; font-size: 12px; }
.user-card .info { flex: 1; min-width: 0; }
.user-card .info .name { font-size: 12px; font-weight: 500; color: var(--stone-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .info .role { font-size: 10px; color: var(--stone-500); text-transform: uppercase; letter-spacing: 0.1em; }

/* ============================================================
   MAIN
   ============================================================ */
.main { flex: 1; overflow-y: auto; }

/* QuickBooks-style top menu bar */
.topmenu {
    background: linear-gradient(to bottom, #f8fafc, #e2e8f0);
    border-bottom: 1px solid var(--stone-300);
    padding: 0 16px;
    display: flex;
    align-items: stretch;
    gap: 2px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    flex-wrap: wrap;
}
.topmenu-item {
    position: relative;
}
.topmenu-link {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: var(--stone-700);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    height: 100%;
    transition: background 0.12s;
    white-space: nowrap;
}
.topmenu-link:hover {
    background: var(--sky-100);
    color: var(--sky-700);
}
.topmenu-link.active {
    background: var(--sky-600);
    color: #fff;
}
.topmenu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--stone-300);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 30;
    padding: 4px 0;
}
.topmenu-dropdown.open {
    display: block;
}
.topmenu-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    color: var(--stone-800);
    font-size: 13px;
    text-decoration: none;
    transition: background 0.1s;
}
.topmenu-dropdown a:hover {
    background: var(--sky-50);
    color: var(--sky-700);
}
.topmenu-dropdown a .icon {
    color: var(--stone-500);
    flex-shrink: 0;
}

@media print {
    .topmenu { display: none !important; }
}

@media (max-width: 768px) {
    .topmenu {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .topmenu-dropdown {
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
    }
}

body.dark-mode .topmenu {
    background: linear-gradient(to bottom, #1e293b, #0f172a);
    border-bottom-color: #334155;
}
body.dark-mode .topmenu-link {
    color: #cbd5e1;
}
body.dark-mode .topmenu-link:hover {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
}
body.dark-mode .topmenu-dropdown {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .topmenu-dropdown a {
    color: #cbd5e1;
}
body.dark-mode .topmenu-dropdown a:hover {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--stone-200);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}
.topbar-title .meta {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--stone-500);
    font-weight: 500;
}
.topbar-title h1 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    color: var(--stone-900);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .icon-btn {
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--stone-600);
    transition: background 0.15s;
}
.topbar-actions .icon-btn:hover { background: var(--stone-100); }
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--emerald-600), var(--emerald-700));
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.content { padding: 32px; max-width: 1600px; }

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
.eyebrow {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--stone-500);
    font-weight: 500;
}
.section-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    color: var(--stone-900);
}
.display-1 {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 600;
    color: var(--stone-900);
    line-height: 1.1;
}
.display-2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    color: var(--stone-900);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: #fff;
    border: 1px solid var(--stone-200);
    border-radius: var(--radius);
    transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-pad-lg { padding: 24px; }
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--stone-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.kpi-card {
    background: #fff;
    border: 1px solid var(--stone-200);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.2s ease;
    display: block;
    text-decoration: none;
    color: inherit;
}
.kpi-card:hover { box-shadow: var(--shadow-sm); }
.kpi-card-link {
    cursor: pointer;
}
.kpi-card-link:hover {
    border-color: var(--sky-400);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.15);
    transform: translateY(-2px);
    text-decoration: none;
    color: inherit;
}
.kpi-card-link:hover .kpi-value {
    color: var(--sky-700);
}
.kpi-card-link:hover .kpi-value.warn {
    color: var(--amber-700);
}
.kpi-card-link:hover .kpi-value.good {
    color: var(--emerald-700);
}
.kpi-card-active {
    border-color: var(--sky-500) !important;
    background: var(--sky-50);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.2);
}
.kpi-card-active .eyebrow {
    color: var(--sky-700);
    font-weight: 600;
}
.kpi-card .eyebrow { margin-bottom: 8px; }
.kpi-value {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    color: var(--stone-900);
    margin-bottom: 4px;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    word-break: break-word;
}
.kpi-value.alert { color: var(--rose-700); }
.kpi-value.good { color: var(--emerald-700); }
.kpi-value.warn { color: var(--amber-700); }
.kpi-meta {
    font-size: 12px;
    color: var(--stone-500);
    display: flex;
    align-items: center;
    gap: 6px;
}
.trend-up { color: var(--emerald-700); font-weight: 500; }
.trend-down { color: var(--rose-600); font-weight: 500; }

/* ============================================================
   GRID
   ============================================================ */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-gap-lg { gap: 24px; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

.stack { display: flex; flex-direction: column; gap: 24px; }
.stack-sm { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
    border: 1px solid transparent;
}
.btn-primary { background: var(--stone-900); color: #fff; }
.btn-primary:hover { background: var(--stone-800); }
.btn-emerald { background: var(--emerald-700); color: #fff; }
.btn-emerald:hover { background: var(--emerald-800); }
.btn-amber { background: var(--amber-700); color: #fff; }
.btn-amber:hover { background: var(--amber-800); }
.btn-rose { background: var(--rose-600); color: #fff; }
.btn-rose:hover { background: var(--rose-700); }
.btn-blue { background: var(--blue-700); color: #fff; }
.btn-secondary {
    background: var(--stone-100);
    color: var(--stone-700);
}
.btn-secondary:hover { background: var(--stone-200); }
.btn-outline {
    background: transparent;
    color: var(--emerald-700);
    border: 1px solid var(--emerald-700);
}
.btn-outline:hover { background: var(--emerald-50); }
.btn-ghost {
    background: transparent;
    color: var(--stone-700);
    border: 1px solid var(--stone-300);
}
.btn-ghost:hover { background: var(--stone-100); }
.btn-danger-ghost {
    background: transparent;
    color: var(--rose-600);
    border: 1px solid var(--rose-200, #fecdd3);
}
.btn-danger-ghost:hover { background: var(--rose-50); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 10px; font-size: 11px; }

/* Export buttons row */
.export-buttons {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}
.export-buttons .btn-sm { white-space: nowrap; }

.icon-action {
    padding: 6px;
    border-radius: 6px;
    color: var(--stone-500);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-action:hover { background: var(--stone-200); color: var(--stone-800); }
.icon-action.danger:hover { background: var(--rose-100); color: var(--rose-700); }
.icon-action.success:hover { background: var(--emerald-100); color: var(--emerald-800); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    display: inline-block;
}
.badge-paid, .badge-active { background: var(--emerald-100); color: var(--emerald-800); }
.badge-pending, .badge-low { background: var(--amber-100); color: var(--amber-800); }
.badge-partial { background: var(--blue-100); color: var(--blue-800); }
.badge-march_carryover, .badge-carryover { background: #fed7aa; color: #9a3412; font-weight: 700; }
.badge-overdue, .badge-out, .badge-cancelled, .badge-inactive { background: var(--rose-100); color: var(--rose-700); }
.badge-draft { background: var(--stone-100); color: var(--stone-700); }
.badge-good { background: var(--emerald-100); color: var(--emerald-800); }
.badge-cash { background: var(--emerald-100); color: var(--emerald-800); }
.badge-bank { background: var(--blue-100); color: var(--blue-800); }
.badge-admin { background: var(--rose-100); color: var(--rose-700); }
.badge-accountant { background: var(--blue-100); color: var(--blue-800); }
.badge-sales { background: var(--amber-100); color: var(--amber-800); }
.badge-staff { background: var(--stone-100); color: var(--stone-700); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
}
table.data thead {
    background: var(--stone-50);
    border-bottom: 2px solid var(--stone-200);
}
table.data th {
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--stone-500);
    font-weight: 600;
    padding: 12px 16px;
    white-space: nowrap;
}
table.data td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--stone-100);
    font-size: 13px;
    color: var(--stone-700);
    vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr {
    transition: background 0.1s;
}
table.data tbody tr:nth-child(odd) {
    background: rgba(248, 250, 252, 0.5);
}
table.data tbody tr:hover {
    background: var(--sky-50);
}
table.data tfoot tr {
    background: var(--sky-50);
    border-top: 2px solid var(--sky-200, #bae6fd);
    font-weight: 700;
}
table.data tfoot td {
    color: var(--stone-900);
    font-weight: 700;
    border-bottom: 0;
    padding: 14px 16px;
}

/* ============================================================
   Generic .table class — same look as table.data + alternating rows
   ============================================================ */
table.table {
    width: 100%;
    border-collapse: collapse;
}
table.table thead {
    background: var(--stone-50);
    border-bottom: 2px solid var(--stone-200);
}
table.table th {
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--stone-600);
    font-weight: 700;
    padding: 10px 14px;
    white-space: nowrap;
    border-bottom: 1px solid var(--stone-200);
}
table.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--stone-100);
    font-size: 13px;
    color: var(--stone-700);
    vertical-align: middle;
}
table.table tbody tr {
    transition: background 0.1s;
}
table.table tbody tr:nth-child(odd) {
    background: rgba(248, 250, 252, 0.4);
}
table.table tbody tr:hover {
    background: var(--sky-50);
}
table.table tr:last-child td { border-bottom: 0; }
table.table tfoot tr {
    background: var(--amber-50);
    border-top: 2px solid var(--amber-200, #fde68a);
    font-weight: 700;
}
table.table tfoot td {
    color: var(--stone-900);
    font-weight: 700;
    border-bottom: 0;
}
table.table th.num, table.table td.num,
table.table th.cell-num, table.table td.cell-num {
    text-align: right;
}

.cell-strong { font-weight: 500; color: var(--stone-900); }
.cell-mono { font-family: var(--font-mono); }
.cell-num {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--stone-900);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
table.data th.num { text-align: right; }
.amount-pos { color: var(--emerald-700); font-family: var(--font-mono); font-weight: 600; }
.amount-neg { color: var(--rose-700); font-family: var(--font-mono); font-weight: 600; }

/* Semantic cell colors (used in AR Aging style — apply everywhere) */
.cell-num.warn  { color: #d97706; }       /* amber-700 */
.cell-num.good  { color: var(--emerald-700); }
.cell-num.danger{ color: var(--rose-700); }
.col-actions { white-space: nowrap; text-align: right; }

/* Dark mode support for .table */
body.dark-mode table.table thead { background: #1e293b; border-bottom-color: #334155; }
body.dark-mode table.table th    { color: #94a3b8; border-bottom-color: #334155; }
body.dark-mode table.table td    { color: #cbd5e1; border-bottom-color: #334155; }
body.dark-mode table.table tbody tr:nth-child(odd) { background: rgba(30,41,59,0.3); }
body.dark-mode table.table tbody tr:hover { background: rgba(56,189,248,0.08); }
body.dark-mode table.table tfoot tr { background: rgba(217,119,6,0.15); }
body.dark-mode table.table tfoot td { color: #f1f5f9; }

/* Dark mode for table.data */
body.dark-mode table.data thead { background: #1e293b; border-bottom-color: #334155; }
body.dark-mode table.data th    { color: #94a3b8; }
body.dark-mode table.data td    { color: #cbd5e1; border-bottom-color: #334155; }
body.dark-mode table.data tbody tr:nth-child(odd) { background: rgba(30,41,59,0.3); }
body.dark-mode table.data tbody tr:hover { background: rgba(56,189,248,0.08); }
body.dark-mode table.data tfoot tr { background: rgba(14,165,233,0.15); }
body.dark-mode table.data tfoot td { color: #f1f5f9; }

/* Tighter table for invoice items */
table.data.compact th, table.data.compact td { padding: 8px 12px; font-size: 12px; }

/* ============================================================
   FORMS
   ============================================================ */
.field-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--stone-500);
    font-weight: 500;
    margin-bottom: 6px;
    display: block;
}
.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--stone-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--stone-900);
    background: #fff;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--emerald-700);
    box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.1);
}
.input.cell-mono, .input[type="number"] { font-family: var(--font-mono); }
.textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, 1fr); }
.form-group { margin-bottom: 16px; }
.input-search {
    background: var(--stone-50);
    border: 1px solid var(--stone-200);
    padding: 9px 12px 9px 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: var(--emerald-50); color: var(--emerald-800); border: 1px solid var(--emerald-100); }
.alert-error { background: var(--rose-50); color: var(--rose-700); border: 1px solid #fecaca; }
.alert-warn { background: var(--amber-50); color: var(--amber-800); border: 1px solid var(--amber-200); }
.alert-info { background: var(--blue-50); color: var(--blue-800); border: 1px solid var(--blue-100); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(28, 25, 23, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    overflow: hidden;
}
.modal {
    background: #fff;
    border-radius: 20px;
    max-width: 880px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.modal-sm { max-width: 480px; }
.modal-md { max-width: 640px; }
.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--stone-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-body { padding: 24px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--stone-200);
    background: var(--stone-50);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
/* When a form wraps the modal contents, make it a flex container too */
.modal > form {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 90vh;
    margin: 0;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--stone-50);
    padding: 24px;
}
.login-wrap::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 15% 20%, rgba(4, 120, 87, 0.08), transparent 40%),
        radial-gradient(circle at 85% 75%, rgba(244, 63, 94, 0.04), transparent 40%);
    pointer-events: none;
}
.login-card {
    background: #fff;
    border: 1px solid var(--stone-200);
    border-radius: 20px;
    padding: 40px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-md);
    position: relative;
}
.login-card .logo-mark { width: 48px; height: 48px; font-size: 24px; }
.login-card .logo-mark:has(img) {
    width: 180px;
    height: 56px;
    border-radius: 8px;
}
.login-card .logo-mark img {
    padding: 4px;
}
.login-card h1 {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
    color: var(--stone-900);
    margin-top: 24px;
}
.login-card p { color: var(--stone-500); margin-top: 4px; }

/* ============================================================
   PRINT / PDF VIEW
   ============================================================ */
.print-page {
    background: #fff;
    max-width: 820px;
    margin: 32px auto;
    padding: 48px 56px;
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    color: var(--stone-900);
    min-height: 1100px;
}
/* Defensive: ensure logos never overflow even if image fails to load */
.print-page img {
    max-width: 100%;
    height: auto;
}
.print-header img {
    object-fit: contain;
}
.print-actions {
    max-width: 820px;
    margin: 0 auto 16px;
    padding: 12px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--stone-900);
}
.print-header .brand {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 700;
    color: var(--stone-900);
    line-height: 1.1;
}
.print-header .brand .tag {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--stone-500);
    margin-top: 6px;
    font-family: var(--font-body);
    font-weight: 500;
}
.print-header .doc-title {
    text-align: right;
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
    color: var(--emerald-700);
}
.print-header .doc-meta {
    text-align: right;
    font-size: 12px;
    color: var(--stone-600);
    margin-top: 4px;
    font-family: var(--font-mono);
}

.print-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}
.print-meta-grid .col h4 {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--stone-500);
    font-weight: 600;
    margin-bottom: 8px;
}
.print-meta-grid .col .name {
    font-size: 16px;
    font-weight: 600;
    color: var(--stone-900);
    margin-bottom: 4px;
}
.print-meta-grid .col .detail {
    font-size: 13px;
    color: var(--stone-600);
    line-height: 1.6;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}
.print-table th {
    background: var(--stone-900);
    color: #fff;
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}
.print-table th.num { text-align: right; }
.print-table td {
    padding: 12px;
    border-bottom: 1px solid var(--stone-200);
    font-size: 13px;
    color: var(--stone-800);
}
.print-table td.num {
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 600;
}

.print-totals {
    width: 320px;
    margin-left: auto;
    margin-bottom: 32px;
}
.print-totals .row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
}
.print-totals .row.total {
    border-top: 2px solid var(--stone-900);
    padding-top: 12px;
    margin-top: 4px;
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    color: var(--stone-900);
}

.print-footer {
    border-top: 1px solid var(--stone-200);
    padding-top: 20px;
    font-size: 11px;
    color: var(--stone-500);
    line-height: 1.6;
}

.print-stamp {
    display: inline-block;
    padding: 8px 16px;
    border: 2px solid var(--emerald-700);
    color: var(--emerald-700);
    border-radius: 8px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    transform: rotate(-4deg);
}

@media print {
    body { background: #fff; }
    .sidebar, .topbar, .print-actions, .no-print { display: none !important; }
    .main { overflow: visible !important; }
    .content { padding: 0; max-width: 100%; }
    .print-page { box-shadow: none; margin: 0; padding: 24px; max-width: 100%; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.text-stone-500 { color: var(--stone-500); }
.text-stone-600 { color: var(--stone-600); }
.text-stone-700 { color: var(--stone-700); }
.text-stone-900 { color: var(--stone-900); }
.text-emerald-700 { color: var(--emerald-700); }
.text-rose-600 { color: var(--rose-600); }
.text-amber-700 { color: var(--amber-700); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.divider { height: 1px; background: var(--stone-100); margin: 12px 0; }
.no-wrap { white-space: nowrap; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--stone-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--stone-400); }

/* ============================================================
   PROGRESS / METRICS
   ============================================================ */
.progress {
    height: 8px;
    background: var(--stone-100);
    border-radius: 4px;
    overflow: hidden;
}
.progress-thin { height: 6px; }
.progress > div { height: 100%; transition: width 0.3s; }
.progress .seg-emerald { background: var(--emerald-700); }
.progress .seg-amber { background: var(--amber-500); }
.progress .seg-rose { background: var(--rose-500); }
.progress .seg-stone { background: var(--stone-300); }

/* Search bar */
.search-bar {
    background: #fff;
    border: 1px solid var(--stone-200);
    padding: 12px 16px;
    border-radius: var(--radius);
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search-bar .input { flex: 1; min-width: 200px; }
.search-bar .select { width: auto; min-width: 140px; }

/* Confirmation hover */
.danger-confirm {
    position: relative;
}

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-5 { grid-template-columns: repeat(2, 1fr); }
    .col-span-2 { grid-column: span 1; }
}
@media (max-width: 768px) {
    .sidebar { width: 64px; }
    .sidebar .logo-text, .nav-item span, .user-card .info, .nav-section-title,
    .sidebar-controls, .nav-group-label, .nav-group-chevron, .btn-create span,
    .nav-group-chevron-btn { display: none; }
    .nav-group.collapsed .nav-group-items { max-height: 1500px; }
    .nav-group-toggle, .nav-group-toggle-link { padding: 4px; pointer-events: none; }
    .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .topbar { padding: 12px 16px; }
}

/* ============================================================
   DARK MODE
   ============================================================ */
body.dark-mode {
    background: #0f172a;
    color: #cbd5e1;
}
body.dark-mode .sidebar,
body.dark-mode .topbar,
body.dark-mode .card,
body.dark-mode .kpi-card,
body.dark-mode .modal,
body.dark-mode .data thead,
body.dark-mode .search-bar {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
body.dark-mode .data {
    background: #1e293b;
    color: #e2e8f0;
}
body.dark-mode .data td,
body.dark-mode .data th {
    border-color: #334155;
    color: #e2e8f0;
}
body.dark-mode .data thead th {
    background: #0f172a;
    color: #94a3b8;
}
body.dark-mode .data tbody tr:hover {
    background: #334155;
}
body.dark-mode .input,
body.dark-mode .select {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}
body.dark-mode .input:focus,
body.dark-mode .select:focus {
    border-color: var(--sky-400);
    background: #1e293b;
}
body.dark-mode .modal-overlay {
    background: rgba(0,0,0,0.7);
}
body.dark-mode .nav-section-title,
body.dark-mode .eyebrow {
    color: #94a3b8;
}
body.dark-mode .nav-group-toggle {
    color: #94a3b8;
}
body.dark-mode .nav-group-toggle:hover {
    color: #e2e8f0;
}
body.dark-mode .nav-group-chevron { color: #64748b; }
body.dark-mode .nav-group-icon-link {
    color: #94a3b8;
}
body.dark-mode .nav-group-icon-link:hover {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
}
body.dark-mode .sidebar-controls {
    border-bottom-color: #334155;
}
body.dark-mode .nav-search {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
body.dark-mode .nav-search:focus {
    background: #0f172a;
    border-color: var(--sky-500);
}
body.dark-mode .nav-control-buttons button {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}
body.dark-mode .nav-control-buttons button:hover {
    background: #334155;
    color: #e2e8f0;
}
body.dark-mode .text-stone-900 { color: #f1f5f9; }
body.dark-mode .text-stone-800 { color: #e2e8f0; }
body.dark-mode .text-stone-700 { color: #cbd5e1; }
body.dark-mode .text-stone-600 { color: #94a3b8; }
body.dark-mode .text-stone-500 { color: #64748b; }
body.dark-mode .text-stone-400 { color: #64748b; }
body.dark-mode .display-2,
body.dark-mode .kpi-value,
body.dark-mode .section-title,
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4 {
    color: #f8fafc;
}
body.dark-mode .nav-item {
    color: #94a3b8;
}
body.dark-mode .nav-item:hover {
    background: #334155;
    color: #e2e8f0;
}
body.dark-mode .nav-item.active {
    background: var(--sky-700);
    color: #fff;
}
body.dark-mode .btn-ghost {
    color: #cbd5e1;
}
body.dark-mode .btn-ghost:hover {
    background: #334155;
}
body.dark-mode .btn-secondary {
    background: #334155;
    color: #e2e8f0;
    border-color: #475569;
}
body.dark-mode .alert-info {
    background: #1e3a5f;
    border-color: #1e40af;
    color: #dbeafe;
}
body.dark-mode .alert-success {
    background: #064e3b;
    border-color: #047857;
    color: #d1fae5;
}
body.dark-mode .alert-error {
    background: #7f1d1d;
    border-color: #b91c1c;
    color: #fee2e2;
}
body.dark-mode pre {
    background: #0f172a !important;
    color: #cbd5e1;
}
body.dark-mode .table-wrap,
body.dark-mode tfoot tr,
body.dark-mode tbody tr {
    background: #1e293b;
}
body.dark-mode .text-stone-900,
body.dark-mode .cell-strong {
    color: #f1f5f9;
}
body.dark-mode .badge-paid { background: #064e3b; color: #6ee7b7; }
body.dark-mode .badge-pending { background: #78350f; color: #fcd34d; }
body.dark-mode .badge-partial { background: #1e3a8a; color: #93c5fd; }
body.dark-mode .badge-cancelled { background: #4c0519; color: #fca5a5; }

/* ============================================================
   MOBILE RESPONSIVE — Enhanced
   ============================================================ */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 8px;
    margin-right: 8px;
}

@media (max-width: 768px) {
    .mobile-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar - slide in from left */
    .sidebar {
        position: fixed !important;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px !important;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.15);
    }
    .sidebar.mobile-open {
        left: 0;
    }
    .sidebar .logo-text,
    .nav-item span,
    .user-card .info,
    .nav-section-title,
    .sidebar-controls,
    .nav-group-label,
    .nav-group-chevron,
    .btn-create span {
        display: block !important;
    }
    .sidebar.mobile-open .sidebar-controls { display: block !important; }
    .sidebar.mobile-open .nav-control-buttons { display: flex !important; }
    .sidebar.mobile-open .nav-search-wrap { display: block !important; }
    .sidebar.mobile-open .nav-group-toggle {
        padding: 9px 16px 5px !important;
        pointer-events: auto;
        display: flex !important;
    }
    .nav-item {
        padding: 12px 16px !important;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    .sidebar.mobile-open + .main .sidebar-overlay,
    .sidebar-overlay.active {
        display: block;
    }

    /* Main content takes full width */
    .main {
        margin-left: 0 !important;
    }
    .content {
        padding: 12px !important;
    }
    .topbar {
        padding: 10px 12px !important;
    }
    .topbar h1 {
        font-size: 18px !important;
    }

    /* Tables scroll horizontally */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modal: full screen on mobile */
    .modal {
        max-width: 100% !important;
        margin: 0 !important;
        max-height: 100vh !important;
        height: 100%;
        border-radius: 0 !important;
    }
    .modal-overlay {
        padding: 0 !important;
    }

    /* KPI cards stack */
    .grid-2, .grid-3, .grid-4, .grid-5 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Buttons */
    .btn {
        padding: 10px 14px !important;
    }
    .btn-sm {
        padding: 8px 12px !important;
        font-size: 13px;
    }

    /* Search bar */
    .search-bar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px;
    }
    .search-bar > div {
        margin: 0 !important;
        width: 100%;
    }
    .search-bar select,
    .search-bar input {
        width: 100% !important;
    }

    /* Header card */
    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }

    /* Form grids → single column */
    .form-grid,
    .form-grid-3 {
        grid-template-columns: 1fr !important;
    }
    .col-span-2,
    .col-span-3 {
        grid-column: span 1 !important;
    }

    /* Print actions */
    .print-actions {
        flex-direction: column;
        gap: 8px;
    }
}

/* Theme toggle button */
.theme-toggle {
    background: none;
    border: 1px solid var(--stone-300);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--stone-700);
    transition: all 0.2s;
}
.theme-toggle:hover {
    background: var(--stone-100);
    border-color: var(--sky-400);
}
body.dark-mode .theme-toggle {
    border-color: #475569;
    color: #cbd5e1;
}
body.dark-mode .theme-toggle:hover {
    background: #334155;
    border-color: var(--sky-400);
}
