:root {
    /* --- Palette Dark --- */
    --bg-dark:        #0d0d0d;
    --surface-dark:   #181818;
    --card-dark:      #1f1f1f;
    --border-dark:    #2d2d2d;
    --text-dark:      #f0f0f0;
    --text-muted-dark:#9a9a9a;
    --accent-dark:    #ffffff;
    --accent2-dark:   #d0d0d0;
    --danger-dark:    #ff6b6b;
    --warning-dark:   #ffd166;
    --success-dark:   #6bcb77;
    --info-dark:      #a0c4ff;

    /* --- Palette Light --- */
    --bg-light:        #f5f5f5;
    --surface-light:   #ffffff;
    --card-light:      #ffffff;
    --border-light:    #e0e0e0;
    --text-light:      #111111;
    --text-muted-light:#6b6b6b;
    --accent-light:    #111111;
    --accent2-light:   #444444;
    --danger-light:    #c0392b;
    --warning-light:   #d4851d;
    --success-light:   #1e8449;
    --info-light:      #1a5276;

    /* --- Defaults (dark) --- */
    --bg:        var(--bg-dark);
    --surface:   var(--surface-dark);
    --card:      var(--card-dark);
    --border:    var(--border-dark);
    --text:      var(--text-dark);
    --muted:     var(--text-muted-dark);
    --accent:    var(--accent-dark);
    --accent2:   var(--accent2-dark);
    --danger:    var(--danger-dark);
    --warning:   var(--warning-dark);
    --success:   var(--success-dark);
    --info:      var(--info-dark);

    --radius:   10px;
    --radius-sm: 6px;
    --shadow:   0 4px 24px rgba(0,0,0,0.5);
    --shadow-sm:0 2px 8px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
    --font: 'Inter', sans-serif;
    --logo-filter: none;
}

[data-theme="light"] {
    --bg:      var(--bg-light);
    --surface: var(--surface-light);
    --card:    var(--card-light);
    --border:  var(--border-light);
    --text:    var(--text-light);
    --muted:   var(--text-muted-light);
    --accent:  var(--accent-light);
    --accent2: var(--accent2-light);
    --danger:  var(--danger-light);
    --warning: var(--warning-light);
    --success: var(--success-light);
    --info:    var(--info-light);
    --shadow:  0 4px 24px rgba(0,0,0,0.08);
    --shadow-sm:0 2px 8px rgba(0,0,0,0.06);
    --logo-filter: brightness(0);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    line-height: 1.6;
    font-size: 14px;
}

/* ─── Links ─── */
a { color: var(--accent); text-decoration: none; transition: opacity var(--transition); }
a:hover { opacity: 0.75; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ─── Layout ─── */
.portal-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── Navbar ─── */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    gap: 12px;
}
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-shrink: 1;
}
.navbar-brand img {
    height: 34px;
    width: auto;
    flex-shrink: 0;
    filter: var(--logo-filter, none);
}

[data-theme="dark"]  .navbar-brand img { filter: none; }
[data-theme="light"] .navbar-brand img { filter: brightness(0) !important; }

.navbar-brand .brand-text {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.navbar-brand .brand-sub {
    font-size: 10px;
    color: var(--muted);
    font-weight: 400;
    display: block;
}
.navbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* ─── Mobile Navbar ─── */
@media (max-width: 640px) {
    .navbar { padding: 0 14px; height: 56px; }
    .navbar-brand img { height: 28px; }
    .navbar-brand .brand-text { font-size: 12px; }
    .navbar-brand .brand-sub { display: none; }
    /* hide brand text div entirely on mobile */
    .navbar-brand > div { display: none; }
    /* user pill: avatar only */
    .user-pill { padding: 4px; }
    .user-pill .user-name,
    .user-pill .user-email { display: none; }
    /* logout icon only */
    .btn-logout { padding: 6px 8px; }
    .btn-logout .logout-label { display: none; }
    .navbar-right { gap: 8px; }
}
.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 14px 4px 4px;
    font-size: 12px;
    color: var(--text);
}
.user-pill .avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
}
.user-pill .user-name { font-weight: 600; }
.user-pill .user-email { color: var(--muted); font-size: 10px; display: block; line-height: 1; }

/* ─── Theme Toggle ─── */
.theme-toggle {
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.theme-toggle:hover { background: var(--border); }
.theme-toggle svg { width: 16px; height: 16px; }
.icon-moon { display: block; }
.icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: block; }

/* ─── Logout ─── */
.btn-logout {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex; align-items: center; gap: 6px;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }
.btn-logout svg { width: 14px; height: 14px; }

/* ─── Page Content ─── */
.page-content { flex: 1; padding: 28px 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
@media (max-width: 640px) {
    .page-content { padding: 16px 12px 88px; }
}

/* ─── Cards ─── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: background var(--transition), border-color var(--transition);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.card-body { padding: 20px; }

/* ─── Stat Cards ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 16px;
    }
    /* Total Purchases spans full width as hero stat */
    .stats-grid .stat-card.total { grid-column: 1 / -1; }
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 16px;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
@media (max-width: 640px) {
    .stat-card { padding: 14px 12px; }
    .stat-card:hover { transform: none; }
    .stat-value { font-size: 18px !important; }
}
.stat-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--stat-color, var(--accent));
    border-radius: 3px 0 0 3px;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 8px;
}
.stat-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--stat-color, var(--text));
    letter-spacing: -0.5px;
    line-height: 1;
}
.stat-card.total  { --stat-color: var(--text); }
.stat-card.pending { --stat-color: var(--danger); }
.stat-card.partial { --stat-color: var(--warning); }
.stat-card.paid    { --stat-color: var(--success); }
.stat-card.completed { --stat-color: var(--info); }

/* ─── Two-col layout ─── */
.report-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 1024px) {
    .report-grid { grid-template-columns: 1fr; }
}

/* ─── Table Styles ─── */
.table-wrap {
    overflow-x: auto;
    max-height: 560px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ─── Mobile Card List (replaces table on ≤640px) ─── */
@media (max-width: 640px) {
    .table-wrap { max-height: none; overflow: visible; }
    #sales-table thead, #sales-table tfoot { display: none !important; }
    #sales-table, #sales-table tbody { display: block; }
    /* Each invoice row becomes a card */
    tr.invoice-row {
        display: block;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--card);
        margin: 0 0 10px;
        padding: 14px 14px 12px;
        box-shadow: var(--shadow-sm);
        cursor: pointer;
        transition: background var(--transition), box-shadow var(--transition);
    }
    tr.invoice-row > td { display: none !important; } /* raw tds hidden; mobile card HTML is injected */
    tr.invoice-row:active { background: var(--surface) !important; }
    tr.invoice-row.is-open { background: var(--surface) !important; box-shadow: var(--shadow); }
    /* Mobile card inner */
    .mobile-card-inner { display: flex; flex-direction: column; gap: 10px; }
    .mc-row1 { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
    .mc-invoice { font-size: 13px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
    .mc-date { font-size: 11px; color: var(--muted); margin-top: 2px; }
    .mc-type { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
    .mc-row2 {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
        background: var(--bg);
        border-radius: var(--radius-sm);
        padding: 10px;
        border: 1px solid var(--border);
    }
    .mc-amount-block { display: flex; flex-direction: column; gap: 2px; }
    .mc-amount-label { font-size: 9px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
    .mc-amount-value { font-size: 13px; font-weight: 700; }
    .mc-amount-value.mc-balance { color: var(--danger); }
    .mc-amount-value.zero { color: var(--muted); }
    .mc-row3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .mc-chevron { color: var(--muted); display: inline-flex; transition: transform 0.25s cubic-bezier(0.4,0,0.2,1); }
    .mc-chevron svg { width: 16px; height: 16px; }
    tr.invoice-row.is-open .mc-chevron { transform: rotate(90deg); }
    /* accordion detail in mobile card mode */
    tr.accordion-detail-row { display: block; margin: -8px 0 10px; }
    tr.accordion-detail-row > td { display: block !important; padding: 0 !important; border: none !important; }
    .accordion-detail-container { margin: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
    /* hide inner padding on mobile */
    #sales-table .accordion-inner > div { padding: 0 4px 8px !important; }
}
table { width: 100%; border-collapse: collapse; }
thead {
    position: sticky; top: 0; z-index: 10;
    background: var(--surface);
}
th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
th .sort-icon {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0.3;
}
th[data-sort]:hover .sort-icon,
th.sort-active .sort-icon { opacity: 1; }
.sort-icon::before,
.sort-icon::after {
    content: '';
    display: block;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}
.sort-icon::before { border-bottom: 4px solid var(--text); }
.sort-icon::after  { border-top:    4px solid var(--text); }
th.sort-asc  .sort-icon::before { opacity: 1; }
th.sort-asc  .sort-icon::after  { opacity: 0.2; }
th.sort-desc .sort-icon::before { opacity: 0.2; }
th.sort-desc .sort-icon::after  { opacity: 1; }
th.sort-asc, th.sort-desc { color: var(--text); }

td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] tbody tr:hover { background: rgba(0,0,0,0.03); }

tfoot td {
    padding: 10px 14px;
    font-weight: 700;
    font-size: 13px;
    background: var(--surface);
    border-top: 2px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* ─── Accordion Styles (Ultra-Smooth CSS Grid Animation) ─── */
.invoice-row {
    cursor: pointer;
    user-select: none;
}
.accordion-toggle-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease, background 0.2s ease;
}
.accordion-toggle-btn:hover {
    color: var(--text);
    background: rgba(255,255,255,0.08);
}
[data-theme="light"] .accordion-toggle-btn:hover {
    background: rgba(0,0,0,0.06);
}
.accordion-toggle-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.invoice-row.is-open .accordion-toggle-btn svg {
    transform: rotate(90deg);
}
.invoice-row.is-open {
    background: rgba(255,255,255,0.05) !important;
}
[data-theme="light"] .invoice-row.is-open {
    background: rgba(0,0,0,0.04) !important;
}

.accordion-detail-row {
    background: var(--surface) !important;
}
.accordion-detail-row > td {
    padding: 0 !important;
    border-bottom: 1px solid var(--border);
}
.accordion-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    opacity: 0;
}
.accordion-wrapper.is-open {
    grid-template-rows: 1fr;
    opacity: 1;
}
.accordion-inner {
    overflow: hidden;
}
.accordion-detail-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-top: 4px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}
[data-theme="light"] .accordion-detail-container {
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
}

.itemized-subtable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
}
.itemized-subtable th {
    padding: 6px 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: transparent;
}
.itemized-subtable td {
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text);
    border-bottom: 1px dashed var(--border);
}
.itemized-subtable tr:last-child td {
    border-bottom: none;
}
.itemized-subtable tbody tr:hover {
    background: rgba(255,255,255,0.02);
}
[data-theme="light"] .itemized-subtable tbody tr:hover {
    background: rgba(0,0,0,0.02);
}
.accordion-loading {
    padding: 16px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.spinner-icon {
    animation: spin 1s linear infinite;
    width: 16px; height: 16px;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ─── Status Badges ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid currentColor;
}
.badge-pending  { color: var(--danger);  background: rgba(255,107,107,0.12); }
.badge-partial  { color: var(--warning); background: rgba(255,209,102,0.12); }
.badge-paid     { color: var(--success); background: rgba(107,203,119,0.12); }
.badge-completed{ color: var(--info);    background: rgba(160,196,255,0.12); }
.badge-draft    { color: var(--muted);   background: rgba(150,150,150,0.12); }
.badge-cancelled{ color: var(--muted);   background: rgba(150,150,150,0.12); }

[data-theme="light"] .badge-pending  { background: #fde8e8; }
[data-theme="light"] .badge-partial  { background: #fef3cd; }
[data-theme="light"] .badge-paid     { background: #d4edda; }
[data-theme="light"] .badge-completed{ background: #cce5ff; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}
.btn-primary:hover { opacity: 0.85; }
.btn-secondary {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 11px; }

/* ─── Filter Bar ─── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
@media (max-width: 640px) {
    .filter-bar { flex-direction: column; align-items: stretch; padding: 10px 12px; gap: 8px; }
    .filter-bar-dates { display: flex; gap: 8px; }
    .filter-bar-dates .filter-input { flex: 1; min-width: 0; }
    /* prevent iOS font zoom */
    .filter-input { font-size: 16px !important; padding: 9px 10px; }
    /* chips: horizontal scroll, no wrap */
    .filter-chips { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
    .filter-chips::-webkit-scrollbar { display: none; }
    .chip { flex-shrink: 0; padding: 7px 14px; font-size: 11px; }
    /* clear button row */
    .filter-bar-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
}
.filter-input {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 6px 10px;
    font-size: 12px;
    font-family: var(--font);
    outline: none;
    transition: border-color var(--transition);
}
.filter-input:focus { border-color: var(--text); }
.filter-input::placeholder { color: var(--muted); }

/* Status filter chips */
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid var(--border);
    color: var(--muted);
    background: var(--card);
    cursor: pointer;
    transition: all var(--transition);
}
.chip:hover { border-color: var(--text); color: var(--text); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ─── Checkbox ─── */
input[type="checkbox"] {
    width: 14px; height: 14px;
    accent-color: var(--text);
    cursor: pointer;
}
@media (max-width: 640px) {
    input[type="checkbox"] { width: 18px; height: 18px; }
    /* hide select-all row on mobile */
    .no-print label[for="select-all-cb"] { display: none; }
}

/* ─── Product History Panel ─── */
.product-panel { display: flex; flex-direction: column; }
.product-search-box {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.product-search-input {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 8px 12px;
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: border-color var(--transition);
}
.product-search-input:focus { border-color: var(--text); }
.product-search-input::placeholder { color: var(--muted); }
.product-list { overflow-y: auto; max-height: 480px; }
.product-row {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px;
    align-items: center;
}
.product-row:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] .product-row:hover { background: rgba(0,0,0,0.03); }
.product-row:last-child { border-bottom: none; }
.product-name { font-size: 12px; font-weight: 600; color: var(--text); }
.product-meta { font-size: 10px; color: var(--muted); }
.product-price { font-size: 13px; font-weight: 700; color: var(--text); text-align: right; }
.product-invoice { font-size: 10px; color: var(--muted); text-align: right; }

/* ─── Auth Pages (Login/Signup) ─── */
.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}
.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
}
.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}
.auth-logo img {
    height: 40px;
    width: auto;
    filter: none;
}
[data-theme="light"] .auth-logo img { filter: none; }

.auth-logo .company-name {
    display: block;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text);
    margin-top: 8px;
}
.auth-logo .portal-label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.04em;
    margin-top: 2px;
}
.auth-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 6px;
    text-align: center;
}
.auth-subtitle {
    font-size: 13px;
    color: var(--muted);
    text-align: center;
    margin-bottom: 28px;
}
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}
.form-control {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
    border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}
[data-theme="light"] .form-control:focus {
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.form-control::placeholder { color: var(--muted); }
.form-control[readonly] {
    background: var(--border);
    color: var(--muted);
    cursor: not-allowed;
}

.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-error   { background: rgba(255,107,107,0.1); border-color: rgba(255,107,107,0.3); color: var(--danger); }
.alert-success { background: rgba(107,203,119,0.1); border-color: rgba(107,203,119,0.3); color: var(--success); }
.alert-info    { background: rgba(160,196,255,0.1); border-color: rgba(160,196,255,0.3); color: var(--info); }
[data-theme="light"] .alert-error   { background: #fde8e8; border-color: #f5c6cb; color: var(--danger); }
[data-theme="light"] .alert-success { background: #d4edda; border-color: #c3e6cb; color: var(--success); }
[data-theme="light"] .alert-info    { background: #cce5ff; border-color: #b8daff; color: var(--info); }

.divider {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    margin: 16px 0;
    position: relative;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 38%;
    height: 1px;
    background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

/* ─── Page header ─── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.page-header p  { font-size: 13px; color: var(--muted); margin-top: 3px; }
@media (max-width: 640px) {
    .page-header { margin-bottom: 16px; gap: 10px; }
    .page-header h1 { font-size: 18px; }
    .page-header p  { font-size: 12px; }
}

/* ─── Inline actions row ─── */
.actions-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ─── Empty state ─── */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--muted);
}
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 13px; }

/* ─── Modal ─── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 500px;
    animation: slideUp 0.2s ease;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
@keyframes slideUp {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
/* ─── Mobile: bottom-sheet modal ─── */
@media (max-width: 640px) {
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .modal {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 88vh;
        animation: slideUpSheet 0.32s cubic-bezier(0.32,0.72,0,1);
        border-bottom: none;
    }
    @keyframes slideUpSheet {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
    /* drag handle */
    .modal::before {
        content: '';
        display: block;
        width: 40px; height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 0;
        flex-shrink: 0;
    }
    /* allow body to scroll */
    .modal-body { -webkit-overflow-scrolling: touch; }
    /* payment table: horizontal scroll */
    #payments-modal-content > div:last-child { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #payments-modal-content table { min-width: 460px; }
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--text); }
.modal-close {
    background: transparent; border: none;
    color: var(--muted); cursor: pointer;
    font-size: 20px; line-height: 1;
    padding: 0; transition: color var(--transition);
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
}
.modal-close:hover { color: var(--danger); background: rgba(255,107,107,0.1); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

/* ─── Password strength ─── */
.pw-strength { height: 3px; border-radius: 2px; margin-top: 6px; transition: all 0.3s; background: var(--border); }
.pw-strength.weak   { background: var(--danger);  width: 33%; }
.pw-strength.medium { background: var(--warning); width: 66%; }
.pw-strength.strong { background: var(--success); width: 100%; }

/* ─── Theme toggle in auth page ─── */
.auth-theme-toggle {
    position: absolute;
    top: 16px; right: 16px;
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
}
.auth-theme-toggle:hover { background: var(--border); }
.auth-theme-toggle svg { width: 16px; height: 16px; }
.auth-wrapper { position: relative; }

/* ─── Balance text colors ─── */
.text-danger  { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-muted   { color: var(--muted) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.font-bold    { font-weight: 700; }
.font-mono    { font-family: 'JetBrains Mono', 'Courier New', monospace; }

/* ═══════════════════════════════════════
   MOBILE SUMMARY FOOTER BAR
   Sticky bar showing live running totals
═══════════════════════════════════════ */
.mobile-summary-bar { display: none; }
@media (max-width: 640px) {
    .mobile-summary-bar {
        display: flex;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: 10px 12px;
        z-index: 50;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.28);
        gap: 4px;
    }
    [data-theme="light"] .mobile-summary-bar { box-shadow: 0 -4px 20px rgba(0,0,0,0.08); }
    .msb-item { display: flex; flex-direction: column; align-items: center; gap: 1px; flex: 1; min-width: 0; }
    .msb-label { font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
    .msb-value { font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .msb-divider { width: 1px; height: 32px; background: var(--border); flex-shrink: 0; }
    .msb-total   { color: var(--text); }
    .msb-paid    { color: var(--success); }
    .msb-balance { color: var(--danger); }
    .msb-balance.zero { color: var(--muted); }
    /* actions bar: smaller on mobile */
    .card-header.no-print { padding: 8px 12px !important; }
    .actions-bar .btn-sm .btn-label { display: none; }
    .actions-bar .btn-sm { padding: 7px 10px; }
}

/* ─── Print ─── */
@media print {
    :root { --bg: #fff; --text: #000; --surface: #fff; --card: #fff; --border: #ccc; --muted: #555; }
    .no-print, .navbar, .filter-bar, .actions-bar, .theme-toggle, .btn-logout,
    .mobile-summary-bar { display: none !important; }
    body { background: #fff; }
    .card { border: none; box-shadow: none; }
    table { font-size: 11px; }
    thead { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    th, td { border: 1px solid #ccc; padding: 4px 8px; }
    .badge { border: 1px solid #999; background: transparent !important; color: #000 !important; }
    a { color: #000; }
    .product-panel, .report-grid { display: block; }
    .product-panel { page-break-before: always; }
    .stat-card::before { display: none; }
    .stats-grid { grid-template-columns: repeat(5, 1fr); }
    tfoot { display: table-row-group; }
    .table-wrap { max-height: none; overflow: visible; }
    /* restore table layout for print */
    #sales-table, #sales-table tbody { display: table !important; }
    #sales-table thead, #sales-table tfoot { display: table-row-group !important; }
    tr.invoice-row { display: table-row !important; border: none !important; box-shadow: none !important; margin: 0 !important; padding: 0 !important; }
    tr.invoice-row > td { display: table-cell !important; }
    .mobile-card-inner { display: none !important; }
}
