/* ============================================================
   Revenue Governance System (RGS) — X86 Network
   Main Stylesheet
   ============================================================ */

/* ---- Design tokens (x86DESIGN.md, v1.26.0) ----
   --rgs-primary / --rgs-primary-rgb / --rgs-sidebar come from System Settings
   (themeCssVars() in core/helpers.php, printed by layouts/main.php and
   auth/login.php). Everything themed reads the tokens below, never a hex. */
:root {
    /* Brand */
    --primary: var(--rgs-primary, #5865F2);
    --primary-rgb: var(--rgs-primary-rgb, 88, 101, 242);
    --primary-dark: color-mix(in srgb, var(--primary) 82%, #000);
    --primary-tint: color-mix(in srgb, var(--primary) 8%, #fff);
    --accent: color-mix(in srgb, var(--primary) 55%, #fff);
    --success: #10B981;
    --success-rgb: 16, 185, 129;
    --success-dark: #059669;
    --success-tint: #ecfdf5;
    --warning: #ffc107;
    --warning-dark: #d97706;
    --danger: #dc3545;
    --danger-dark: #dc2626;

    /* Slate scale */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* Surfaces */
    --sidebar-bg: var(--rgs-sidebar, var(--slate-900));
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-active: rgba(var(--primary-rgb), .18);
    --sidebar-width: 240px;
    --topbar-height: 64px;
    --text-muted: #8a9bb0;
    --card-bg: #fff;
    --body-bg: var(--slate-50);
    --border-color: var(--slate-200);

    /* Type */
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    /* Shape, depth, motion */
    --radius-card: 24px;
    --radius-control: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, .08), 0 8px 10px -6px rgba(15, 23, 42, .06);
    --shadow-glow: 0 12px 32px -8px rgba(var(--primary-rgb), .18);
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --dur: 400ms;
    --dur-fast: 150ms;

    /* Bootstrap 5.3 hooks. Not --bs-body-bg: cards, inputs and modals use it. */
    --bs-primary: var(--primary);
    --bs-primary-rgb: var(--primary-rgb);
    --bs-success: var(--success);
    --bs-success-rgb: var(--success-rgb);
    --bs-link-color: var(--primary);
    --bs-link-color-rgb: var(--primary-rgb);
    --bs-link-hover-color: var(--primary-dark);
    --bs-link-hover-color-rgb: var(--primary-rgb);
    --bs-body-font-family: var(--font-sans);
    --bs-font-monospace: var(--font-mono);
    --bs-border-color: var(--border-color);
    --bs-focus-ring-color: rgba(var(--primary-rgb), .25);
    --bs-heading-color: var(--slate-900);
    /* Radii: controls/alerts/dropdowns 12px, small controls 8px, large 16px,
       cards and modals 24px (set on .card / .modal below). */
    --bs-border-radius: var(--radius-control);
    --bs-border-radius-sm: 8px;
    --bs-border-radius-lg: 16px;
    --bs-border-radius-xl: var(--radius-card);
    font-family: var(--font-sans);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--body-bg);
    color: var(--slate-800);
    font-family: var(--font-sans);
}

/* Numbers: mono with aligned digits (.num on any money/count). Right-aligned
   table cells are almost always figures, so they get aligned digits too. */
.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.table td.text-end,
.table th.text-end {
    font-variant-numeric: tabular-nums;
}

/* ---- Bootstrap components that hard-code their own blue/green ---- */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-color: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
}

.btn-success {
    --bs-btn-bg: var(--success);
    --bs-btn-border-color: var(--success);
    --bs-btn-hover-bg: var(--success-dark);
    --bs-btn-hover-border-color: var(--success-dark);
    --bs-btn-active-bg: var(--success-dark);
    --bs-btn-active-border-color: var(--success-dark);
    --bs-btn-disabled-bg: var(--success);
    --bs-btn-disabled-border-color: var(--success);
    --bs-btn-focus-shadow-rgb: var(--success-rgb);
}

.btn-outline-success {
    --bs-btn-color: var(--success-dark);
    --bs-btn-border-color: var(--success);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--success);
    --bs-btn-hover-border-color: var(--success);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--success-dark);
    --bs-btn-active-border-color: var(--success-dark);
    --bs-btn-disabled-color: var(--success);
    --bs-btn-disabled-border-color: var(--success);
    --bs-btn-focus-shadow-rgb: var(--success-rgb);
}

.nav-pills {
    --bs-nav-pills-link-active-bg: var(--primary);
}

.dropdown-menu {
    --bs-dropdown-link-active-bg: var(--primary);
}

.pagination {
    --bs-pagination-color: var(--primary);
    --bs-pagination-hover-color: var(--primary-dark);
    --bs-pagination-focus-color: var(--primary-dark);
    --bs-pagination-focus-box-shadow: 0 0 0 .25rem rgba(var(--primary-rgb), .25);
    --bs-pagination-active-bg: var(--primary);
    --bs-pagination-active-border-color: var(--primary);
}

.list-group {
    --bs-list-group-active-bg: var(--primary);
    --bs-list-group-active-border-color: var(--primary);
}

.progress,
.progress-stacked {
    --bs-progress-bar-bg: var(--primary);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.form-check-input:focus {
    border-color: color-mix(in srgb, var(--primary) 50%, #fff);
    box-shadow: 0 0 0 .25rem rgba(var(--primary-rgb), .25);
}

/* Motion off for people who ask for it (OS "reduce motion" setting). */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }

    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }

    /* Delayed entrances would still wait out their delay; drop them. */
    .stagger > *,
    .stagger .stat-value {
        animation: none !important;
    }

    .progress-shimmer .progress-bar::after {
        display: none;
    }
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    z-index: 1040;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: transform var(--dur) var(--ease);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--topbar-height);
    padding: 14px 18px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand-icon,
.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex-shrink: 0;
}

.brand-icon {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 6px 16px -4px rgba(var(--primary-rgb), .55);
}

.brand-logo {
    object-fit: contain;
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    letter-spacing: -.01em;
}

.brand-sub {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: .5px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px 20px;
}

.nav-section {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 14px 8px 4px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.nav-section::after {
    content: "\25BE";
    font-size: 9px;
    transition: transform var(--dur-fast) var(--ease);
}

.nav-section.collapsed::after {
    transform: rotate(-90deg);
}

/* Active link: a 4px primary bar on the left plus a primary tint (x86DESIGN.md
   "Sidebar Navigation", kept on the dark sidebar). The bar is a ::before so it
   follows the rounded corners and causes no layout shift. */
.sidebar-nav .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: #b0bec5;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sidebar-nav .nav-link i {
    width: 18px;
    text-align: center;
    font-size: 14px;
    transition: color var(--dur-fast) var(--ease);
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar-nav .nav-link.active i {
    color: var(--accent);
}

.sidebar-nav .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--primary);
}

/* ---- Main Wrapper ---- */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--dur) var(--ease);
}

/* ---- Topbar: frosted white glass over the scrolling content ---- */
.topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, .8);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-title {
    color: var(--slate-900);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -.01em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .btn-link {
    --bs-btn-color: var(--slate-600);
    --bs-btn-hover-color: var(--primary);
    --bs-btn-active-color: var(--primary);
    font-size: 18px;
    text-decoration: none;
}

.topbar .dropdown-toggle {
    font-size: 13.5px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-control);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.topbar .dropdown-toggle:hover,
.topbar .dropdown-toggle.show {
    background: var(--slate-100);
}

.topbar .dropdown-toggle:active {
    transform: scale(.95);
}

.sidebar-toggle {
    display: none;
}

/* ---- Content Area ---- */
.content-area {
    flex: 1;
    padding: 24px;
}

/* ---- Footer ---- */
.app-footer {
    background: transparent;
    border-top: 1px solid var(--border-color);
    padding: 14px 24px;
    font-size: 11px;
    color: var(--slate-500);
}

/* ---- Cards (24px radius, soft shadow) ----
   Set through Bootstrap's card variables so headers, footers and list groups
   get the matching inner radius on their own. No overflow:hidden here: it
   would clip the combobox/dropdown menus that open inside form cards. */
h1, h2, h3, h4, h5, h6 {
    letter-spacing: -.01em;
}

.card {
    --bs-card-border-radius: var(--radius-card);
    --bs-card-inner-border-radius: calc(var(--radius-card) - 1px);
    --bs-card-border-color: var(--border-color);
    --bs-card-spacer-y: 1.25rem;
    --bs-card-spacer-x: 1.5rem;
    --bs-card-cap-padding-y: .9rem;
    --bs-card-cap-padding-x: 1.5rem;
    --bs-card-cap-bg: transparent;
    box-shadow: var(--shadow-sm);
}

.card-header {
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--slate-900);
}

/* Table flush inside a card: round the scroll box so header and hover rows
   don't poke square corners out of the card. .table-responsive already
   clips its content, so this adds no new clipping. */
.card > .card-body.p-0:last-child > .table-responsive:last-child,
.card > .table-responsive:last-child {
    border-bottom-left-radius: var(--bs-card-inner-border-radius);
    border-bottom-right-radius: var(--bs-card-inner-border-radius);
}

.card > .card-body.p-0:first-child > .table-responsive:first-child,
.card > .table-responsive:first-child {
    border-top-left-radius: var(--bs-card-inner-border-radius);
    border-top-right-radius: var(--bs-card-inner-border-radius);
}

/* Cards that are links lift with a primary glow on hover. Form cards stay
   still, so typing never makes the page move. */
a > .card,
a.card {
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

a:hover > .card,
a.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}

/* ---- Modals & dropdowns ---- */
.modal {
    --bs-modal-border-radius: var(--radius-card);
    --bs-modal-inner-border-radius: calc(var(--radius-card) - 1px);
    --bs-modal-border-color: var(--border-color);
    --bs-modal-box-shadow: var(--shadow-xl);
}

.dropdown-menu {
    --bs-dropdown-border-color: var(--border-color);
    --bs-dropdown-box-shadow: var(--shadow-xl);
    --bs-dropdown-link-hover-bg: var(--slate-100);
    --bs-dropdown-font-size: 13.5px;
    box-shadow: var(--bs-dropdown-box-shadow);
    padding: 6px;
}

.dropdown-item {
    border-radius: 8px;
}

/* Numbered step header used across the Quotation form's sections */
.card-header-step {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    row-gap: 6px;
}

.card-header-step .step-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--rgs-primary, var(--primary));
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

/* Quotation Summary sidebar: sticky only once the layout has room (desktop) */
@media (min-width: 768px) {
    .summary-card {
        position: sticky;
        top: 80px;
    }
}

/* ---- KPI Stat Cards ---- */
.stat-card {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius-card);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}

/* The text column may shrink, so long figures wrap instead of overflowing. */
.stat-card > :not(.stat-icon) {
    min-width: 0;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: color-mix(in srgb, var(--primary) 12%, #fff);
    color: var(--primary);
}

.stat-icon.green {
    background: #d1fae5;
    color: var(--success-dark);
}

.stat-icon.orange {
    background: #ffedd5;
    color: #ea580c;
}

.stat-icon.purple {
    background: #f3e8ff;
    color: #9333ea;
}

.stat-icon.red {
    background: #fee2e2;
    color: #dc2626;
}

.stat-icon.teal {
    background: #ccfbf1;
    color: #0f766e;
}

.stat-label {
    font-size: 12.5px;
    color: var(--slate-500);
    font-weight: 500;
}

/* 30px on wide screens (x86DESIGN.md), scaling down so currency still fits
   a narrow card. Inline font-size overrides on a few pages still win. */
.stat-value {
    font-size: clamp(20px, 1rem + .9vw, 30px);
    font-weight: 700;
    color: var(--slate-900);
    line-height: 1.15;
    letter-spacing: -.02em;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

/* Smaller figure for text-like values (durations such as "2h 15m"). */
.stat-value.stat-value-sm {
    font-size: clamp(16px, .9rem + .4vw, 20px);
}

.stat-sub {
    font-size: 12px;
    color: var(--slate-400);
    margin-top: 2px;
}

/* Optional change chip pinned top-right: <span class="stat-badge up">+4%</span> */
.stat-badge {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--slate-100);
    color: var(--slate-600);
}

.stat-card:has(> .stat-badge) > div:last-child {
    padding-right: 52px;
}

.stat-badge.up {
    background: var(--success-tint);
    color: var(--success-dark);
}

.stat-badge.down {
    background: #fef2f2;
    color: var(--danger-dark);
}

.stat-trend {
    font-size: 11.5px;
    font-weight: 600;
    margin-top: 4px;
}

/* ---- KPI Grid (unified stat-card layout with grouped section labels) ---- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-grid .kpi-group-label {
    grid-column: 1 / -1;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: .02em;
}

.kpi-grid .kpi-group-label:not(:first-child) {
    margin-top: .25rem;
}

.kpi-grid .stat-card {
    height: 100%;
}

@media (max-width: 576px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---- Tables ---- */
.table {
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: rgba(var(--primary-rgb), .04);
    font-size: 13.5px;
}

.table thead th {
    background: var(--slate-50);
    font-weight: 600;
    font-size: 11.5px;
    letter-spacing: .04em;
    color: var(--slate-500);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    padding: 11px 14px;
}

.table thead th a {
    color: inherit;
    text-decoration: none;
}

.table td {
    padding: 11px 14px;
    vertical-align: middle;
    border-color: var(--border-color);
}

/* Flush tables (card-body p-0) line their outer columns up with the card
   header's 1.5rem inset. Phone-width stacked tables keep their own padding. */
.card-body.p-0 > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :first-child,
.card-body.p-0 > .table:not(.stack-table) > :not(caption) > * > :first-child,
.card > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :first-child {
    padding-left: 1.5rem;
}

.card-body.p-0 > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :last-child,
.card-body.p-0 > .table:not(.stack-table) > :not(caption) > * > :last-child,
.card > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :last-child {
    padding-right: 1.5rem;
}

/* ---- Badges ---- */
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 999px;
    letter-spacing: .01em;
}

.bg-role-admin {
    background: #7c3aed !important;
}

.bg-role-manager {
    background: #0369a1 !important;
}

.bg-role-sales {
    background: #047857 !important;
}

.bg-role-ops {
    background: #b45309 !important;
}

.bg-role-finance {
    background: #dc2626 !important;
}

/* ---- Buttons: 12px radius (from --bs-border-radius), press-in on click ---- */
.btn {
    font-size: 13px;
    font-weight: 500;
    transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease),
        border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
        transform var(--dur-fast) var(--ease);
}

.btn-primary,
.btn-success,
.btn-danger {
    font-weight: 600;
}

.btn:active:not(:disabled):not(.disabled) {
    transform: scale(.95);
}

/* ---- Workflow Stage Indicator ---- */
.workflow-steps {
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.workflow-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--slate-100);
    border-radius: 0;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--slate-500);
    position: relative;
}

.workflow-step:first-child {
    border-radius: var(--radius-control) 0 0 var(--radius-control);
}

.workflow-step:last-child {
    border-radius: 0 var(--radius-control) var(--radius-control) 0;
}

.workflow-step.done {
    background: #d1fae5;
    color: #065f46;
}

.workflow-step.active {
    background: color-mix(in srgb, var(--primary) 14%, #fff);
    color: var(--primary-dark);
    font-weight: 700;
}

.workflow-step.pending {
    background: var(--slate-100);
    color: var(--slate-400);
}

/* ---- Revenue Leakage Indicators ---- */
.leakage-alert {
    border-left: 4px solid #dc3545;
}

/* ---- Margin display ---- */
.margin-good {
    color: var(--success-dark);
    font-weight: 600;
}

.margin-warn {
    color: var(--warning-dark);
    font-weight: 600;
}

.margin-danger {
    color: var(--danger-dark);
    font-weight: 700;
}

/* ---- Forms ---- */
.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--slate-700);
}

/* Radius comes from --bs-border-radius(-sm): 12px, 8px for -sm controls. */
.form-control,
.form-select {
    font-size: 13.5px;
    border-color: var(--border-color);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .15);
}

.input-group-text {
    background: var(--slate-50);
    border-color: var(--border-color);
    color: var(--slate-500);
}

/* ---- Quotation builder: line items ---- */
.line-item-row {
    background: var(--slate-50);
    border-radius: var(--radius-control);
    padding: 12px;
    margin-bottom: 8px;
}

.line-item-row .line-margin {
    font-size: 12px;
    font-weight: 600;
}

/* ---- Tabs ---- */
.nav-tabs {
    border-bottom: 2px solid var(--border-color);
}

.nav-tabs .nav-item .nav-link {
    color: var(--slate-500) !important;
    font-weight: 500;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 16px;
    margin-bottom: -2px;
    background-color: transparent !important;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.nav-tabs .nav-item .nav-link:hover {
    color: var(--primary) !important;
}

.nav-tabs .nav-item .nav-link.active {
    color: var(--primary) !important;
    font-weight: 600;
    border-bottom: 2px solid var(--primary) !important;
    background-color: transparent !important;
}

/* ---- Section Divider ---- */
.section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 20px 0 14px;
}

.section-divider span {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}

.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

/* ---- Login page ---- */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, color-mix(in srgb, var(--sidebar-bg) 60%, var(--primary)) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: #fff;
    border-radius: var(--radius-card);
    padding: 44px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .35);
}

.login-logo {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: #fff;
    margin: 0 auto 20px;
}

/* ---- Page header ---- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 22px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--slate-900);
    letter-spacing: -.02em;
    margin: 0;
}

/* Edit pages (v1.17.4): the header holding Back / Save / Save & go back
   (app/views/partials/edit_actions.php) stays in view under the topbar while a
   long form scrolls, since the form itself no longer has save buttons. */
.page-header:has(.edit-actions) {
    position: sticky;
    top: var(--topbar-height);
    z-index: 1020;
    background: var(--body-bg);
    padding-block: 10px;
    margin-bottom: 12px;
    box-shadow: 0 1px 0 var(--border-color);
}

/* ---- Typography utilities ----
   The type scale for small text. Use these instead of inline font-size
   (v1.26.4 cleanup mapped 11.5px to xs, and 12.5/13.5px to sm). */
.text-3xs { font-size: 10px; }
.text-2xs { font-size: 11px; }
.text-xs  { font-size: 12px; }
.text-sm  { font-size: 13px; }
.text-md  { font-size: 14px; }

/* Preformatted values (IP details, serials) that should wrap like text. */
.pre-wrap { white-space: pre-wrap; }

/* Faint panel tints (A-End / B-End blocks on Ops Validation). */
.tint-primary { background: rgba(var(--primary-rgb), .05); }
.tint-slate   { background: var(--slate-50); }

/* An optional sub-panel (e.g. B-End fields on the Ops Validation checklist). */
.panel-optional {
    border-color: var(--slate-400) !important;
    background: var(--slate-50);
}

/* A sticky side card that sits just under the topbar. */
.sticky-below-topbar {
    position: sticky;
    top: calc(var(--topbar-height) + 16px);
}

/* ---- Responsive ---- */
@media (max-width: 992px) {
    /* Tablet: tighten content padding */
    .content-area {
        padding: 18px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block !important;
    }

    .content-area {
        padding: 14px;
    }

    .card {
        --bs-card-spacer-x: 1rem;
        --bs-card-cap-padding-x: 1rem;
    }

    .card-body.p-0 > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :first-child,
    .card-body.p-0 > .table:not(.stack-table) > :not(caption) > * > :first-child,
    .card > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :first-child {
        padding-left: 1rem;
    }

    .card-body.p-0 > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :last-child,
    .card-body.p-0 > .table:not(.stack-table) > :not(caption) > * > :last-child,
    .card > .table-responsive > .table:not(.stack-table) > :not(caption) > * > :last-child {
        padding-right: 1rem;
    }

    .page-header h1 {
        font-size: 18px;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
        padding: 14px 10px;
        gap: 8px;
        height: 100%;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 17px;
        border-radius: 10px;
    }

    .stat-card .stat-value {
        font-size: 18px;
    }

    .stat-card .stat-sub,
    .stat-card .stat-trend {
        display: none; /* save vertical space on phones */
    }

    /* Stacked & centred on phones: the chip sits above the icon's corner. */
    .stat-card:has(> .stat-badge) > div:last-child {
        padding-right: 0;
    }

    .workflow-steps {
        flex-direction: column;
    }

    .workflow-step {
        border-radius: 8px !important;
        width: 100%;
    }

    /* Line Items / Build Cost tables: stacked cards instead of horizontal
       scroll. Each <td> pulls its column label from data-label via ::before —
       set on both the JS-built rows (RGS.addRow/addBuildCostRow) and the
       server-rendered read-only rows on the Quotation detail page. */
    .stack-table thead {
        display: none;
    }

    .stack-table, .stack-table tbody, .stack-table tr, .stack-table td {
        display: block;
        width: 100%;
    }

    .stack-table tr {
        border-bottom: 1px solid var(--border-color);
        padding: 10px 0;
    }

    .stack-table tr:last-child {
        border-bottom: none;
    }

    .stack-table td {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 4px 0;
        border: none !important;
        text-align: left !important;
    }

    .stack-table td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: .4px;
    }

    /* Plain-value cells (no form control inside, e.g. the read-only detail
       page) read better as a label + value row than fully stacked. */
    .stack-table td:not(:has(input, select, textarea, button)) {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .2);
    border-radius: 4px;
}

/* ── Cross-document View Transitions ──────────────────────────────────────
   Supported: Chrome 111+, Edge 111+, Firefox 131+. Falls back silently.

   Strategy:
   - sidebar-brand + topbar: non-scrolling chrome → locked in place (no anim)
   - main-content: fade + slide on entry
   - root (sidebar nav links, footer): animation:none → instant swap
     This is critical: the scrollable #sidebar must NOT have its own
     view-transition-name. If it did, the browser would snapshot it at
     scroll-position X (old page) vs 0 (new page) and that mismatch is
     exactly what causes the flash after a few clicks.                        */

@view-transition {
    navigation: auto;
}

/* Lock non-scrolling chrome in place */
.sidebar-brand {
    view-transition-name: sidebar-brand;
}
.topbar {
    view-transition-name: topbar;
}
::view-transition-old(sidebar-brand),
::view-transition-new(sidebar-brand),
::view-transition-old(topbar),
::view-transition-new(topbar) {
    animation: none;
}

/* Content area: fade + slide in */
.content-area {
    view-transition-name: main-content;
}
/* Opacity-only — no transform. transform:translateY(0) creates a stacking
   context even at zero offset, which traps Bootstrap modals behind the
   backdrop. Opacity:1 at the end does NOT create a stacking context. */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to  { opacity: 0; } }
::view-transition-old(main-content) { animation: 80ms  ease-out both fade-out; }
::view-transition-new(main-content) { animation: 150ms ease-out both fadeIn;   }

/* Root layer (sidebar nav links, footer, etc.): instant swap — no animation.
   The active link just appears in the correct state immediately. */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
}

/* ---- Dashboard motion (x86DESIGN.md, v1.26.3) ----
   .stagger on a row/grid: its children fade up one after another, 100ms
   apart. Set --stagger-offset on a later row so it starts after the rows
   above. Only on dashboards: list pages re-render on every filter change,
   and replaying this there would be noise.
   fill-mode "backwards" (never "both"/"forwards"): the end transform must
   not stick, or it creates a stacking context that traps modals. */
@keyframes rgs-fade-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: none; }
}

@keyframes rgs-pop {
    from { transform: scale(.95); filter: blur(2px); opacity: .4; }
    to   { transform: none; filter: none; opacity: 1; }
}

.stagger > * {
    animation: rgs-fade-up 600ms var(--ease) backwards;
    animation-delay: var(--stagger-offset, 0ms);
}
.stagger > :nth-child(2)  { animation-delay: calc(var(--stagger-offset, 0ms) + 100ms); }
.stagger > :nth-child(3)  { animation-delay: calc(var(--stagger-offset, 0ms) + 200ms); }
.stagger > :nth-child(4)  { animation-delay: calc(var(--stagger-offset, 0ms) + 300ms); }
.stagger > :nth-child(5)  { animation-delay: calc(var(--stagger-offset, 0ms) + 400ms); }
.stagger > :nth-child(6)  { animation-delay: calc(var(--stagger-offset, 0ms) + 500ms); }
.stagger > :nth-child(7)  { animation-delay: calc(var(--stagger-offset, 0ms) + 600ms); }
.stagger > :nth-child(n+8) { animation-delay: calc(var(--stagger-offset, 0ms) + 700ms); }

.stagger .stat-value {
    animation: rgs-pop 500ms var(--ease) 250ms backwards;
}

/* ---- Shimmering progress bar (rankings / funnels) ----
   <div class="progress progress-shimmer"><div class="progress-bar …"></div></div> */
.progress-shimmer {
    height: 8px;
    background: var(--slate-100);
    border-radius: 999px;
}

.progress-shimmer .progress-bar {
    position: relative;
    overflow: hidden;
    border-radius: 999px;
}

.progress-shimmer .progress-bar::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -100%;
    width: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .4), transparent);
    animation: rgs-shimmer 2s linear infinite;
}

@keyframes rgs-shimmer {
    to { left: 100%; }
}

/* ---- Pill / tag input (RGS.tagInput, v1.19.0) ---- */
.tag-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 31px;
    padding: 3px 6px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--bs-border-radius-sm);
    cursor: text;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.tag-input:focus-within { border-color: color-mix(in srgb, var(--primary) 50%, #fff); box-shadow: 0 0 0 .2rem rgba(var(--primary-rgb), .15); }
.tag-input.is-invalid { border-color: var(--danger); }
.tag-input .tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 4px 1px 8px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
    color: var(--primary-dark);
    background: color-mix(in srgb, var(--primary) 12%, #fff);
    border-radius: 999px;
    white-space: nowrap;
}
.tag-input .tag-pill button {
    border: 0;
    background: transparent;
    color: inherit;
    opacity: .6;
    padding: 0 3px;
    line-height: 1;
    font-size: 13px;
}
.tag-input .tag-pill button:hover { opacity: 1; }
.tag-input .tag-pill.pending-remove { background: #fde2e1; color: #9f1d1a; }
.tag-input .tag-text {
    flex: 1 0 80px;
    min-width: 80px;
    border: 0;
    outline: 0;
    padding: 2px;
    font-size: 13px;
    background: transparent;
}

/* ---- Quotation service rows (v1.19.0) ---- */
.service-block {
    border: 1px solid var(--border-color);
    border-radius: var(--bs-border-radius-lg);
    background: #fff;
}
.service-block + .service-block { margin-top: .75rem; }
.service-block .service-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    padding: .6rem .75rem;
    background: var(--slate-50);
    border-bottom: 1px solid var(--border-color);
    border-radius: calc(var(--bs-border-radius-lg) - 1px) calc(var(--bs-border-radius-lg) - 1px) 0 0;
}
.service-block .service-num {
    width: 24px; height: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.service-block .service-price-table th { font-size: 11.5px; font-weight: 600; color: var(--slate-500); white-space: nowrap; }
.service-block .service-price-table input { min-width: 90px; }
/* .service-primary-row removed in v1.23.0 — terms are equal options, none is highlighted */