/* ============================================================
   EMPEROR WEB — App design system (dashboards, portal, login)
   Matches the marketing site: deep navy + cyan, glass morphism
   ============================================================ */

:root {
    --bg: #0a0f2c;
    --bg-dark: #05081a;
    --accent: #00bfff;
    --accent-light: #4dd4ff;
    --accent-dark: #0099cc;
    --primary: var(--accent);
    --primary-hover: var(--accent-dark);
    --text: #f4f7fb;
    --text-muted: #8b96b8;
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-bg-strong: rgba(13, 20, 48, 0.85);
    --glass-border: rgba(255, 255, 255, 0.09);
    --card-hover: rgba(255, 255, 255, 0.07);
    --success: #10b981;
    --pending: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
    --radius-sm: 9px;
    --font-heading: 'Outfit', 'Inter', sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --modal-solid: #0e1533;
}

/* Light theme: same tokens, re-pointed. Applied by a data-theme attribute the
   page sets before first paint from localStorage (see the head script). */
:root[data-theme="light"] {
    --bg: #f4f6fb;
    --bg-dark: #ffffff;
    --accent: #0a8ed6;
    --accent-light: #0369a1;
    --accent-dark: #075985;
    --text: #0f172a;
    --text-muted: #5b6478;
    --glass-bg: rgba(255, 255, 255, 0.86);
    --glass-bg-strong: rgba(255, 255, 255, 0.97);
    --glass-border: rgba(15, 23, 42, 0.09);
    --card-hover: rgba(15, 23, 42, 0.03);
    --shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
    --modal-solid: #ffffff;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(900px 500px at 85% -10%, rgba(0, 191, 255, 0.13), transparent 60%),
        radial-gradient(700px 500px at -10% 110%, rgba(77, 84, 255, 0.10), transparent 60%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-body);
    margin: 0;
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 600; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ---------- App shell ---------- */

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

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: rgba(5, 8, 26, 0.7);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid var(--glass-border);
    padding: 1.75rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0 0.6rem;
    text-decoration: none;
    color: var(--text);
}

.sidebar-brand img { height: 34px; }

.sidebar-brand span {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.14em;
}

.sidebar nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.78rem 0.9rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.93rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    background: none;
    font-family: var(--font-body);
}

.nav-item i { width: 20px; text-align: center; font-size: 1rem; }

.nav-item:hover { color: var(--text); background: var(--glass-bg); }

.nav-item.active {
    color: var(--text);
    background: linear-gradient(135deg, rgba(0, 191, 255, 0.18), rgba(0, 191, 255, 0.06));
    border-color: rgba(0, 191, 255, 0.35);
}

.nav-item.active i { color: var(--accent); }

.sidebar-footer { border-top: 1px solid var(--glass-border); padding-top: 1.1rem; }

.user-chip { display: flex; align-items: center; gap: 0.7rem; padding: 0 0.4rem; }

.user-chip .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #04121c;
    flex-shrink: 0;
    text-transform: uppercase;
}

.user-chip .who { min-width: 0; }

.user-chip .who p {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-chip .who button {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);   /* leaving is routine, not destructive */
    font-size: 0.78rem;
    cursor: pointer;
    font-family: var(--font-body);
}

.main {
    flex: 1;
    padding: 2.2rem 2.6rem 4rem;
    min-width: 0;
    animation: fadeIn 0.5s ease-out;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.page-header h1 { margin: 0; font-size: 1.7rem; }
.page-header p { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.9rem; }
.page-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; }

/* ---------- Cards ---------- */

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.6rem;
    box-shadow: var(--shadow);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: 1.2rem;
    margin-bottom: 1.6rem;
}

.stat-card {
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.stat-card:hover { transform: translateY(-3px); border-color: rgba(0, 191, 255, 0.3); }

.stat-card .stat-icon {
    position: absolute;
    top: 1.2rem;
    right: 1.2rem;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(0, 191, 255, 0.12);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 0.55rem;
}

.stat-card .stat-value { font-size: 1.85rem; font-weight: 700; margin: 0; font-family: var(--font-heading); }
.stat-card .stat-sub { color: var(--text-muted); font-size: 0.8rem; margin: 0.4rem 0 0; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.2rem;
}

.card-header h3 { margin: 0; font-size: 1.08rem; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.68rem 1.3rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-family: var(--font-body);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #03111f;
    box-shadow: 0 6px 22px rgba(0, 191, 255, 0.28);
}

.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 9px 28px rgba(0, 191, 255, 0.4); }

.btn-secondary {
    background: var(--glass-bg);
    color: var(--text);
    border-color: var(--glass-border);
}

.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-light); }

.btn-ghost { background: none; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--glass-bg); }

.btn-danger { background: rgba(239, 68, 68, 0.12); color: #f87171; border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); }

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; border-radius: 8px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }

.table th {
    text-align: left;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}

.table td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.875rem;
    vertical-align: middle;
}

.table tbody tr { transition: background 0.15s ease; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.table tbody tr:last-child td { border-bottom: none; }

.table .mono { font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 0.28rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    border: 1px solid transparent;
}

.badge-paid { background: rgba(16, 185, 129, 0.12); color: #34d399; border-color: rgba(16, 185, 129, 0.3); }
.badge-pending { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
.badge-part-paid { background: rgba(0, 191, 255, 0.12); color: var(--accent-light); border-color: rgba(0, 191, 255, 0.3); }
.badge-failed { background: rgba(239, 68, 68, 0.12); color: #f87171; border-color: rgba(239, 68, 68, 0.3); }
.badge-active { background: rgba(16, 185, 129, 0.12); color: #34d399; border-color: rgba(16, 185, 129, 0.3); }
.badge-inactive { background: rgba(148, 163, 184, 0.12); color: var(--text-muted); border-color: rgba(148, 163, 184, 0.3); }
.badge-draft { background: rgba(148, 163, 184, 0.12); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.3); }
.badge-sent { background: rgba(167, 139, 250, 0.12); color: #c4b5fd; border-color: rgba(167, 139, 250, 0.3); }
.badge-converted { background: rgba(16, 185, 129, 0.12); color: #34d399; border-color: rgba(16, 185, 129, 0.3); }
.badge-cancelled, .badge-void, .badge-expired { background: rgba(239, 68, 68, 0.1); color: #fca5a5; border-color: rgba(239, 68, 68, 0.25); text-decoration: line-through; }
.badge-skipped { background: rgba(148, 163, 184, 0.12); color: var(--text-muted); border-color: rgba(148, 163, 184, 0.3); }

/* ---------- Line-item editor ---------- */

.items-editor { display: flex; flex-direction: column; gap: 0.55rem; margin-bottom: 1rem; }

.item-row { display: grid; grid-template-columns: 1fr 64px 96px 32px; gap: 0.5rem; align-items: center; }

.item-row input {
    padding: 0.55rem 0.7rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.85rem;
    font-family: var(--font-body);
    width: 100%;
}

.item-row input:focus { outline: none; border-color: var(--accent); }

.item-row .remove-item {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0.3rem;
}

.item-row .remove-item:hover { color: var(--danger); }

.totals-preview {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    margin-bottom: 1.1rem;
    font-size: 0.85rem;
}

.totals-preview .row { display: flex; justify-content: space-between; padding: 0.16rem 0; color: var(--text-muted); }
.totals-preview .row.grand { color: var(--text); font-weight: 700; font-size: 1rem; border-top: 1px solid var(--glass-border); margin-top: 0.4rem; padding-top: 0.5rem; }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 1.15rem; }

.form-group label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.72rem 0.9rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92rem;
    font-family: var(--font-body);
    transition: var(--transition);
}

.form-group select option { background: var(--bg-dark); color: var(--text); }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 191, 255, 0.15);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }

.field-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

/* ---------- Filters / segmented control ---------- */

.segmented { display: inline-flex; background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.25rem; gap: 0.25rem; }

.segmented button {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.42rem 0.9rem;
    border-radius: 7px;
    cursor: pointer;
    font-family: var(--font-body);
    transition: var(--transition);
}

.segmented button.active { background: rgba(0, 191, 255, 0.18); color: var(--accent-light); }

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 18, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal.modal-lg { max-width: 860px; }

.pdf-frame {
    width: 100%;
    height: 68vh;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: #fff;
}

.modal {
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: translateY(14px) scale(0.98);
    transition: transform 0.22s ease;
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.3rem 1.5rem 0;
}

.modal-header h3 { margin: 0; font-size: 1.12rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 0.3rem;
    line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 1.2rem 1.5rem 1.5rem; }

/* Sticks to the bottom of a scrolling modal so the submit button is never below the fold. */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    margin: 1.4rem -1.5rem -1.5rem;
    padding: 0.9rem 1.5rem;
    position: sticky;
    bottom: 0;
    background: var(--modal-solid);   /* opaque, so scrolled content never shows through */
    border-top: 1px solid var(--glass-border);
}

/* ---------- Toasts ---------- */

#toast-stack {
    position: fixed;
    bottom: 1.4rem;
    right: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    z-index: 2000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1.15rem;
    font-size: 0.87rem;
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

.toast.success { border-left-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.error i { color: var(--danger); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- Empty / loading states ---------- */

.empty-state {
    text-align: center;
    padding: 2.8rem 1rem;
    color: var(--text-muted);
}

.empty-state i { font-size: 1.9rem; color: rgba(0, 191, 255, 0.45); margin-bottom: 0.7rem; display: block; }
.empty-state p { margin: 0; font-size: 0.9rem; }

.spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(0, 191, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 2rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Plans grid ---------- */

.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1.2rem; }

.plan-card { transition: var(--transition); }
.plan-card:hover { transform: translateY(-3px); border-color: rgba(0, 191, 255, 0.35); }

.plan-card .plan-name { margin: 0 0 0.3rem; font-size: 1.02rem; }
.plan-card .plan-price { font-size: 1.55rem; font-weight: 700; font-family: var(--font-heading); margin: 0; }
.plan-card .plan-price small { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.plan-card .plan-desc { color: var(--text-muted); font-size: 0.83rem; margin: 0.6rem 0 0; }

/* ---------- Auth (login) ---------- */

.auth-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1.2rem;
}

.auth-card { width: 100%; max-width: 410px; padding: 2.4rem; }

.auth-card .auth-logo { text-align: center; margin-bottom: 1.9rem; }
.auth-card .auth-logo img { height: 58px; margin-bottom: 0.9rem; }
.auth-card .auth-logo h1 { margin: 0; font-size: 1.45rem; }
.auth-card .auth-logo p { color: var(--text-muted); margin: 0.45rem 0 0; font-size: 0.9rem; }

.error-message {
    color: #f87171;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.95rem;
    font-size: 0.84rem;
    margin-top: 1rem;
    display: none;
}

/* ---------- Cash-flow chart ---------- */

.chart {
    display: flex;
    align-items: flex-end;
    gap: 1.2rem;
    height: 170px;
    padding: 0.4rem 0.2rem 0;
}

.chart .group {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    min-width: 0;
}

.chart .bars {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    height: 100%;
}

.chart .bar {
    flex: 1;
    /* Cap the width so a wide panel or a sparse window gives bars, not slabs. */
    max-width: 26px;
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: var(--transition);
}

.chart .bar.received { background: linear-gradient(180deg, var(--accent), var(--accent-dark)); }
.chart .bar.billed { background: rgba(255, 255, 255, 0.18); }
.chart .bar:hover { filter: brightness(1.25); }

.chart .label {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.45rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Pagination ---------- */

.pager {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.8rem;
    margin-top: 0.9rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.search-input {
    padding: 0.5rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 9px;
    color: var(--text);
    font-size: 0.85rem;
    font-family: var(--font-body);
    width: 220px;
}

.search-input:focus { outline: none; border-color: var(--accent); }

/* ---------- Settings section labels ---------- */

.section-label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0 0 0.9rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}

.section-label i { color: var(--accent); }

/* ---------- Settings sub-tabs ---------- */

.subtabs {
    display: flex;
    gap: 0.2rem;
    margin-bottom: 1.6rem;
    border-bottom: 1px solid var(--glass-border);
    overflow-x: auto;
    scrollbar-width: none;
}

.subtabs::-webkit-scrollbar { display: none; }

.subtab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: none;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.72rem 1rem;
    cursor: pointer;
    /* Sit the underline on top of the bar's own border, not below it. */
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: var(--transition);
}

.subtab i { font-size: 0.9em; }
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

.subpanel { display: none; }
.subpanel.active { display: block; animation: fadeIn 0.25s ease-out; }

/* Forms read better at a comfortable measure; tables still span the panel. */
.settings-form-card { max-width: 820px; }

/* ---------- Sections (tab panels) ---------- */

.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.35s ease-out; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */

@media (max-width: 920px) {
    .app-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        gap: 1rem;
        padding: 0.9rem 1rem;
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .sidebar-brand span { display: none; }

    .sidebar nav { flex-direction: row; overflow-x: auto; flex: 1; }
    .nav-item { padding: 0.55rem 0.8rem; }
    .nav-item span { display: none; }
    .nav-item i { width: auto; }

    .sidebar-footer { border-top: none; padding-top: 0; margin-left: auto; }
    .user-chip .who { display: none; }

    .main { padding: 1.4rem 1.1rem 3rem; }
    .form-row { grid-template-columns: 1fr; }
}

/* Phone width: a table becomes a stack of cards, every cell captioned by its
   column header (the page copies header text into data-label on each cell). */
@media (max-width: 700px) {
    .table-wrap { overflow-x: visible; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { padding: 0.7rem 0.2rem; border-bottom: 1px solid var(--glass-border); }
    .table tr:last-child { border-bottom: none; }
    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: 0.3rem 0;
        border-bottom: none;
        text-align: right;
    }
    .table td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        text-align: left;
        flex: 0 0 auto;
    }
    .table td[data-label=""]::before, .table td:not([data-label])::before { content: none; }
    .table td[data-label=""], .table td:not([data-label]) { justify-content: flex-end; padding-top: 0.5rem; }
    .table td[style*="text-align:right"] { justify-content: flex-end; }
    .pager { justify-content: center; }
}

/* The hidden attribute must win over any display rule (buttons, flex cards). */
[hidden] { display: none !important; }

/* Long identifiers (client emails) truncate rather than push columns around. */
.table td.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) {
    .table td.ellipsis { max-width: none; white-space: normal; word-break: break-all; }
}

/* ---------- Accessibility ---------- */

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .nav-item:focus-visible, .subtab:focus-visible, .segmented button:focus-visible,
.table th[data-sort]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- Lists ---------- */

.table .mono, .nowrap { white-space: nowrap; }   /* an identifier or an amount never wraps */

.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th[data-sort].asc::after { content: " \2191"; color: var(--accent); }
.table th[data-sort].desc::after { content: " \2193"; color: var(--accent); }

.due-late { color: #f87171; font-weight: 600; white-space: nowrap; }
.due-soon { color: #fbbf24; white-space: nowrap; }

.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.35rem; }
.menu-btn { padding-left: 0.55rem; padding-right: 0.55rem; }

/* The "more" menu is fixed-positioned by the page so a table's overflow never clips it. */
.row-menu {
    position: fixed;
    z-index: 1200;
    min-width: 200px;
    padding: 0.35rem;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}
.row-menu button {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font: inherit;
    font-size: 0.86rem;
    padding: 0.55rem 0.7rem;
    border-radius: 7px;
    cursor: pointer;
}
.row-menu button:hover, .row-menu button:focus-visible { background: var(--glass-bg); outline: none; }
.row-menu button i { width: 16px; text-align: center; color: var(--text-muted); }
.row-menu button.danger, .row-menu button.danger i { color: #f87171; }

/* KPI tiles: the page currency large, any other currency on a quieter line. */
.stat-card .stat-alt { display: block; font-family: var(--font-body); font-size: 0.8rem; font-weight: 500; color: var(--text-muted); margin-top: 0.15rem; }
#chart-currency { display: none; }   /* superseded by the page-level toggle */

.plan-card .plan-meta { color: var(--text-muted); font-size: 0.82rem; margin: 0.45rem 0 0; }

.item-row .it-detail { grid-column: 1 / -1; font-size: 0.82rem; }

.table td.title-col { min-width: 260px; }

/* ---------- Instalment plan editor ---------- */

.inst-head, .inst-row { display: grid; grid-template-columns: 1.25fr 2fr 1fr 1.2fr 32px; gap: 0.5rem; align-items: center; }
.inst-head { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; margin: 0.2rem 0 0.4rem; }
.inst-row input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.86rem;
    font-family: var(--font-body);
}
.inst-row input:focus { outline: none; border-color: var(--accent); }
.inst-row .remove-item { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.inst-row .remove-item:hover { color: var(--danger); }
@media (max-width: 700px) {
    .inst-head { display: none; }
    .inst-row { grid-template-columns: 1fr 1fr 32px; }
    .inst-row .in-trigger { grid-column: 1 / -1; }
}
:root[data-theme="light"] .inst-row input { background: #fff; }

/* ---------- Client portal: what is due, up front ---------- */

.due-hero { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.due-hero[hidden] { display: none; }
.due-hero .amount { font-family: var(--font-heading); font-size: 1.9rem; font-weight: 700; margin: 0; line-height: 1.15; }
.due-hero .sub { color: var(--text-muted); margin: 0.3rem 0 0; font-size: 0.9rem; }
.due-hero.clear .amount { color: #34d399; }

/* ---------- Theme toggle ---------- */

.theme-toggle {
    margin-left: auto;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.theme-toggle:hover { color: var(--text); background: var(--glass-bg); }

/* ---------- Light theme: the few rules that hard-coded white ---------- */

:root[data-theme="light"] body {
    background-image: radial-gradient(900px 500px at 85% -10%, rgba(10, 142, 214, 0.08), transparent 60%);
}
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.16); }
:root[data-theme="light"] .table td { border-bottom-color: rgba(15, 23, 42, 0.06); }
:root[data-theme="light"] .table tbody tr:hover { background: rgba(15, 23, 42, 0.03); }
:root[data-theme="light"] .form-group input, :root[data-theme="light"] .form-group select,
:root[data-theme="light"] .form-group textarea, :root[data-theme="light"] .item-row input,
:root[data-theme="light"] .search-input, :root[data-theme="light"] #nd-discount-value { background: #fff; }
:root[data-theme="light"] .chart .bar.billed { background: rgba(15, 23, 42, 0.16); }
:root[data-theme="light"] .btn-danger, :root[data-theme="light"] .row-menu button.danger,
:root[data-theme="light"] .row-menu button.danger i, :root[data-theme="light"] .due-late { color: #b91c1c; }
:root[data-theme="light"] .due-soon { color: #b45309; }
:root[data-theme="light"] .due-hero.clear .amount { color: #047857; }
:root[data-theme="light"] .badge-paid, :root[data-theme="light"] .badge-active, :root[data-theme="light"] .badge-converted { color: #047857; }
:root[data-theme="light"] .badge-pending { color: #b45309; }
:root[data-theme="light"] .badge-part-paid { color: #0369a1; }
:root[data-theme="light"] .badge-failed, :root[data-theme="light"] .badge-cancelled,
:root[data-theme="light"] .badge-void, :root[data-theme="light"] .badge-expired { color: #b91c1c; }
:root[data-theme="light"] .badge-draft, :root[data-theme="light"] .badge-inactive, :root[data-theme="light"] .badge-skipped { color: #475569; }
:root[data-theme="light"] .badge-sent { color: #6d28d9; }
:root[data-theme="light"] .toast { background: #fff; color: var(--text); }
/* White text needs a deeper blue than the brand cyan to reach AA (5.9:1). */
:root[data-theme="light"] .btn-primary { background: #0369a1; color: #fff; box-shadow: 0 6px 18px rgba(3, 105, 161, 0.25); }
:root[data-theme="light"] .btn-primary:hover:not(:disabled) { box-shadow: 0 8px 22px rgba(3, 105, 161, 0.32); }
