/* ================================================================
   InvoiceHelm Theme — design tokens
   Centralized color / spacing / radius / font tokens used across
   all templates. Reuse these classes instead of inline hex values.
   ================================================================ */
:root {
    --ic-blue: #4f46e5;
    --ic-blue-dark: #4338ca;
    --ic-indigo: #6366f1;
    --ic-red: #e11d48;
    --ic-green: #16a34a;
    --ic-green-soft: #dcfce7;
    --ic-yellow: #ca8a04;
    --ic-yellow-soft: #fef3c7;
    --ic-gray-900: #0f172a;
    --ic-gray-800: #1e293b;
    --ic-gray-700: #334155;
    --ic-gray-600: #475569;
    --ic-gray-500: #64748b;
    --ic-gray-300: #cbd5e1;
    --ic-gray-200: #e2e8f0;
    --ic-gray-100: #f1f5f9;
    --ic-gray-50: #f8fafc;
    --ic-white: #ffffff;
    --ic-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --ic-body-bg: #f8fafc;
    --ic-card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --ic-radius: 12px;
    --ic-radius-lg: 16px;
    --ic-navbar-h: 60px;
    --ic-navbar-bg: #ffffff;
    --ic-navbar-border: #e2e8f0;
    --ic-text: #1e293b;
    --ic-muted: #64748b;
    --ic-heading: #0f172a;
    --ic-card-bg: #ffffff;
    --ic-card-border: #e2e8f0;
    --ic-table-head-bg: #f1f5f9;
    --ic-table-head-color: #475569;
    --ic-table-border: #f1f5f9;
    --ic-table-hover: #f8fafc;
    --ic-kpi-border: #e2e8f0;
    --ic-kpi-danger-bg: #fef2f2;
    --ic-kpi-success-bg: #f0fdf4;
    --ic-kpi-warning-bg: #fefce8;
}

/* ---- Dark mode ---------------------------------------------------
   Driven ONLY by data-bs-theme on <html> (set by the navbar theme
   toggle + localStorage), never by the OS preference alone, so the
   user's choice wins. Every surface below used to be a hardcoded
   light value that blocked dark mode. */
[data-bs-theme="dark"] {
    --ic-body-bg: #0f172a;
    --ic-text: #e2e8f0;
    --ic-muted: #94a3b8;
    --ic-heading: #f1f5f9;
    --ic-navbar-bg: #1e293b;
    --ic-navbar-border: #334155;
    --ic-card-bg: #1e293b;
    --ic-card-border: #334155;
    --ic-table-head-bg: #1e293b;
    --ic-table-head-color: #cbd5e1;
    --ic-table-border: #334155;
    --ic-table-hover: rgba(255, 255, 255, 0.05);
    --ic-kpi-border: #334155;
    --ic-kpi-danger-bg: rgba(225, 29, 72, 0.14);
    --ic-kpi-success-bg: rgba(22, 163, 74, 0.14);
    --ic-kpi-warning-bg: rgba(202, 138, 4, 0.16);
}

body {
    font-family: var(--ic-font);
    background-color: var(--ic-body-bg);
    color: var(--ic-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: var(--ic-blue);
}

/* Dark-mode hyperlink contrast (WCAG AA, ≥4.5:1). The indigo --ic-blue token
   sits at ~2.3–2.8:1 on the dark body (#0f172a) and card (#1e293b) surfaces,
   so content links — legal-page body links, mailto: contacts, and dashboard
   links — switch to Bootstrap's dark link blue. #6ea8fe measures 7.4:1 on the
   dark body and 6.1:1 on cards. Buttons are excluded: they carry their own
   theme-aware colours and text. */
[data-bs-theme="dark"] a:not(.btn) {
    color: #6ea8fe;
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    font-weight: 700;
    color: var(--ic-heading);
    line-height: 1.2;
}

.navbar {
    background-color: var(--ic-navbar-bg);
    border-bottom: 1px solid var(--ic-navbar-border);
    height: var(--ic-navbar-h);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.brand-logo {
    font-weight: 800;
    color: var(--ic-blue);
    font-size: 1.5rem;
}

/* Theme-aware heading colour (was a hardcoded --ic-gray-900, which stayed
   near-black inside dark mode). */
.brand-logo span {
    color: var(--ic-heading);
}

/* Navbar brand: deliberately sets NO text colour of its own, so the brand
   follows the active theme. The wordmark colours itself — "Invoice" via
   .text-body (Bootstrap's theme-aware body colour) and "Helm" via its own
   indigo accent — and `color: inherit` keeps the anchor from falling back to
   the global `a { color: var(--ic-blue) }` rule. Never add a hardcoded dark
   color to .navbar-brand or .navbar-brand span: it would pin the wordmark in
   dark mode. */
.navbar-brand {
    color: inherit;
    text-decoration: none;
}

.card {
    /* No hardcoded background/border: Bootstrap's themed card defaults
       follow data-bs-theme, and bg-body / bg-body-tertiary utilities
       (applied per card) stay in control. */
    border-radius: var(--ic-radius-lg);
    box-shadow: var(--ic-card-shadow);
}

.card-header-custom {
    background: linear-gradient(135deg, var(--ic-blue) 0%, var(--ic-indigo) 100%);
    color: var(--ic-white);
    font-weight: 600;
    font-size: 1.05rem;
    border-radius: var(--ic-radius-lg) var(--ic-radius-lg) 0 0;
    padding: 1.1rem 1.5rem;
}

.kpi-card {
    border-radius: var(--ic-radius);
    border: 1px solid var(--ic-kpi-border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ic-card-shadow);
}

.kpi-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.kpi-card.kpi-danger { background-color: var(--ic-kpi-danger-bg); }
.kpi-card.kpi-danger .kpi-icon { background-color: rgba(225, 29, 72, 0.12); color: var(--ic-red); }
.kpi-card.kpi-success { background-color: var(--ic-kpi-success-bg); }
.kpi-card.kpi-success .kpi-icon { background-color: rgba(22, 163, 74, 0.12); color: var(--ic-green); }
.kpi-card.kpi-warning { background-color: var(--ic-kpi-warning-bg); }
.kpi-card.kpi-warning .kpi-icon { background-color: rgba(202, 138, 4, 0.15); color: var(--ic-yellow); }

.kpi-label {
    color: var(--ic-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-value {
    font-weight: 800;
    margin: 0.35rem 0 0;
    font-size: 1.5rem;
}

.table thead th {
    background-color: var(--ic-table-head-bg);
    color: var(--ic-table-head-color);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    border: none;
    padding: 1rem;
}

.table tbody td {
    vertical-align: middle;
    padding: 1rem;
    color: var(--ic-text);
    border-bottom: 1px solid var(--ic-table-border);
}

.table-hover tbody tr:hover {
    background-color: var(--ic-table-hover);
}

.badge {
    font-weight: 600;
    padding: 0.5em 0.8em;
    border-radius: 999px;
    font-size: 0.82rem;
}

.badge-unpaid { background-color: var(--ic-yellow-soft); color: var(--ic-yellow); }
.badge-paid { background-color: var(--ic-green-soft); color: var(--ic-green); }
.badge-written-off { background-color: #f5f3ff; color: #6d28d9; }
.badge-overdue { background-color: #fee2e2; color: #b91c1c; }
.badge-danger { background-color: #fef2f2; color: var(--ic-red); }
.badge-stage { background-color: var(--ic-gray-100); color: var(--ic-gray-700); }
.badge-schedule { background-color: #eff6ff; color: var(--ic-blue-dark); }
.badge-link { background-color: #ecfeff; color: #0891b2; }
/* Refunded invoice: money went back to the client, so it gets its own chip. */
.badge-refunded { background-color: #fff7ed; color: #c2410c; }
/* INVA-90: a discretionary waiver is active on this invoice. */
.badge-waiver { background-color: #f5f3ff; color: #6d28d9; }
/* Admin subscription console */
.badge-free { background-color: var(--ic-gray-100); color: var(--ic-gray-700); }
.badge-sub-active { background-color: var(--ic-green-soft); color: var(--ic-green); }
.badge-sub-canceled { background-color: var(--ic-gray-100); color: var(--ic-gray-700); }
.badge-sub-refunded { background-color: #fff7ed; color: #c2410c; }
.badge-event { background-color: #eff6ff; color: var(--ic-blue-dark); }

.btn { border-radius: 6px; }
.btn-primary {
    background-color: var(--ic-blue);
    border-color: var(--ic-blue);
    transition: all 0.2s ease;
}
.btn-primary:hover {
    background-color: var(--ic-blue-dark);
    border-color: var(--ic-blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.btn-primary:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.3);
    outline-offset: 2px;
}

.btn-outline-success:hover {
    background-color: var(--ic-green);
    border-color: var(--ic-green);
    color: #fff;
    transform: translateY(-1px);
}

.btn-outline-danger:hover {
    background-color: var(--ic-red);
    border-color: var(--ic-red);
    color: #fff;
    transform: translateY(-1px);
}

.btn-pay {
    background-color: var(--ic-green);
    border-color: var(--ic-green);
    color: white;
    font-weight: 600;
    transition: all 0.2s ease;
    min-height: 44px;
}

.btn-pay:hover {
    background-color: #059669;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.35);
}

.btn-pay:focus-visible {
    outline: 3px solid rgba(22, 163, 74, 0.3);
    outline-offset: 2px;
}

.form-control {
    border-radius: 6px;
    min-height: 44px;
}

.form-control:focus {
    border-color: var(--ic-blue);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-control-sm { border-radius: 6px; }

.max-w-xs { max-width: 660px; }
.max-w-sm { max-width: 700px; }
.max-w-md { max-width: 780px; }
.max-w-lg { max-width: 1000px; }
.max-w-xl { max-width: 1200px; }
.max-w-2xl { max-width: 1340px; }
.max-w-3xl { max-width: 1520px; }
.max-w-7xl { max-width: 1400px; }

.text-muted { color: var(--ic-muted); }

.nav-tabs { border-bottom: 1px solid var(--ic-gray-200); }
.nav-tabs .nav-link { border: none; font-weight: 600; color: var(--ic-gray-500); border-radius: 8px; padding: 0.5rem 1rem; background: transparent; }
.nav-tabs .nav-link:hover { background-color: var(--ic-gray-100); color: var(--ic-gray-800); }
.nav-tabs .nav-link.active { background-color: var(--ic-blue); color: #fff; box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3); }

[data-bs-theme="dark"] .nav-tabs { border-bottom: 1px solid var(--ic-gray-700); }
[data-bs-theme="dark"] .nav-tabs .nav-link { color: #cbd5e1; background: transparent; }
[data-bs-theme="dark"] .nav-tabs .nav-link:hover { background-color: var(--ic-gray-700); color: #e2e8f0; }
[data-bs-theme="dark"] .nav-tabs .nav-link.active { background-color: #4f46e5; color: #fff; }

/* ---- Badge chips: translucent tints so they sit on dark rows ---- */
[data-bs-theme="dark"] .badge-stage { background-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .badge-unpaid { background-color: rgba(202, 138, 4, 0.18); color: #fbbf24; }
[data-bs-theme="dark"] .badge-paid { background-color: rgba(22, 163, 74, 0.20); color: #4ade80; }
[data-bs-theme="dark"] .badge-written-off { background-color: rgba(109, 40, 217, 0.22); color: #c4b5fd; }
[data-bs-theme="dark"] .badge-overdue { background-color: rgba(225, 29, 72, 0.20); color: #fda4af; }
[data-bs-theme="dark"] .badge-schedule { background-color: rgba(79, 70, 229, 0.20); color: #a5b4fc; }
[data-bs-theme="dark"] .badge-link { background-color: rgba(8, 145, 178, 0.20); color: #67e8f9; }
[data-bs-theme="dark"] .badge-refunded { background-color: rgba(194, 65, 12, 0.22); color: #fdba74; }
[data-bs-theme="dark"] .badge-waiver { background-color: rgba(109, 40, 217, 0.22); color: #c4b5fd; }
[data-bs-theme="dark"] .badge-free { background-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .badge-sub-active { background-color: rgba(22, 163, 74, 0.20); color: #4ade80; }
[data-bs-theme="dark"] .badge-sub-canceled { background-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .badge-sub-refunded { background-color: rgba(194, 65, 12, 0.22); color: #fdba74; }
[data-bs-theme="dark"] .badge-event { background-color: rgba(79, 70, 229, 0.20); color: #a5b4fc; }

/* --- Invoice activity timeline (Nudge modal) ------------------------------ */
/* Compact vertical rail: a muted line with a coloured dot per event type,
   readable in both themes. */
.tl {
    position: relative;
}
.tl::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 9px;
    bottom: 9px;
    width: 2px;
    background-color: #e2e8f0;
}
[data-bs-theme="dark"] .tl::before { background-color: #334155; }

.tl-item {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.9rem;
}
.tl-item:last-child { margin-bottom: 0; }

.tl-dot {
    position: absolute;
    left: 0;
    top: 0.3rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #cbd5e1;
    /* Ring in the modal's own background so the rail appears to pass behind. */
    box-shadow: 0 0 0 3px var(--bs-body-bg, #fff);
}
[data-bs-theme="dark"] .tl-dot { background-color: #64748b; }

/* Event accents — one colour per event_type. */
.tl-dot.tl-reminder_sent { background-color: #6366f1; }
.tl-dot.tl-note_saved { background-color: #0ea5e9; }
.tl-dot.tl-promised_date { background-color: #d97706; }
.tl-dot.tl-status_changed { background-color: #16a34a; }
.tl-dot.tl-invoice_created { background-color: #0f766e; }
.tl-dot.tl-payment_received { background-color: #15803d; }
.tl-dot.tl-receipt_sent { background-color: #7c3aed; }
.tl-dot.tl-payment_refunded { background-color: #c2410c; }

.tl-meta {
    font-size: 0.72rem;
    line-height: 1.2;
    color: #6c757d;
}
[data-bs-theme="dark"] .tl-meta { color: #94a3b8; }

/* ---- Utility safety net ------------------------------------------
   These Bootstrap utilities are hardcoded and would otherwise stay
   light inside a dark page. */
[data-bs-theme="dark"] .text-dark { color: var(--ic-heading) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--bs-tertiary-bg) !important; }
[data-bs-theme="dark"] .bg-white { background-color: var(--bs-body-bg) !important; color: var(--ic-text); }

/* ---- Multi-invoice bulk action bar ---------------------------------
   Sticky to the bottom of the viewport while the table is in view; the
   markup carries `.d-none` until at least one row is ticked. */
.bulk-bar {
    position: sticky;
    bottom: 1rem;
    z-index: 1020;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15);
}
[data-bs-theme="dark"] .bulk-bar {
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.55);
}
.bulk-bar #bulkCount { font-size: 0.9rem; }

/* ---- Theme-aware dashboard preview image --------------------------
   The landing-page hero ships a light-mode SVG illustration. Rather
   than maintain a second asset, invert it in dark mode and rotate the
   hue back so the indigo/violet brand accents survive the inversion
   (invert(1) alone would swing them to orange). The transition keeps
   the theme toggle from producing a jarring flash. */
.dashboard-preview {
    transition: filter 0.25s ease;
}
[data-bs-theme="dark"] .dashboard-preview {
    filter: invert(1) hue-rotate(180deg);
}
@media (prefers-reduced-motion: reduce) {
    .dashboard-preview { transition: none; }
}

/* ---- Mobile offcanvas drawer (INVA-166) ---------------------------
    The navbars collapse below <768px into this end drawer. It inherits
    the theme tokens so the surface, divider and hover tints stay
    correct in dark mode; width caps at 85vw so it never covers the
    whole phone screen. */
.dash-mobile-nav {
    --bs-offcanvas-width: min(320px, 85vw);
    background-color: var(--ic-card-bg);
    border-left: 1px solid var(--ic-card-border);
}
/* Dark mode: Bootstrap's btn-outline-secondary label (gray-600) reaches
   only 3.1:1 on the drawer surface; lift it to gray-200 (11.4:1) so the
   drawer's secondary actions meet WCAG 4.5:1 (INVA-166 UX residual). */
[data-bs-theme="dark"] .dash-mobile-nav .btn-outline-secondary {
    color: var(--ic-gray-200);
}
.dash-drawer-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 1rem;
}
.dash-drawer-link:hover { background-color: var(--ic-gray-100); }
[data-bs-theme="dark"] .dash-drawer-link:hover { background-color: var(--ic-gray-800); }
.dash-drawer-divider {
    border-color: var(--ic-card-border);
    opacity: 1;
    margin: 0.5rem 0;
}
/* The theme toggle is rendered by theme.js into the mount span; give the
   drawer copy a full-width, 44px row so it reads as a first-class action. */
.dash-drawer-theme [data-theme-toggle] {
    width: 100%;
    min-height: 44px;
}

/* ---- Mobile touch ergonomics (INVA-166) ---------------------------
    Coarse-pointer viewports: every interactive control gets at least a
    44px touch target (WCAG 2.5.8). Desktop layout is untouched. */
@media (max-width: 767.98px) {
    .btn,
    .btn-sm,
    .btn-ghost {
        min-height: 44px;
    }
    .navbar-toggler {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .nav-pills .nav-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }
    /* btn-close draws a fixed 1em glyph, so a bigger box grows the hit
       area while the visible X stays the same size. */
    .btn-close {
        width: 44px;
        height: 44px;
    }
}
