/* ============================================
   SpexCRM Theme System — the app shell
   ============================================

   The world, the scales and --brand live in tokens.css, which this
   file and the public site both load. What lives here is the mapping
   from those raw values to semantic surface tokens, per theme.

   Dark is the ground state. Light is paper.
   ============================================ */

/* -- Brand derivations ------------------------ */
:root {
    /* Sidebar dimensions */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;

    /* Every brand shade derives from --brand, so one injected value
       re-skins the app and the shades cannot drift out of relation.
       --primary is a FILL. Text and links use --link (set per theme
       below), because an organisation may pick a colour that is
       illegible as type, and readability must not depend on taste. */
    --primary:         var(--brand);
    --primary-hover:   color-mix(in srgb, var(--brand) 85%, black);
    --primary-muted:   color-mix(in srgb, var(--brand) 15%, transparent);
    --primary-border:  color-mix(in srgb, var(--brand) 38%, transparent);

    /* Flat fills. These kept their --gradient-* names so the ~20
       existing references keep resolving; the gradients are gone. */
    --gradient-primary: var(--primary);
    --gradient-success: var(--accent-success);
    --gradient-warning: var(--accent-warning);
    --gradient-danger:  var(--accent-danger);

    --card-radius:  var(--radius-md);
    --input-radius: var(--radius-sm);
    --btn-radius:   var(--radius-sm);
    --table-row-height: 48px;
}

/* -- Dark (default): the ink world ------------ */
[data-bs-theme="dark"] {
    --bg-primary:    var(--ink-2);
    --bg-secondary:  var(--ink-3);
    --bg-tertiary:   var(--ink);
    --bg-quaternary: var(--ink-4);
    --bg-card:       #141F33;
    --bg-hover:      var(--ink-4);
    --bg-surface:    var(--ink-3);

    --text-primary:   #EEF2F8;
    --text-secondary: var(--ink-pale);
    /* #6E829E was 4.20:1 on cards and 3.5:1 on row hover: below AA for the
       help text, timestamps and labels it carries. Same hue, lighter. */
    --text-muted:     #8498B2;
    /* --accent-danger (#d04545) is 3.63:1 on dark cards, so error text failed AA
       in this theme only. Lighter same-hue red: 6.19 card, 5.19 hover. */
    --accent-danger:  #E88181;

    /* Interactive text. Not the brand -- see the note above. */
    --link:       #8FB3E6;
    --link-hover: #B9D1F2;

    --border-color: #24364F;
    --border-light: #2F4461;
    --border-hover: var(--primary-border);

    --sidebar-bg:     #0B1320;
    --sidebar-border: #1C2A40;
    --topbar-bg:      #0B1320;

    --card-bg:      var(--bg-card);
    --card-border:  var(--border-color);
    --input-bg:     var(--bg-secondary);
    --input-border: var(--border-color);

    --shadow-md: 0 4px 16px rgba(0,0,0,0.35), 0 1px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5), 0 4px 16px rgba(0,0,0,0.3);
    --shadow-glow: 0 0 0 1px var(--primary-border);
}

/* -- Light: paper ----------------------------- */
[data-bs-theme="light"] {
    --bg-primary:    var(--paper);
    --bg-secondary:  #FFFFFF;
    --bg-tertiary:   #FFFFFF;
    --bg-quaternary: var(--paper-2);
    --bg-card:       #FFFFFF;
    --bg-hover:      var(--paper-2);
    --bg-surface:    var(--paper-2);

    --text-primary:   var(--ink);
    --text-secondary: #56606F;
    --text-muted:     var(--muted);

    --link:       var(--ink-soft);
    --link-hover: var(--ink);

    --border-color: var(--rule);
    --border-light: #C9C6BC;
    --border-hover: var(--primary-border);

    --sidebar-bg:     var(--paper);
    --sidebar-border: var(--rule);
    --topbar-bg:      var(--paper);

    --card-bg:      #FFFFFF;
    --card-border:  var(--rule);
    --input-bg:     #FFFFFF;
    --input-border: #C9C6BC;

    --shadow-md: 0 2px 10px rgba(22,35,58,0.07);
    --shadow-lg: 0 8px 26px rgba(22,35,58,0.10);
    --shadow-glow: 0 0 0 1px var(--primary-border);
}

/* Aliases kept so templates that reached for names this file never
   defined now resolve instead of rendering nothing. They were
   referenced in 8 places across dashboard, kanban, onboarding,
   plan_status and reporting: the activity dots had no background
   and "At limit" was not red. */
:root {
    --accent:           var(--brand);
    --accent-primary:   var(--brand);
    --accent-secondary: var(--link);

    /* --primary-light was this file's name for "interactive text" before
       --link replaced it. Twelve app templates and base-components.css
       still reference it by that name, so it stays as an alias rather
       than silently resolving to nothing. --bg-sidebar is the same story
       for accept_invitation.html. */
    --primary-light: var(--link);
    --bg-sidebar:    var(--sidebar-bg);
    --success: var(--accent-success);
    --danger:  var(--accent-danger);
    --warning: var(--accent-warning);
    --info:    var(--accent-info);
}

/* Light-specific overrides */
[data-bs-theme="light"] .sidebar-nav .nav-link.active {
    background: var(--primary-muted);
    color: var(--text-primary);
}
[data-bs-theme="light"] .table > tbody > tr:hover { background: var(--bg-quaternary); }
[data-bs-theme="light"] .btn-close   { filter: none; }
[data-bs-theme="light"] ::-webkit-scrollbar-track  { background: var(--paper-2); }
[data-bs-theme="light"] ::-webkit-scrollbar-thumb  { background: var(--rule); }
[data-bs-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #B9B5A9; }
[data-bs-theme="light"] .ts-control   { background: #fff !important; }
[data-bs-theme="light"] .ts-dropdown  { background: #fff !important; box-shadow: var(--shadow-md); }
[data-bs-theme="light"] .ts-dropdown .option.selected { background: var(--bg-quaternary); }
[data-bs-theme="light"] .filter-bar  { background: #ffffff; border-color: var(--rule); }

/* ============================================
   Base
   ============================================ */
h1, h2, h3, h4, h5, h6,
.page-title, .card-title, .stat-value, .section-title {
    font-family: var(--font-display);
    letter-spacing: -0.005em;
}

/* Keyboard focus. There were 50 :hover rules and no :focus-visible at all. */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 2px;
}
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: none;
}

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

body {
    font-family: var(--font-ui);
    font-size: 0.9375rem;    /* 15px — precise, not oversized */
    line-height: 1.55;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* lining-nums is load-bearing, not decoration. Zilla Slab -- which
       carries every heading and figure -- defaults to OLDSTYLE figures,
       where zero sits at x-height. "R0" therefore rendered as "Ro" on the
       Overdue tile, and every 0 in R32,200 read as a lowercase o.
       tabular-nums alone fixes the spacing and not the figure style, which
       is why this looked correct in the stylesheet and wrong on screen.
       Found by looking at a rendered page; no test can see it. */
    font-feature-settings: "tnum", "lnum";
    font-variant-numeric: lining-nums tabular-nums;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

/* ── Typography utilities ─────────────────────── */
h1, .h1 { font-size: 1.75rem;   font-weight: 700; letter-spacing: -0.025em; line-height: 1.25; }
h2, .h2 { font-size: 1.4rem;    font-weight: 700; letter-spacing: -0.02em;  line-height: 1.25; }
h3, .h3 { font-size: 1.15rem;   font-weight: 600; letter-spacing: -0.015em; line-height: 1.25; }
h4, .h4 { font-size: 1rem;      font-weight: 600; line-height: 1.3; }
h5, .h5 { font-size: 0.9375rem; font-weight: 600; line-height: 1.3; }

.section-label {
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--text-muted);
}

.gradient-chip {
    display: inline-flex;
    align-items: center;
    background: var(--primary-muted);
    border: 1px solid var(--primary-border);
    color: var(--link);
    border-radius: var(--radius-pill);
    padding: 4px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0;
}

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

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: width 0.25s var(--ease-out);
    border-right: 1px solid var(--sidebar-border, var(--border-color));
    overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

body.sidebar-is-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
body.sidebar-is-collapsed .main-content.with-sidebar { margin-left: var(--sidebar-collapsed-width); }

body.sidebar-is-collapsed .sidebar .brand-text,
body.sidebar-is-collapsed .sidebar .sidebar-nav .nav-link span,
body.sidebar-is-collapsed .sidebar .sidebar-footer .nav-link span,
.sidebar.collapsed .brand-text,
.sidebar.collapsed .sidebar-nav .nav-link span,
.sidebar.collapsed .sidebar-footer .nav-link span {
    display: none;
}

body.sidebar-is-collapsed .sidebar .sidebar-nav .nav-link,
body.sidebar-is-collapsed .sidebar .sidebar-footer .nav-link,
.sidebar.collapsed .sidebar-nav .nav-link,
.sidebar.collapsed .sidebar-footer .nav-link {
    justify-content: center;
    padding: 0.75rem;
}

body.sidebar-is-collapsed .sidebar .sidebar-nav .nav-link i,
body.sidebar-is-collapsed .sidebar .sidebar-footer .nav-link i,
.sidebar.collapsed .sidebar-nav .nav-link i,
.sidebar.collapsed .sidebar-footer .nav-link i {
    font-size: 1.2rem;
    margin-right: 0;
}

body.sidebar-is-collapsed .sidebar .nav-section,
.sidebar.collapsed .nav-section { display: none; }

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--sidebar-border, var(--border-color));
    min-height: 60px;
    gap: 10px;
    flex-shrink: 0;
}

/* Logo mark — gradient square with initial */
.sidebar-logo {
    width: 32px;
    height: 32px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 800;
    font-size: 14px;
    color: white;
    letter-spacing: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
    flex: 1;
    overflow: hidden;
}

.sidebar-brand:hover { color: var(--link); text-decoration: none; }

.sidebar-brand .brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle {
    color: var(--text-muted);
    padding: 0.25rem 0.375rem;
    font-size: 1.1rem;
    background: transparent;
    border: none;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

/* Sidebar Nav */
.sidebar-nav {
    list-style: none;
    padding: 0.75rem;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

.sidebar-nav::-webkit-scrollbar       { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.sidebar-nav .nav-item { margin-bottom: 2px; }

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin: 1px 0;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
    white-space: nowrap;
}

.sidebar-nav .nav-link i {
    font-size: 1rem;
    margin-right: 0.75rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color 0.15s;
}

.sidebar-nav .nav-link:hover {
    background: color-mix(in srgb, var(--brand) 8%, transparent);
    color: var(--text-primary);
}
.sidebar-nav .nav-link:hover i { color: var(--link); }
.sidebar-nav .nav-link.active i { color: var(--link); }

.sidebar-nav .nav-link.active {
    background: color-mix(in srgb, var(--brand) 15%, transparent);
    color: var(--link);
    font-weight: 600;
    border-left: 2px solid var(--primary);
    padding-left: 10px;  /* compensate for 2px border */
}

/* Nav section headers */
.sidebar-nav .nav-section {
    padding: 0.875rem 0.875rem 0.375rem;
}

.sidebar-nav .nav-section-text {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}

.sidebar.collapsed .nav-section { padding: 0.5rem 0; }
.sidebar.collapsed .nav-section-text { display: none; }
.sidebar.collapsed .nav-section::after {
    content: '';
    display: block;
    height: 1px;
    background: var(--border-color);
    margin: 0 0.5rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 8px 12px 12px;
    border-top: 1px solid var(--sidebar-border, var(--border-color));
    flex-shrink: 0;
}

.sidebar-footer .nav-link {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    color: var(--accent-danger);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s;
    white-space: nowrap;
}

.sidebar-footer .nav-link i { font-size: 1rem; margin-right: 0.75rem; }
.sidebar-footer .nav-link:hover { background: rgba(239, 68, 68, 0.1); }

/* Sidebar upgrade CTA (shown for non-professional plans) */
.sidebar-upgrade-cta {
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--brand) 20%, transparent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow: hidden;
    transition: border-color 0.2s;
}
.sidebar-upgrade-cta:hover { border-color: color-mix(in srgb, var(--brand) 40%, transparent); }
.sidebar-upgrade-plan {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--link);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-upgrade-sidebar {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.btn-upgrade-sidebar:hover { opacity: 0.85; color: white; text-decoration: none; }
body.sidebar-is-collapsed .sidebar-upgrade-cta,
.sidebar.collapsed .sidebar-upgrade-cta { display: none; }

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg-primary);
}

.main-content.with-sidebar {
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-speed) ease;
}

.main-content.expanded { margin-left: var(--sidebar-collapsed-width); }

/* ============================================
   Top Navbar
   ============================================ */
.top-navbar {
    background: var(--topbar-bg) !important;
    border-bottom: 1px solid var(--border-color);
    padding: 0 1rem;
    min-height: 56px;
}

.top-navbar .navbar-brand {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
}

/* The logged-out brand mark: the same per-theme SVG pair as the sidebar
   (.logo-on-ink / .logo-on-paper swap them), not an icon font tinted with
   --brand -- brand is a fill, never type. */
.top-navbar .navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2, 0.5rem);
}
.top-navbar .navbar-brand-img {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.top-navbar .navbar-brand:hover { color: var(--link); }

.top-navbar .nav-link {
    color: var(--text-secondary) !important;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: color 0.15s ease;
}

.top-navbar .nav-link:hover { color: var(--text-primary) !important; }

.top-navbar .dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
}

.top-navbar .dropdown-item {
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
}

.top-navbar .dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   Content Area
   ============================================ */
.content-area { flex: 1; }
.content-area .container-fluid {
    max-width: 1400px;
    padding-left: 28px;
    padding-right: 28px;
}

@media (max-width: 575.98px) {
    .content-area .container-fluid {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ── Page Header (standardised across all inner pages) ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;   /* the action was pushed off-screen below ~500px */
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.025em;
    line-height: 1.25;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 2px 0 0;
}

/* ── Upgrade Modal ───────────────────────────── */
.upgrade-modal-icon {
    text-align: center;
    padding: 24px 0 8px;
}
.upgrade-modal-icon i {
    font-size: 2.5rem;
    color: var(--text-primary);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 0.875rem 1rem;
    text-align: center;
}

.footer .text-muted { color: var(--text-muted) !important; font-size: 0.8rem; }

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--card-bg, var(--bg-card));
    border: 1px solid var(--card-border, var(--border-color));
    border-radius: var(--card-radius);
    box-shadow: none;
    transition: border-color 0.15s var(--ease-out);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 20px;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body  { padding: 1.5rem; }
.card-footer {
    background: transparent;
    border-top: 1px solid var(--border-color);
    padding: 12px 20px;
}
.card-title { color: var(--text-primary); font-weight: 600; margin: 0; }

/* Interactive card — lifts and glows on hover */
.card-interactive {
    cursor: pointer;
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
.card-interactive:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

/* Legacy alias kept for existing templates */
.card-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}
.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ── Table Card (table + filter wrapper) ─────── */
.table-card {
    background: transparent;
    border: 0;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
    overflow: visible;
}
.table-card .table { margin: 0; }
.table-card .table-responsive { border-radius: 0; }

.table-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Filter Bar ──────────────────────────────── */
.filter-bar {
    background: var(--card-bg, var(--bg-card));
    border: 1px solid var(--card-border, var(--border-color));
    border-radius: var(--card-radius);
    padding: 16px 20px;
    margin-bottom: 24px !important;
}

/* ── Dashboard Cards ─────────────────────────── */
.dashboard-card {
    background: var(--card-bg, var(--bg-card));
    border: 1px solid var(--card-border, var(--border-color));
    border-radius: var(--card-radius);
    overflow: hidden;
}
.dashboard-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.dashboard-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
.dashboard-card-body { padding: 20px; }

/* ── Activity Feed ───────────────────────────── */
.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}
.activity-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex: 1;
}
.activity-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================
   Stat Cards  (dashboard + summary rows)
   ============================================ */
.stat-card {
    background: var(--card-bg, var(--bg-card));
    border: 1px solid var(--card-border, var(--border-color));
    border-radius: var(--card-radius);
    padding: 20px;
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out), transform 0.2s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    border-color: var(--border-hover);
}

/* Subtle gradient stripe at top */
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity 0.2s var(--ease-out);
}
.stat-card:hover::before { opacity: 1; }

.stat-card .stat-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: lining-nums tabular-nums;
}

@media (min-width: 1200px) {
    .stat-card .stat-value { font-size: 1.9rem; }
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0;
}

.stat-card .stat-delta {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-success);
}

/* Stat icon colour variants */
/* Brand-tinted tile. The tint carries the colour; the glyph stays
   readable whatever hue the organisation chose. */
/* Stat-tile icon chips.
   These were named for the colours of the old violet palette (.icon-purple,
   .icon-cyan ...) and set a bright dark-mode text colour -- #67e8f9 cyan,
   #6ee7b7 mint -- on a 15%-alpha fill. In light mode that is pale text on
   near-white paper. They now derive from the semantic accent tokens, which
   are defined per theme, and are named for what they mean rather than for a
   hue the product no longer uses. */
.icon-brand   { background: color-mix(in srgb, var(--brand) 18%, transparent);
                color: var(--text-primary); }
.icon-info    { background: color-mix(in srgb, var(--accent-info) 15%, transparent);
                color: var(--accent-info); }
.icon-success { background: color-mix(in srgb, var(--accent-success) 15%, transparent);
                color: var(--accent-success); }
.icon-warning { background: color-mix(in srgb, var(--accent-warning) 15%, transparent);
                color: var(--accent-warning); }
.icon-danger  { background: color-mix(in srgb, var(--accent-danger) 15%, transparent);
                color: var(--accent-danger); }
.icon-blue   { background: rgba(59, 130, 246, 0.15); color: #93c5fd; }
.icon-indigo { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }

/* ============================================
   Forms
   ============================================ */
.form-control,
.form-select {
    background-color: var(--input-bg, var(--bg-secondary));
    border: 1px solid var(--input-border, var(--border-color));
    color: var(--text-primary);
    border-radius: var(--input-radius);
    padding: 0 12px;
    height: 38px;
    font-size: 0.875rem;
    transition: border-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
}

/* A select needs room on the right for its chevron. Bootstrap reserves it
   with padding-right: 2.25rem; the shared `padding: 0 12px` above replaced
   that, so a long option ran underneath the arrow. */
.form-select {
    padding-right: 34px;
}

/* The report filter bar lays its fields out in `col-auto` columns, where a
   child with Bootstrap's `width: 100%` resolves against a parent that is
   itself sizing to the child -- so the select settled far narrower than its
   own text and "All clients" spilled past its border with the chevron drawn
   over it. Giving the fields a real width range breaks the circularity, and
   the max stops a 50-character client name from sizing the whole row. */
#reportFilterForm .form-select,
#reportFilterForm .form-control {
    min-width: 148px;
    max-width: 220px;
    text-overflow: ellipsis;
}

textarea.form-control {
    height: auto;
    padding: 10px 12px;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--input-bg, var(--bg-secondary));
    border-color: color-mix(in srgb, var(--brand) 60%, transparent);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent);
    outline: none;
}

.form-control.is-invalid {
    border-color: var(--accent-danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.form-control::placeholder { color: var(--text-muted); }

.form-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.invalid-feedback {
    font-size: 0.78rem;
    color: var(--accent-danger);
}

.input-group-text {
    background: var(--input-bg, var(--bg-secondary));
    border-color: var(--input-border, var(--border-color));
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: var(--on-brand);
    box-shadow: none;
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--on-brand);
}

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.btn-success {
    background: var(--gradient-success);
    border: none;
    color: #fff;
}
.btn-success:hover { background: var(--accent-success); color: #fff; }

.btn-danger {
    background: var(--gradient-danger);
    border: none;
    color: #fff;
}
.btn-danger:hover { background: var(--accent-danger); color: #fff; }

.btn-warning {
    background: var(--gradient-warning);
    border: none;
    color: #1a1f2e;
}
.btn-warning:hover { background: var(--accent-warning); color: #1a1f2e; }

.btn-outline-primary {
    border: 1px solid var(--primary);
    color: var(--link);
    background: transparent;
}
.btn-outline-primary:hover {
    background: var(--primary-muted);
    color: var(--link);
    border-color: var(--primary);
}

.btn-outline-secondary {
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: transparent;
}
.btn-outline-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-outline-success  { border-color: var(--accent-success); color: var(--accent-success); }
.btn-outline-success:hover { background: rgba(16,185,129,0.12); color: var(--accent-success); }

.btn-outline-danger   { border-color: var(--accent-danger); color: var(--accent-danger); }
.btn-outline-danger:hover { background: rgba(239,68,68,0.12); color: var(--accent-danger); }

.btn-outline-warning  { border-color: var(--accent-warning); color: var(--accent-warning); }
.btn-outline-warning:hover { background: rgba(245,158,11,0.12); color: var(--accent-warning); }

.btn-outline-info     { border-color: var(--accent-info); color: var(--accent-info); }
.btn-outline-info:hover { background: rgba(6,182,212,0.12); color: var(--accent-info); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.7rem 1.5rem; font-size: 1rem; }

/* Icon vertical alignment inside buttons and nav links */
.btn .bi, .nav-link .bi, .row-action-btn .bi { vertical-align: -0.125em; }

/* Disabled button state */
.btn:disabled, .btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(30%);
    pointer-events: none;
}

/* Loading button — shows inline spinner, hides text */
.btn-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
    opacity: 0.85;
}
.btn-loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    top: calc(50% - 7px);
    left: calc(50% - 7px);
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
.btn-outline-secondary.btn-loading::after,
.btn-secondary.btn-loading::after {
    border-color: rgba(100,116,139,0.35);
    border-top-color: var(--text-secondary);
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ============================================
   Tables
   ============================================ */
.table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: color-mix(in srgb, var(--brand) 5%, transparent);
    color: var(--text-primary);
    font-size: 0.875rem;
    margin: 0;
}

.table > thead > tr > th {
    background: var(--bg-quaternary, var(--bg-tertiary));
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0;
    border-bottom: 1px solid var(--border-light);
    padding: 0 16px;
    height: 40px;
    vertical-align: middle;
    white-space: nowrap;
}

.table > tbody > tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.1s var(--ease-out);
}

.table > tbody > tr > td {
    padding: 0 16px;
    height: var(--table-row-height);
    vertical-align: middle;
    color: var(--text-primary);
}

.table > tbody > tr:last-child { border-bottom: none; }
.table > tbody > tr:hover { background: var(--bs-table-hover-bg); }

/* Table inside a card — remove outer border so card border suffices */
.card .table { border-radius: 0; }
.card .table-responsive { border-radius: 0 0 var(--card-radius) var(--card-radius); overflow: hidden; }
.table-card .table { border-radius: 0; }

/* ── Row Actions (revealed on hover) ─────────── */
.row-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0.55;
    transition: opacity 0.15s var(--ease-out);
}
tr:hover .row-actions { opacity: 1; }

.row-action-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}
.row-action-btn:hover {
    background: var(--bg-quaternary, var(--bg-tertiary));
    color: var(--text-primary);
}
.row-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
}
.row-action-btn.primary:hover {
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    color: var(--link);
}

/* ── Overdue task row & flagged client row — deeper red with left accent ── */
tr.task-overdue,
tr.client-flagged {
    background: rgba(220, 38, 38, 0.12) !important;
    border-left: 3px solid var(--accent-danger, #dc2626);
}
tr.task-overdue:hover,
tr.client-flagged:hover {
    background: rgba(220, 38, 38, 0.18) !important;
}

/* Light theme: slightly stronger tint for better contrast on white */
[data-bs-theme="light"] tr.task-overdue,
[data-bs-theme="light"] tr.client-flagged {
    background: rgba(220, 38, 38, 0.09) !important;
}
[data-bs-theme="light"] tr.task-overdue:hover,
[data-bs-theme="light"] tr.client-flagged:hover {
    background: rgba(220, 38, 38, 0.15) !important;
}

/* ── Topbar settings-active state ───────────── */
.theme-toggle.settings-active {
    background: var(--bg-tertiary);
    color: var(--link);
    border-color: var(--primary);
}

/* ── Settings Hub cards ──────────────────────── */
.settings-card {
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
}
.settings-card:hover {
    border-color: color-mix(in srgb, var(--brand) 40%, transparent);
    box-shadow: var(--shadow-glow);
}
.settings-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--brand) 12%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
    color: var(--link);
}
[data-bs-theme="light"] .settings-card-icon {
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    color: var(--primary);
}

/* ── Reference codes ─────────────────────────── */
.ref-code {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    color: var(--link);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    display: inline-block;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.ref-code:hover { background: color-mix(in srgb, var(--brand) 20%, transparent); }
.ref-code.copied { background: rgba(16,185,129,0.15); color: #6ee7b7; }

/* ============================================
   Badges
   ============================================ */
.badge {
    padding: 0.3rem 0.6rem;
    font-weight: 600;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    border-radius: var(--radius-sm);
}

/* Status-semantic badge colours */
.badge.bg-success,
.badge.text-bg-success { background: rgba(16,185,129,0.18) !important; color: #34d399 !important; }

.badge.bg-danger,
.badge.text-bg-danger  { background: rgba(239,68,68,0.18) !important; color: #f87171 !important; }

.badge.bg-warning,
.badge.text-bg-warning { background: rgba(245,158,11,0.18) !important; color: #fbbf24 !important; }

.badge.bg-info,
.badge.text-bg-info    { background: rgba(6,182,212,0.18) !important; color: #22d3ee !important; }

.badge.bg-primary,
.badge.text-bg-primary { background: color-mix(in srgb, var(--brand) 22%, transparent) !important; color: var(--text-primary) !important; }

.badge.bg-secondary,
.badge.text-bg-secondary { background: var(--bg-tertiary) !important; color: var(--text-secondary) !important; }

/* ============================================
   Alerts
   ============================================ */
.alert {
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.875rem;
    padding: 0.875rem 1rem;
}

.alert-success { background: rgba(16,185,129,0.12); color: #34d399; }
.alert-danger  { background: rgba(239,68,68,0.12);  color: #f87171; }
.alert-warning { background: rgba(245,158,11,0.12); color: #fbbf24; }
.alert-info    { background: rgba(6,182,212,0.12);  color: #22d3ee; }

/* ============================================
   Pagination
   ============================================ */
.pagination { gap: 3px; }

.pagination .page-link {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-md) !important;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
}

.pagination .page-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.pagination .page-item.active .page-link {
    background: var(--gradient-primary);
    border-color: transparent;
    color: #fff;
}

.pagination .page-item.disabled .page-link { opacity: 0.4; }

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 2.75rem;
    opacity: 0.4;
    margin-bottom: 0.875rem;
    display: block;
}

.empty-state h5 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.empty-state p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

/* ============================================
   Theme Toggle
   ============================================ */
/* Topbar shadow on scroll — JS adds .topbar-scrolled */
.top-navbar.topbar-scrolled {
    box-shadow: var(--shadow-md);
    border-bottom-color: transparent;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    opacity: 0.75;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-light);
    opacity: 1;
}

/* ============================================
   List Group
   ============================================ */
.list-group-item {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
    font-size: 0.875rem;
    padding: 0.75rem 1rem;
}

.list-group-item:hover { background: var(--bg-tertiary); }

.list-group-flush .list-group-item:last-child { border-bottom: none; }

/* ============================================
   Dropdown
   ============================================ */
.dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0.4rem;
    font-size: 0.875rem;
}

.dropdown-item {
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-divider { border-color: var(--border-color); margin: 0.3rem 0; }

/* ============================================
   Modal
   ============================================ */
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.btn-close { filter: invert(1); opacity: 0.6; }
.btn-close:hover { opacity: 1; }
[data-bs-theme="light"] .btn-close { filter: none; }

/* ============================================
   Pipeline / Kanban
   ============================================ */
.pipeline-board {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    align-items: flex-start;
}

.pipeline-column {
    min-width: 270px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    flex-shrink: 0;
}

.column-header {
    background: var(--bg-tertiary);
    padding: 0.875rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.column-cards {
    padding: 0.75rem;
    min-height: 160px;
}

.pipeline-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.875rem;
    margin-bottom: 0.5rem;
    cursor: grab;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    font-size: 0.875rem;
}

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

.pipeline-card:active { cursor: grabbing; }

/* ============================================
   Chart Container
   ============================================ */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

/* ============================================
   Theme-aware helpers
   ============================================ */
.table-header { background: var(--bg-tertiary); color: var(--text-primary); }
[data-bs-theme="dark"]  .table-header { background: var(--bg-tertiary); }
[data-bs-theme="light"] .table-header { background: #e8edf5; }

/* Legacy alias — use .ref-code for new templates */
.reference-code {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    background: color-mix(in srgb, var(--brand) 10%, transparent);
    color: var(--link);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    display: inline-block;
    letter-spacing: 0.02em;
}

/* ============================================
   Links
   ============================================ */
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }

/* ============================================
   Text utilities
   ============================================ */
.text-muted    { color: var(--text-muted)     !important; }
.text-secondary{ color: var(--text-secondary) !important; }

/* ============================================
   Scrollbars
   ============================================ */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: var(--radius-xs); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================
   Tom Select
   ============================================ */
.ts-wrapper { --ts-pr-caret: 2rem; }

.ts-control {
    background: var(--bg-tertiary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 0.45rem 0.75rem !important;
    min-height: calc(1.5em + 0.75rem + 2px);
    border-radius: var(--radius-md) !important;
}

.ts-control:focus,
.ts-wrapper.focus .ts-control {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent) !important;
}

.ts-control input            { color: var(--text-primary) !important; }
.ts-control input::placeholder { color: var(--text-muted) !important; }

.ts-dropdown {
    background: var(--bg-card) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md) !important;
}

.ts-dropdown .option               { color: var(--text-primary); padding: 0.45rem 0.875rem; }
.ts-dropdown .option:hover,
.ts-dropdown .option.active        { background: var(--primary-muted) !important; color: var(--link) !important; }
.ts-dropdown .option.selected      { background: var(--bg-tertiary); }
.ts-dropdown .no-results           { color: var(--text-muted); padding: 0.875rem; }

/* ============================================
   Light mode — softer badge tints
   ============================================ */
[data-bs-theme="light"] .badge.bg-success,
[data-bs-theme="light"] .badge.text-bg-success { background: rgba(16,185,129,0.12) !important; color: #059669 !important; }
[data-bs-theme="light"] .badge.bg-danger,
[data-bs-theme="light"] .badge.text-bg-danger  { background: rgba(239,68,68,0.12)  !important; color: #dc2626 !important; }
[data-bs-theme="light"] .badge.bg-warning,
[data-bs-theme="light"] .badge.text-bg-warning { background: rgba(245,158,11,0.12) !important; color: #d97706 !important; }
[data-bs-theme="light"] .badge.bg-info,
[data-bs-theme="light"] .badge.text-bg-info    { background: rgba(6,182,212,0.12)  !important; color: #0891b2 !important; }
[data-bs-theme="light"] .badge.bg-primary,
[data-bs-theme="light"] .badge.text-bg-primary { background: color-mix(in srgb, var(--brand) 30%, transparent) !important; color: var(--ink) !important; }

/* ============================================
   Modal & overlay polish
   ============================================ */
.modal-backdrop {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.55);
}
.offcanvas-backdrop {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.55);
}

/* ============================================
   Animations & Keyframes
   ============================================ */

/* Toast slide-in from right */
@keyframes toast-slide-in {
    from { transform: translateX(calc(100% + 1.5rem)); opacity: 0; }
    to   { transform: translateX(0);                  opacity: 1; }
}
.toast { animation: toast-slide-in 0.3s var(--ease-out); }

/* Notification badge pulse (triggered when .has-new class added by JS) */
@keyframes notif-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0.6); }
    60%  { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0);   }
}
.notif-badge.has-new { animation: notif-pulse 1.2s ease-out 2; }

/* Skeleton loader shimmer */
@keyframes skeleton-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position:  400px 0; }
}
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-quaternary) 25%,
        var(--border-color)  50%,
        var(--bg-quaternary) 75%
    );
    background-size: 800px 100%;
    animation: skeleton-shimmer 1.6s ease-in-out infinite;
    border-radius: var(--radius-xs);
    display: inline-block;
}

/* ============================================
   Responsive — Mobile Sidebar
   ============================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }

    .sidebar.mobile-open { transform: translateX(0); }

    .main-content.with-sidebar,
    .main-content.expanded { margin-left: 0; }

    .sidebar.mobile-open::after {
        content: '';
        position: fixed;
        top: 0; right: 0; bottom: 0;
        left: var(--sidebar-width);
        background: rgba(0, 0, 0, 0.55);
        z-index: -1;
    }

    .pipeline-board { padding-bottom: 1.5rem; }
}

@media (max-width: 575.98px) {
    .content-area .container-fluid { padding-left: 0.875rem; padding-right: 0.875rem; }
    .stat-card .stat-value { font-size: 1.5rem; }
}

/* ── Sidebar SVG logo ──────────────────────────────────────────────────────── */
.sidebar-logo-img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    transition: filter 0.2s ease;
}

.sidebar-brand:hover .sidebar-logo-img {
    filter: brightness(1.25);
}

/* Collapsed sidebar: hide brand text but keep logo visible */
.sidebar.collapsed .sidebar-logo-img {
    margin: 0 auto;
}

/* ── Tenant name pill in top navbar ───────────────────────────────────────── */
.tenant-name-badge {
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    padding: 0.28em 0.75em;
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}


/* ============================================
   Form helpers
   ============================================
   .form-helper-text and .form-section-header are used 22 times across
   the client, project and contact forms and had no rule anywhere, so
   every help string rendered unstyled. */
.form-helper-text {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--text-sm);
    line-height: 1.45;
    color: var(--text-muted);
}
.form-section-header {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
}

/* Collapsible form sections (static/js/collapsible-sections.js). The
   heading's text becomes a full-width button; the chevron turns when closed. */
.section-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.section-toggle:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 4px;
    border-radius: var(--radius-sm);
}
.section-toggle-icon {
    margin-left: auto;
    font-size: var(--text-sm);
    color: var(--text-muted);
    transition: transform 0.15s ease;
}
.card.is-collapsed .section-toggle-icon { transform: rotate(-90deg); }
.card.is-collapsed > .card-header { border-bottom: 0; }
@media (prefers-reduced-motion: reduce) {
    .section-toggle-icon { transition: none; }
}

/* Required marker. Derived from the form, not hand-typed per field. */
.form-label .req {
    color: var(--accent-danger);
    font-weight: 600;
    margin-left: 2px;
}

/* Skip link: the sidebar is 20+ items, and a keyboard user had to
   traverse all of it on every page to reach the content. */
.skip-link {
    position: absolute;
    left: var(--space-2);
    top: -3rem;
    z-index: 2000;
    padding: var(--space-2) var(--space-4);
    background: var(--brand);
    color: var(--on-brand);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    transition: top var(--transition-speed) var(--ease-out);
}
.skip-link:focus { top: var(--space-2); color: var(--on-brand); }


/* One mark per ground. The carbon hexagon disappears on paper and the
   ink one disappears on ink, so each theme shows its own. */
.logo-on-paper { display: none; }
[data-bs-theme="light"] .logo-on-ink   { display: none; }
[data-bs-theme="light"] .logo-on-paper { display: inline-block; }


/* ============================================
   Narrow widths
   ============================================
   Neither of these apps had a single media query or responsive utility,
   so at phone width the page itself scrolled sideways: the filter bar,
   the status button group and the table all pushed past the viewport,
   taking the footer and the page's primary action with them.

   A table that is genuinely too wide should scroll inside its own
   container. The page should not. */
.main-content,
.content-area,
.content-area > .container-fluid { min-width: 0; max-width: 100%; }

/* overflow:visible let the table escape its wrapper entirely, which is
   what turned a wide table into a wide page. */
.table-card { overflow: hidden; }
.table-responsive { max-width: 100%; overflow-x: auto; }

@media (max-width: 767.98px) {
    .page-header > div { min-width: 0; }
    .page-header .btn { white-space: nowrap; }

    /* Filter controls stack; the segmented status control spans the row
       rather than overflowing it. */
    .filter-bar .btn-group { width: 100%; }
    .filter-bar .btn-group .btn { flex: 1 1 0; }
    .filter-bar .row > [class*="col-"] { margin-bottom: var(--space-2); }

    .table-footer { flex-wrap: wrap; gap: var(--space-2); }
}


/* Columns worth having on a wide screen and not worth sideways scrolling
   for on a narrow one. Marked on both the th and the matching td.
   Everything still reachable: the row links through to the record. */
@media (max-width: 991.98px) {
    .table th.col-optional,
    .table td.col-optional { display: none; }
}


/* Segmented control. Which view you are on is *state*, not an action, so
   the active segment is a surface change rather than the accent -- the
   accent belongs to the one thing on the page worth doing. */
.segmented .btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
}
.segmented .btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.segmented .btn[aria-current="page"] {
    background: var(--bg-quaternary);
    color: var(--text-primary);
    font-weight: 600;
    border-color: var(--border-light);
}


/* Stat tiles. The fill used to come from seven .icon-* classes holding
   hardcoded pastels, assigned per metric in the view -- two unrelated
   metrics shared "green", so the hue carried no meaning. One quiet
   treatment; the icon inside is what distinguishes them. */
.stat-icon {
    background: color-mix(in srgb, var(--brand) 16%, transparent);
    color: var(--text-primary);
}
