/* ============================================================
   CashCow — Design System
   GreenPasture Finance Middleware UI
   YCM Brand Guide v2 — Dark Theme
   ============================================================ */

/* ── TOKENS ──────────────────────────────────────────────── */
:root {
    /* Brand Colors */
    --charcoal:      #1C1D1F;
    --charcoal-2:    #242527;
    --charcoal-3:    #2C2D30;
    --charcoal-4:    #363739;
    --charcoal-5:    #404244;
    --ochre:         #D97742;
    --ochre-hover:   #C5693A;
    --ochre-muted:   rgba(217, 119, 66, 0.12);
    --sandstone:     #B59E7B;
    --sandstone-muted: rgba(181, 158, 123, 0.1);
    --warm-white:    #FAF9F6;
    --steel:         #6C7A89;
    --steel-muted:   rgba(108, 122, 137, 0.15);
    --periwinkle:    #c3d1e6;

    /* Semantic */
    --bg:            var(--charcoal);
    --bg-raised:     var(--charcoal-2);
    --bg-card:       var(--charcoal-3);
    --bg-input:      var(--charcoal-4);
    --border:        var(--charcoal-4);
    --border-light:  var(--charcoal-5);
    --text-primary:  var(--warm-white);
    --text-secondary: var(--steel);
    --text-muted:    #555759;
    --accent:        var(--ochre);
    --accent-hover:  var(--ochre-hover);

    /* Status */
    --green:         #4CAF7D;
    --green-muted:   rgba(76, 175, 125, 0.12);
    --red:           #E05C5C;
    --red-muted:     rgba(224, 92, 92, 0.12);
    --yellow:        #E0A030;
    --yellow-muted:  rgba(224, 160, 48, 0.12);
    --blue:          #5B8DEF;
    --blue-muted:    rgba(91, 141, 239, 0.12);

    /* Layout */
    --surface-hover: var(--charcoal-4);

    --sidebar-width: 220px;
    --header-h:      64px;
    --bottom-nav-h:  64px;
    --radius:        8px;
    --radius-lg:     12px;
    --radius-xl:     16px;
    --shadow:        0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.5);

    /* Type */
    --font-head:     'Space Grotesk', sans-serif;
    --font-body:     'Open Sans', sans-serif;
}

/* ── RESET ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
svg { display: block; }
img { max-width: 100%; }

/* ── UTILITY ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── LOGIN SCREEN ────────────────────────────────────────── */
.login-screen {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: 10px;
}

.login-brand {
    font-family: var(--font-head);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.login-divider {
    width: 40px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
    margin: 4px 0;
}

.login-desc {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.6;
    padding: 0 8px;
}

.login-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 4px;
}

.login-error {
    width: 100%;
    background: var(--red-muted);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--red);
    text-align: center;
}

.login-footer {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-body);
    transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
    min-height: 44px;
    white-space: nowrap;
    cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: var(--warm-white);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--charcoal-4);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}
.btn-secondary:hover:not(:disabled) { background: var(--charcoal-5); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--steel-muted); color: var(--text-primary); }

.btn-danger {
    background: var(--red-muted);
    color: var(--red);
    border: 1px solid var(--red);
}
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn-lg { padding: 14px 24px; font-size: 16px; min-height: 52px; }
.btn-icon { padding: 8px; min-height: auto; width: 36px; height: 36px; border-radius: var(--radius); }

/* ── APP SHELL ───────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100dvh;
    background: var(--bg-raised);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}

.sidebar-brand-name {
    font-family: var(--font-head);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
}

.sidebar-brand-sub {
    font-size: 10px;
    font-weight: 500;
    color: var(--steel);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
    position: relative;
    user-select: none;
}
.nav-item:hover { background: var(--steel-muted); color: var(--text-primary); }
.nav-item.active {
    background: var(--ochre-muted);
    color: var(--accent);
}
.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
}

.nav-badge {
    margin-left: auto;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 4px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ochre-muted);
    border: 1.5px solid var(--accent);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-head);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}

.sidebar-user-info {
    flex: 1;
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.sidebar-signout {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: color 0.12s, background 0.12s;
    flex-shrink: 0;
}
.sidebar-signout:hover { color: var(--red); background: var(--red-muted); }

/* ── MAIN CONTENT ────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ── PAGE ────────────────────────────────────────────────── */
.page {
    flex: 1;
    padding: 28px 32px;
    max-width: 1280px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.page-title {
    font-family: var(--font-head);
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── CARDS ───────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.card-title {
    font-family: var(--font-head);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* ── KPI CARDS (Dashboard) ───────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.2s;
}
.kpi-card:hover::before { opacity: 1; }

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.kpi-value {
    font-family: var(--font-head);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1;
}

.kpi-meta {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.kpi-delta-up { color: var(--green); }
.kpi-delta-down { color: var(--red); }

/* ── STAT PILL ───────────────────────────────────────────── */
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
}
.stat-pill.green { background: var(--green-muted); color: var(--green); }
.stat-pill.red   { background: var(--red-muted);   color: var(--red); }
.stat-pill.yellow{ background: var(--yellow-muted); color: var(--yellow); }
.stat-pill.blue  { background: var(--blue-muted);  color: var(--blue); }
.stat-pill.ochre { background: var(--ochre-muted); color: var(--accent); }
.stat-pill.steel { background: var(--steel-muted); color: var(--steel); }

/* ── TABLES ──────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead {
    background: var(--charcoal-2);
    position: sticky;
    top: 0;
    z-index: 1;
}

thead th {
    padding: 11px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--steel-muted); }

tbody td {
    padding: 12px 16px;
    color: var(--text-primary);
    vertical-align: middle;
}

.td-muted { color: var(--text-secondary); font-size: 13px; }
.td-mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    letter-spacing: 0.3px;
}
.td-amount {
    font-family: var(--font-head);
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}
.td-amount.positive { color: var(--green); }
.td-amount.negative { color: var(--red); }

.table-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ── FORMS ───────────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; }
.form-row > .form-group { flex: 1; min-width: 0; }
@media (max-width: 520px) { .form-row { flex-direction: column; } }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-label .required {
    color: var(--accent);
    margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
    min-height: 44px;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ochre-muted);
}
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236C7A89' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}
.form-textarea { resize: vertical; min-height: 80px; }

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.form-error {
    font-size: 12px;
    color: var(--red);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ── MODAL / SHEET ───────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title {
    font-family: var(--font-head);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: color 0.12s, background 0.12s;
}
.modal-close:hover { color: var(--text-primary); background: var(--steel-muted); }

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

/* ── TOASTS ──────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--charcoal-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    max-width: 380px;
    pointer-events: all;
    animation: toastIn 0.25s ease;
}
.toast.toast-exit { animation: toastOut 0.25s ease forwards; }

.toast-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.toast.success .toast-dot { background: var(--green); }
.toast.error   .toast-dot { background: var(--red); }
.toast.warning .toast-dot { background: var(--yellow); }
.toast.info    .toast-dot { background: var(--blue); }

.toast-msg { flex: 1; line-height: 1.4; }

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

/* ── DIVIDERS & SECTIONS ─────────────────────────────────── */
.section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* ── LOADING ─────────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

.page-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-secondary);
    gap: 12px;
    font-size: 14px;
}

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    gap: 12px;
    text-align: center;
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
}

.empty-state-title {
    font-family: var(--font-head);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state-desc {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 320px;
    line-height: 1.6;
}

/* ── BADGE INLINE ────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-draft   { background: var(--steel-muted);  color: var(--steel); }
.badge-sent    { background: var(--blue-muted);   color: var(--blue); }
.badge-paid    { background: var(--green-muted);  color: var(--green); }
.badge-overdue { background: var(--red-muted);    color: var(--red); }
.badge-void    { background: var(--charcoal-4);   color: var(--text-muted); }
.badge-open    { background: var(--ochre-muted);  color: var(--accent); }
.badge-locked  { background: var(--green-muted);  color: var(--green); }
.badge-pending { background: var(--yellow-muted); color: var(--yellow); }

/* ── TABS ────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.12s, border-color 0.12s;
    user-select: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── FILTERS ROW ─────────────────────────────────────────── */
.filters-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

.search-input-wrap svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.search-input {
    padding-left: 36px;
}

/* ── BOTTOM NAV (mobile) ─────────────────────────────────── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    z-index: 100;
    align-items: stretch;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.12s;
    border-radius: var(--radius);
    position: relative;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item:active { background: var(--steel-muted); }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
}

.bottom-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(8px);
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* ── DASHBOARD GRID ──────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.dashboard-grid .full-width { grid-column: 1 / -1; }

/* ── CLOSE CHECKLIST ─────────────────────────────────────── */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }

.checklist-check {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-light);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.12s, background 0.12s;
}
.checklist-check.done { border-color: var(--green); background: var(--green-muted); }
.checklist-check.done svg { color: var(--green); }

/* ── SCROLLBAR ───────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--charcoal-5) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--charcoal-5); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding-bottom: var(--bottom-nav-h); }
    .bottom-nav { display: flex; }
    .page { padding: 20px 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid.cols-3 { grid-template-columns: 1fr; }
    .form-grid.cols-4 { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .modal { max-width: 100%; margin: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; align-self: flex-end; }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    #toast-container { bottom: calc(var(--bottom-nav-h) + 16px); right: 16px; left: 16px; }
    .toast { max-width: 100%; }
}

@media (max-width: 520px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-title { font-size: 22px; }
}

/* ── INVOICE PAGE ─────────────────────────────────────────── */
.inv-totals { display: flex; flex-direction: column; gap: 0; }
.inv-totals-internal-header { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); background: var(--charcoal-4); border-radius: var(--radius-sm); padding: 4px 8px; margin-bottom: 4px; }
.inv-totals-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.inv-totals-row:last-child { border-bottom: none; }
.inv-totals-divider { border-top: 1px solid var(--border-light); margin-top: 4px; padding-top: 10px; font-weight: 600; }
.inv-totals-total { font-size: 16px; font-weight: 700; color: var(--text-primary); border-top: 2px solid var(--border-light); padding-top: 12px; margin-top: 4px; }

.btn-icon { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: var(--radius-sm); line-height: 1; transition: color .15s, background .15s; }
.btn-icon:hover { color: var(--red); background: var(--red-muted); }

.filter-btn { color: var(--text-secondary); }
.filter-btn.active { color: var(--ochre); border-color: var(--ochre); background: var(--ochre-muted); }

@media (max-width: 760px) {
    .inv-top-grid, .inv-bottom-grid { grid-template-columns: 1fr !important; }
}

/* ── INVOICE OVERLAY (preview / print) ───────────────────── */
.invoice-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0,0,0,0.85);
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 40px;
    overflow-y: auto;
    gap: 16px;
}

.invoice-overlay-actions {
    display: flex;
    gap: 10px;
    align-self: flex-end;
    max-width: 760px;
    width: 100%;
    flex-shrink: 0;
}

.invoice-paper {
    background: #fff;
    color: #111;
    width: 100%;
    max-width: 760px;
    padding: 40px 48px;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    font-family: 'Open Sans', Arial, sans-serif;
    font-size: 13px;
    line-height: 1.6;
    flex-shrink: 0;
}

.inv-doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    border-bottom: 2px solid #333;
    padding-bottom: 16px;
}

.inv-doc-title {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: .04em;
    color: #111;
    font-family: 'Space Grotesk', sans-serif;
}

.inv-sub-items {
    margin: 4px 0 0 12px;
    padding: 0 0 0 14px;
    font-size: 11px;
    color: #555;
    line-height: 1.5;
}

/* ── PRINT STYLES ─────────────────────────────────────────── */
@media print {
    body * { visibility: hidden; }
    .invoice-paper, .invoice-paper * { visibility: visible; }
    .invoice-paper { position: fixed; inset: 0; padding: 24px 32px; box-shadow: none; max-width: 100%; border-radius: 0; }
    .invoice-overlay-actions { display: none !important; }
    @page { margin: 0; size: letter; }
}

/* ── BADGE — MONTHLY CLOSE STATUSES ─────────────────────── */
.badge-approved      { background: var(--green-muted);  color: var(--green); }
.badge-close-open    { background: var(--ochre-muted);  color: var(--accent); }
.badge-close-in_review { background: var(--blue-muted); color: var(--blue); }
.badge-close-approved  { background: var(--green-muted); color: var(--green); }
.badge-close-locked    { background: var(--charcoal-4);  color: var(--text-muted); }

/* ── BTN EXTRA SMALL ─────────────────────────────────────── */
.btn-xs { padding: 2px 8px; font-size: 11px; height: auto; }

/* ── SETTINGS PAGE ───────────────────────────────────────── */
.settings-detail-grid { display: flex; flex-direction: column; gap: 0; margin-bottom: 4px; }
.settings-detail-row  { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.settings-detail-row:last-child { border-bottom: none; }
.settings-detail-label { color: var(--text-secondary); }
.settings-detail-value { color: var(--text-primary); font-weight: 500; }
