/* =====================================================================================================================
   Partner Portal — Design System (WS-DS, #119)
   Loads after the vendored Bootswatch Flatly 5.3 theme and re-points it at the portal palette.

   Contract: class names, data attributes and custom properties in this file are an API used by every page workstream.
   CssTokenLintTest fails when a template or script uses a var(--x) not declared here, or a literal badge-*, status-*
   or btn-* class not defined here. Breakpoints: sm 576 · md 768 · lg 992 · xl 1200 (max-width queries use .98).
   ===================================================================================================================== */

/* ============================================
   1. TOKENS, ALIASES, BOOTSTRAP BRIDGE
   ============================================ */
:root {
    /* Surfaces */
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #f0f3f6;
    --bg-elevated: #ffffff;
    --bg-canvas: #f6f8fa;

    /* Borders */
    --border-default: #d0d7de;
    --border-muted: #d8dee4;
    --border-subtle: #eaeef2;

    /* Text (all AA on white) */
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-tertiary: #6a737d;
    --text-link: #0969da;

    /* Accents */
    --accent-primary: #0969da;
    --accent-primary-hover: #0860c4;
    --accent-success: #1a7f37;
    --accent-success-bg: #dafbe1;
    --accent-warning: #bf8700;
    --accent-warning-bg: #fff8c5;
    --accent-danger: #d1242f;
    --accent-danger-bg: #ffebe9;
    --accent-info: #0969da;
    --accent-info-bg: #ddf4ff;
    --accent-purple: #8250df;
    --accent-purple-text: #6639ba;
    --accent-purple-bg: #fbefff;
    --accent-teal: #0e7490;
    --accent-teal-bg: #e0f7fa;

    /* Aliases used by templates (never remove: CssTokenLintTest) */
    --primary: var(--accent-primary);
    --success: var(--accent-success);
    --warning: var(--accent-warning);
    --danger: var(--accent-danger);
    --info: var(--accent-info);
    --secondary: var(--text-secondary);
    --text-muted: var(--text-secondary);
    --border: var(--border-default);
    --border-color: var(--border-default);
    --bg-muted: var(--bg-tertiary);
    --radius: var(--radius-md);
    --warning-bg: var(--accent-warning-bg);
    --warning-border: var(--accent-warning);
    --warning-text: #7d4e00;
    --danger-bg: var(--accent-danger-bg);
    --success-bg: var(--accent-success-bg);
    --info-bg: var(--accent-info-bg);

    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 14px;
    --fs-md: 16px;
    --fs-lg: 18px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 30px;

    /* Shadows */
    --shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
    --shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
    --shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
    --shadow-xl: 0 12px 28px rgba(140, 149, 159, 0.3);
    --focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);

    /* Transitions */
    --transition-fast: 80ms cubic-bezier(0.33, 1, 0.68, 1);
    --transition-base: 150ms cubic-bezier(0.33, 1, 0.68, 1);
    --transition-slow: 250ms cubic-bezier(0.33, 1, 0.68, 1);

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shell */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 60px;
    --partner-sidebar-width: 216px;
    --topbar-h: 60px;
    --admin-topbar-h: 56px;
    --action-bar-h: 64px;
    --tap: 44px;

    /* Timeline / category dots */
    --dot-deal: var(--accent-primary);
    --dot-invoice: var(--accent-success);
    --dot-partner: var(--accent-purple);
    --dot-training: var(--accent-teal);
    --dot-license: var(--accent-warning);
    --dot-registration: #9a3c00;
    --dot-system: var(--text-tertiary);

    /* Risk scale (background / text pairs, AA) */
    --risk-low-bg: #dafbe1;
    --risk-low-text: #1a7f37;
    --risk-moderate-bg: #fff8c5;
    --risk-moderate-text: #7a5a00;
    --risk-high-bg: #ffe8d6;
    --risk-high-text: #9a3c00;
    --risk-critical-bg: #ffebe9;
    --risk-critical-text: #a40e26;

    /* Bootstrap bridge: point Flatly's variables at the portal palette */
    --bs-primary: #0969da;
    --bs-primary-rgb: 9, 105, 218;
    --bs-secondary: #656d76;
    --bs-secondary-rgb: 101, 109, 118;
    --bs-success: #1a7f37;
    --bs-success-rgb: 26, 127, 55;
    --bs-danger: #d1242f;
    --bs-danger-rgb: 209, 36, 47;
    --bs-warning: #bf8700;
    --bs-warning-rgb: 191, 135, 0;
    --bs-info: #0969da;
    --bs-info-rgb: 9, 105, 218;
    --bs-body-color: #1f2328;
    --bs-body-color-rgb: 31, 35, 40;
    --bs-body-bg: #ffffff;
    --bs-secondary-color: #656d76;
    --bs-border-color: #d0d7de;
    --bs-link-color: #0969da;
    --bs-link-color-rgb: 9, 105, 218;
    --bs-link-hover-color: #0860c4;
    --bs-link-hover-color-rgb: 8, 96, 196;
    --bs-code-color: #1f2328;
    --bs-heading-color: #1f2328;
    --bs-emphasis-color: #1f2328;
    --bs-focus-ring-color: rgba(9, 105, 218, 0.35);
    --bs-body-font-family: var(--font-sans);
    --bs-font-sans-serif: var(--font-sans);
    --bs-font-monospace: var(--font-mono);
}

/* ============================================
   2. BASE
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.nav-open {
    overflow: hidden;
}

h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 {
    margin-top: 0;
    font-family: var(--font-sans);
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1, .h1 { font-size: var(--fs-2xl); }
h2, .h2 { font-size: var(--fs-xl); }
h3, .h3 { font-size: var(--fs-lg); }
h4, .h4 { font-size: var(--fs-md); }
h5, .h5 { font-size: var(--fs-base); }
h6, .h6 { font-size: var(--fs-sm); }

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

a:hover {
    text-decoration: underline;
}

code {
    color: inherit;
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.92em;
    overflow-wrap: anywhere;
}

pre {
    font-family: var(--font-mono);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    overflow-x: auto;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-subtle);
    opacity: 1;
}

[hidden] {
    display: none !important;
}

input, select, textarea, button {
    accent-color: var(--accent-primary);
}

::selection {
    background: rgba(9, 105, 218, 0.2);
}

/* Skip link: first focusable element of every layout */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 8px;
    z-index: 2000;
    background: var(--bg-primary);
    color: var(--accent-primary);
    padding: 8px 12px;
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-md);
    font-weight: 600;
}

.skip-link:focus {
    left: 8px;
}

main:focus {
    outline: none;
}

/* ============================================
   3. TYPOGRAPHY UTILITIES
   ============================================ */
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-small { font-size: var(--fs-sm); }
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-secondary) !important; }
.text-tertiary { color: var(--text-tertiary); }
.text-end { text-align: right; }
.nowrap { white-space: nowrap; }
.fw-600 { font-weight: 600; }

.sku {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.section-title {
    font-size: var(--fs-md);
    font-weight: 600;
    margin: 0 0 var(--space-3);
}

/* ============================================
   4. APP SHELL — PARTNER
   ============================================ */
.navbar-portal {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-default);
    padding: 0 var(--space-4);
    min-height: var(--topbar-h);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-portal .navbar-portal__inner,
.navbar-portal > .container-fluid {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--topbar-h);
    padding: 0;
}

.navbar-portal .navbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    min-width: 0;
    white-space: nowrap;
}

.navbar-portal .navbar-brand strong {
    overflow: hidden;
    text-overflow: ellipsis;
}

.navbar-portal .logo {
    height: 32px;
    width: auto;
}

.navbar-portal__end {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
    min-width: 0;
}

.navbar-portal .nav-link {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.navbar-portal .nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    text-decoration: none;
}

.navbar-portal .nav-link.active {
    color: var(--text-primary);
    font-weight: 600;
    background: var(--bg-tertiary);
}

.pp-brand-logo {
    vertical-align: middle;
    border-radius: 6px;
    flex: none;
}

.partner-layout {
    display: flex;
    min-height: calc(100vh - var(--topbar-h));
}

.partner-sidebar {
    width: var(--partner-sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-default);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    align-self: flex-start;
    overflow: hidden;
}

/* the nav scrolls on its own; the drawer header/footer stay pinned */
.partner-sidebar-nav {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-3) 0;
}

.partner-nav-section-title {
    padding: 14px 16px 4px;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    font-weight: 700;
}

.partner-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    border-left: 3px solid transparent;
}

.partner-nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    text-decoration: none;
}

.partner-nav-link.active,
.partner-nav-link[aria-current="page"] {
    color: var(--text-primary);
    font-weight: 600;
    background: var(--bg-tertiary);
    border-left-color: var(--accent-primary);
}

.nav-count {
    margin-left: auto;
    background: var(--accent-danger);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
}

.partner-content {
    flex: 1;
    min-width: 0;
    overflow-x: clip;
}

/* Drawer header/footer: only inside the off-canvas drawer (below 992 px) */
.drawer-header,
.drawer-footer {
    display: none;
}

.drawer-header {
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.drawer-header__title {
    font-weight: 700;
}

.drawer-footer {
    margin-top: auto;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* only inside the open drawer (below 992 px); beats .btn-icon's display */
button.drawer-close {
    display: none;
}

/* User menu + avatar */
.user-menu-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    min-height: 36px;
    max-width: 260px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.user-menu-btn:hover {
    background: var(--bg-tertiary);
}

.user-menu-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.user-avatar {
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--accent-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    overflow: hidden;
    letter-spacing: 0.02em;
}

.user-menu-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    white-space: normal;
    max-width: 280px;
}

.user-menu-header__name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: var(--fs-base);
}

.user-menu-header__email,
.user-menu-header__org {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    overflow-wrap: anywhere;
}

/* Notification bell */
.notification-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    padding: var(--space-1);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

.notification-bell:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    text-decoration: none;
}

.notification-bell .badge-count {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--accent-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    min-width: 16px;
    text-align: center;
    line-height: 14px;
}

/* Language switch (server-rendered state: .active + aria-pressed) */
.lang-selector {
    display: inline-flex;
    flex: none;
    gap: 2px;
    padding: 2px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.lang-btn {
    padding: var(--space-1) var(--space-2);
    min-width: 32px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    color: var(--text-secondary);
}

.lang-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.lang-btn.active,
.lang-btn[aria-pressed="true"] {
    background: var(--accent-primary);
    color: #fff;
}

/* Off-canvas toggle + backdrop (both layouts) */
.pp-sidebar-toggle {
    display: none;
    position: relative;
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    margin-left: calc(-1 * var(--space-2));
    background: none;
    border: 0;
    border-radius: var(--radius-md);
    font-size: 22px;
    line-height: 1;
    color: var(--text-primary);
    cursor: pointer;
}

.pp-sidebar-toggle:hover {
    background: var(--bg-tertiary);
}

.pp-sidebar-toggle__count {
    position: absolute;
    top: 4px;
    right: 2px;
    min-width: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    background: var(--accent-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
}

.pp-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(1, 4, 9, 0.45);
    z-index: 1040;
}

.pp-backdrop.show {
    display: block;
}

/* ============================================
   5. APP SHELL — ADMIN
   ============================================ */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-topbar {
    display: none;
}

.admin-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1045;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    border-bottom: 1px solid var(--border-default);
}

.admin-sidebar .sidebar-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-4);
    text-decoration: none;
    color: var(--text-primary);
    min-width: 0;
}

.admin-sidebar .sidebar-brand:hover {
    text-decoration: none;
}

.admin-sidebar .sidebar-brand-title {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
}

.admin-sidebar .sidebar-brand-subtitle {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: var(--space-3);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-section,
.sidebar-group {
    margin-bottom: var(--space-3);
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    padding: var(--space-2) var(--space-3);
    margin: 0 0 var(--space-1);
    line-height: 1.4;
}

summary.sidebar-section-title {
    cursor: pointer;
    list-style: none;
    border-radius: var(--radius-sm);
    user-select: none;
}

summary.sidebar-section-title::-webkit-details-marker {
    display: none;
}

summary.sidebar-section-title::after {
    content: '';
    width: 6px;
    height: 6px;
    margin-left: auto;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--transition-base);
}

.sidebar-group:not([open]) > summary.sidebar-section-title::after {
    transform: rotate(-45deg);
}

summary.sidebar-section-title:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.sidebar-section--attention .sidebar-section-title {
    color: var(--accent-danger);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 6px var(--space-3);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    text-decoration: none;
}

.sidebar-link.active,
.sidebar-link[aria-current="page"] {
    color: var(--accent-primary);
    background: var(--accent-info-bg);
    font-weight: 600;
    border-left-color: var(--accent-primary);
}

.sidebar-link .sidebar-icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link .sidebar-badge,
.sidebar-link .sidebar-count {
    margin-left: auto;
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 1px 7px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

.sidebar-link .sidebar-badge {
    background: var(--accent-danger);
    color: #fff;
}

.sidebar-link .sidebar-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Attention state: the queue has work (Needs action group) */
.sidebar-link.attention {
    border-left-color: var(--accent-danger);
    background: var(--accent-danger-bg);
    color: var(--text-primary);
    font-weight: 600;
}

.sidebar-link.attention:hover {
    background: #ffdcd7;
}

.sidebar-link.active.attention {
    border-left-color: var(--accent-danger);
}

.sidebar-sub-links {
    padding-left: 32px;
}

.sidebar-sub-links .sidebar-link {
    font-size: 13px;
    padding: var(--space-1) var(--space-3);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-default);
    background: var(--bg-primary);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.sidebar-user__text {
    flex: 1;
    min-width: 0;
}

.sidebar-user__name {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user__role {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

.sidebar-footer__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.sidebar-footer__links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-1) var(--space-3);
    min-width: 0;
}

.sidebar-footer__link {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.sidebar-footer__link.active,
.sidebar-footer__link[aria-current="page"] {
    color: var(--accent-primary);
    font-weight: 600;
}

.sidebar-footer__signout {
    margin: 0;
}

.admin-content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.admin-main {
    flex: 1;
    min-width: 0;
}

/* ============================================
   6. APP SHELL — PUBLIC (AUTH) + FOOTER
   ============================================ */
.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--space-4);
    gap: var(--space-4);
}

.auth-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    max-width: 980px;
    margin: 0 auto;
    width: 100%;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    color: var(--text-primary);
    min-width: 0;
}

.auth-brand:hover {
    text-decoration: none;
}

/* the logo of the sign-in card, next to the company name and the portal name */
.auth-brand__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.auth-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.auth-brand-title {
    font-weight: 700;
    line-height: 1.1;
}

.auth-brand-subtitle {
    color: var(--text-secondary);
    font-size: 12px;
}

.auth-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
}

.auth-main > .flash-region {
    width: 100%;
    max-width: 42rem;
    margin: 0;
    padding: 0;
}

.auth-title {
    font-size: var(--fs-2xl);
    font-weight: 700;
    text-align: center;
    margin-bottom: var(--space-5);
}

.auth-footer {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 12px;
}

.footer-portal {
    text-align: center;
    padding: var(--space-4);
    color: var(--text-tertiary);
    font-size: 12px;
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-6);
}

/* ============================================
   7. PAGE LAYOUT + PAGE HEADER
   ============================================ */
/* The page column is the size container of the page layouts (.detail-layout below 908 px, see §8). container-type
   does not contain fixed descendants (modals, the phone action bar) in current engines; it only makes the box's
   inline size independent of its content, which a block-level page column is anyway. */
.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4);
    container: page / inline-size;
}

.page-header {
    margin-bottom: var(--space-5);
}

.page-header--split {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
}

.page-header__main {
    flex: 1 1 320px;
    min-width: 0;
}

.page-header__actions {
    flex: 0 1 auto;
    justify-content: flex-end;
}

.page-header__meta {
    margin-top: var(--space-2);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.back-link:hover {
    color: var(--text-primary);
}

.page-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 var(--space-1) 0;
    overflow-wrap: anywhere;
}

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

/* Flash region inside the app layouts lines up with .page-container */
.admin-main > .flash-region,
.partner-content > .flash-region {
    max-width: 1400px;
    margin: var(--space-5) auto 0;
    padding: 0 var(--space-4);
}

/* ============================================
   8. LAYOUT PRIMITIVES
   ============================================ */
.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: var(--space-4);
    align-items: start;
}

.detail-main,
.detail-aside {
    min-width: 0;
}

/* One column when the page column is narrower than 908 px (= a 940 px page: below 1200 px with the admin sidebar,
   below ~1156 px with the partner sidebar; the drawer range is one column by the media query in §32). Same order as
   on phones: main, then aside (.detail-aside--first goes first). */
@container page (max-width: 907.98px) {
    .detail-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    /* (two classes: these must beat the later viewport rules of §32 — sticky aside ≥ 1200 px, order reset < 1200 px) */
    .detail-layout > .detail-aside {
        position: static;
    }

    .detail-layout > .detail-aside--first {
        order: -1;
    }
}

.form-grid {
    --cols: 2;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--space-3) var(--space-4);
}

.form-grid--3 { --cols: 3; }
.form-grid--4 { --cols: 4; }

.span-all {
    grid-column: 1 / -1;
}

.grid-2, .grid-3, .grid-4 {
    display: grid;
    gap: var(--space-4);
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.split {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.card + .card {
    margin-top: var(--space-4);
}

.stack > .card + .card,
.grid-2 > .card + .card,
.grid-3 > .card + .card,
.grid-4 > .card + .card,
.detail-main > .card + .card,
.detail-aside > .card + .card,
.kpi-grid > .card + .card,
.stat-grid > .card + .card {
    margin-top: 0;
}

.detail-main > .card + .card,
.detail-aside > .card + .card {
    margin-top: var(--space-4);
}

/* ============================================
   9. CARDS, STATS, KPI TILES, DETAIL FACTS
   ============================================ */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-default);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.card-title {
    font-size: var(--fs-base);
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: var(--space-4);
}

.card-footer {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-default);
}

.card-emphasis {
    border: 2px solid var(--accent-primary);
}

.card-emphasis > .card-header {
    background: var(--accent-info-bg);
    color: var(--text-primary);
}

.card-emphasis-warning {
    border: 2px solid var(--accent-warning);
}

.card-emphasis-warning > .card-header {
    background: var(--accent-warning-bg);
    color: var(--warning-text);
}

/* Stat cards */
.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: box-shadow var(--transition-base), transform var(--transition-base), border-color var(--transition-base);
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--stat-color, var(--accent-primary));
}

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

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: var(--space-3);
    background: var(--stat-color-bg, var(--accent-info-bg));
    color: var(--stat-color, var(--accent-primary));
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.stat-card.stat-primary { --stat-color: var(--accent-primary); --stat-color-bg: var(--accent-info-bg); }
.stat-card.stat-warning { --stat-color: var(--accent-warning); --stat-color-bg: var(--accent-warning-bg); }
.stat-card.stat-success { --stat-color: var(--accent-success); --stat-color-bg: var(--accent-success-bg); }
.stat-card.stat-danger { --stat-color: var(--accent-danger); --stat-color-bg: var(--accent-danger-bg); }
.stat-card.stat-info { --stat-color: #0e7490; --stat-color-bg: rgba(8, 145, 178, 0.1); }
.stat-card.stat-purple { --stat-color: var(--accent-purple); --stat-color-bg: rgba(130, 80, 223, 0.1); }

/* KPI tiles: clickable numbers linking to the filtered list */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.kpi-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-left: 3px solid var(--border-default);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    text-decoration: none;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

a.kpi-tile:hover {
    text-decoration: none;
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
}

.kpi-tile--attention {
    border-left-color: var(--accent-danger);
}

.kpi-tile__label {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.kpi-tile__value {
    font-size: var(--fs-2xl);
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.kpi-tile__sub {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

/* Detail facts */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.info-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
    min-width: 0;
}

.info-item--wide {
    grid-column: 1 / -1;
}

.info-item > .badge,
.info-item > .status-badge {
    align-self: flex-start;
}

.info-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.info-value {
    font-size: 14px;
    color: var(--text-primary);
    overflow-wrap: anywhere;
    max-width: 100%;
}

dl.info-grid {
    margin: 0;
}

dl.info-grid dt {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

dl.info-grid dd {
    margin: 0;
}

/* ============================================
   10. BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 5px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    box-shadow: none;
}

.btn:disabled,
.btn.disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:active {
    background: var(--accent-primary-hover);
    border-color: var(--accent-primary-hover);
    color: #fff;
}

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

.btn-secondary:hover,
.btn-secondary:active {
    background: var(--bg-tertiary);
    border-color: var(--border-muted);
    color: var(--text-primary);
}

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

.btn-success:hover,
.btn-success:active {
    background: #116329;
    border-color: #116329;
    color: #fff;
}

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

.btn-danger:hover,
.btn-danger:active {
    background: #a40e26;
    border-color: #a40e26;
    color: #fff;
}

.btn-warning {
    background: var(--accent-warning-bg);
    border-color: var(--accent-warning);
    color: #1f2328;
}

.btn-warning:hover,
.btn-warning:active {
    background: #fae17d;
    border-color: #9a6700;
    color: #1f2328;
}

.btn-outline-primary {
    background: transparent;
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-outline-primary:hover,
.btn-outline-primary:active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.btn-outline-secondary {
    background: transparent;
    border-color: var(--border-default);
    color: var(--text-primary);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:active {
    background: var(--bg-tertiary);
    border-color: var(--border-muted);
    color: var(--text-primary);
}

.btn-outline-danger {
    background: transparent;
    border-color: var(--accent-danger);
    color: var(--accent-danger);
}

.btn-outline-danger:hover,
.btn-outline-danger:active {
    background: var(--accent-danger);
    border-color: var(--accent-danger);
    color: #fff;
}

.btn-outline-warning {
    background: transparent;
    border-color: #9a6700;
    color: #7d4e00;
}

.btn-outline-warning:hover,
.btn-outline-warning:active {
    background: var(--accent-warning-bg);
    border-color: #9a6700;
    color: #1f2328;
}

.btn-outline-success {
    background: transparent;
    border-color: var(--accent-success);
    color: var(--accent-success);
}

.btn-outline-success:hover,
.btn-outline-success:active {
    background: var(--accent-success);
    border-color: var(--accent-success);
    color: #fff;
}

/* Ghost: Cancel and row actions */
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover,
.btn-ghost:active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Icon-only: always with aria-label */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    flex: none;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-sm {
    padding: 3px 12px;
    font-size: 12px;
    line-height: 18px;
}

.btn-lg {
    padding: 10px 24px;
    font-size: 16px;
}

/* Busy state (data-once / async): spinner, no clicks, pair with aria-busy */
.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-color: rgba(255, 255, 255, 0.9) rgba(255, 255, 255, 0.9) transparent transparent;
    border-radius: 50%;
    animation: qs-spin 0.7s linear infinite;
}

.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-outline-secondary.is-loading::after,
.btn-warning.is-loading::after,
.btn-outline-warning.is-loading::after,
.dropdown-item.is-loading::after {
    border-color: var(--text-secondary) var(--text-secondary) transparent transparent;
}

.btn-outline-primary.is-loading::after {
    border-color: var(--accent-primary) var(--accent-primary) transparent transparent;
}

.btn-outline-danger.is-loading::after {
    border-color: var(--accent-danger) var(--accent-danger) transparent transparent;
}

.btn-outline-success.is-loading::after {
    border-color: var(--accent-success) var(--accent-success) transparent transparent;
}

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

/* Flatly ships a white close icon (for its dark alerts): use the portal's dark one everywhere */
.btn-close {
    --bs-btn-close-color: var(--text-primary);
    --bs-btn-close-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%231f2328'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e");
    --bs-btn-close-opacity: 0.6;
    --bs-btn-close-hover-opacity: 1;
    --bs-btn-close-focus-opacity: 1;
    --bs-btn-close-focus-shadow: var(--focus-ring);
    background-image: var(--bs-btn-close-bg);
    flex: none;
}

.btn-close,
.alert .btn-close,
.modal .btn-close,
.toast .btn-close,
.offcanvas .btn-close {
    filter: none;
    background-image: var(--bs-btn-close-bg);
}

.btn-close:focus {
    box-shadow: var(--focus-ring);
}

/* ============================================
   11. FORMS
   ============================================ */
.form-control,
.form-select {
    display: block;
    width: 100%;
    padding: 5px 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 20px;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23656d76' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px 12px;
    padding: 5px 32px 5px 12px;
}

.form-select[multiple],
.form-select[size]:not([size="1"]) {
    background-image: none;
    padding-right: 12px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-control::placeholder {
    color: var(--text-tertiary);
    opacity: 1;
}

.form-control-sm,
.form-select-sm {
    padding-top: 3px;
    padding-bottom: 3px;
    font-size: 12px;
    line-height: 18px;
    border-radius: var(--radius-sm);
}

.form-control[readonly],
.form-control:disabled,
.form-select:disabled,
textarea.form-control[readonly] {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: default;
    opacity: 1;
}

.form-control-plaintext {
    padding: 5px 0;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: var(--space-3);
}

.form-group > label,
.form-group > .form-label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-1);
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.form-label.required::after {
    content: ' *';
    color: var(--accent-danger);
    font-weight: 600;
}

.form-required-legend {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin: 0 0 var(--space-3);
}

.form-text,
.form-help {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.form-control.is-invalid,
.form-select.is-invalid,
[aria-invalid="true"].form-control,
[aria-invalid="true"].form-select {
    border-color: var(--accent-danger);
    background-image: none;
}

.form-select.is-invalid {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23656d76' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(209, 36, 47, 0.3);
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: var(--space-1);
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-danger);
}

.form-check-input {
    border-color: var(--border-default);
}

.form-check-input:checked {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.form-check-input:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--focus-ring);
}

.form-switch .form-check-input:focus {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%289, 105, 218, 0.5%29'/%3e%3c/svg%3e");
}

/* Grouped sections */
fieldset.form-section {
    border: 0;
    border-top: 1px solid var(--border-subtle);
    margin: 0 0 var(--space-4);
    padding: var(--space-4) 0 0;
    min-width: 0;
}

fieldset.form-section:first-of-type {
    border-top: 0;
    padding-top: 0;
}

legend.form-section-title,
.form-section-title {
    float: none;
    width: auto;
    font-size: var(--fs-md);
    font-weight: 600;
    margin: 0 0 var(--space-1);
    padding: 0;
    color: var(--text-primary);
}

.form-section-desc {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin: 0 0 var(--space-3);
}

/* Checkbox tiles */
.check-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-2);
}

.check-tile {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
    min-width: 0;
}

.check-tile:hover {
    border-color: var(--border-muted);
    background: var(--bg-secondary);
}

.check-tile:has(:checked) {
    border-color: var(--accent-primary);
    background: var(--accent-info-bg);
}

.check-tile:has(:focus-visible) {
    box-shadow: var(--focus-ring);
}

.check-tile input {
    margin-top: 3px;
    flex: none;
}

.check-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-right: var(--space-4);
    cursor: pointer;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-2);
    margin: 0;
}

.pp-inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-2);
    margin: 0;
}

.req {
    color: var(--accent-danger);
}

/* Error summary (fragments/forms :: errorSummary). scroll-margin: focusing it scrolls it clear of the sticky top bar. */
.error-summary {
    border: 2px solid var(--accent-danger);
    border-left-width: 6px;
    border-radius: var(--radius-md);
    background: var(--accent-danger-bg);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    color: var(--text-primary);
    scroll-margin-top: calc(var(--topbar-h) + var(--space-4));
}

.error-summary:focus {
    outline: 3px solid rgba(209, 36, 47, 0.35);
    outline-offset: 2px;
}

.error-summary__title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: #a40e26;
    margin: 0 0 var(--space-2);
}

.error-summary__list {
    margin: 0;
    padding-left: var(--space-5);
}

.error-summary__list a {
    color: #a40e26;
    text-decoration: underline;
    font-weight: 500;
}

/* ============================================
   12. TABLES
   ============================================ */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-bottom: 0;
    color: var(--text-primary);
    --bs-table-bg: transparent;
}

.table thead th {
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-default);
    text-align: left;
    vertical-align: bottom;
}

.table tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.table tbody tr:hover {
    background: var(--bg-secondary);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table th.num,
.table td.num {
    text-align: right;
}

/* Scroll shadows: a soft edge appears on the side that has more columns to scroll to */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    background:
        linear-gradient(to right, var(--bg-primary) 30%, rgba(255, 255, 255, 0)) left center / 40px 100% no-repeat local,
        linear-gradient(to left, var(--bg-primary) 30%, rgba(255, 255, 255, 0)) right center / 40px 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%, rgba(31, 35, 40, 0.18), rgba(31, 35, 40, 0)) left center / 12px 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, rgba(31, 35, 40, 0.18), rgba(31, 35, 40, 0)) right center / 12px 100% no-repeat scroll;
}

.table-compact thead th,
.table-compact tbody td {
    padding: var(--space-2) var(--space-3);
}

/* --------------------------------------------------------------------------------------------------------------------
   Fit-or-stack (SHELL-N02). A table.table-stack inside .table-wrap / .table-responsive never scrolls sideways: main.js
   measures it against its wrap (before the first paint, again on resize, on content change and when a hidden tab panel
   or <details> shows it) and sets ONE state on the table:
     (none)         it fits as a table;
     .is-condensed  it fits once th/td.col-optional are hidden — mark the same column on the th AND on every td;
     .is-stacked    card layout (one card per row, td[data-label] as the label); col-optional cells show again.
   Below 768 px every table-stack is .is-stacked (and stacked by the media query in §32 without JS). Card-mode tweaks of
   an area: write them for `.table-stack.is-stacked …` (any width). Tables without .table-stack keep scrolling.
   -------------------------------------------------------------------------------------------------------------------- */
.table-stack > thead th {
    white-space: normal; /* headers may wrap, so the widest cell decides the column, not its title */
}

/* the row's title never shrinks to a word per line (10rem: at 12rem the 9-column partner list no longer fit 1440 px) */
.table-stack:not(.is-stacked) > tbody > tr > td.cell-primary {
    min-width: 10rem;
}

.table-stack:not(.is-stacked) > tbody > tr > td.cell-actions {
    white-space: nowrap;
}

.table-stack.is-condensed:not(.is-stacked) th.col-optional,
.table-stack.is-condensed:not(.is-stacked) td.col-optional {
    display: none;
}

/* Card layout at any width (the same rules as the phone fallback in §32) */
.table-stack.is-stacked > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.table-stack.is-stacked,
.table-stack.is-stacked > tbody,
.table-stack.is-stacked > tbody > tr,
.table-stack.is-stacked > tbody > tr > td {
    display: block;
    width: 100%;
}

.table-stack.is-stacked > tbody > tr {
    margin: 0 0 var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.table-stack.is-stacked > tbody > tr:last-child {
    margin-bottom: 0;
}

.table-stack.is-stacked > tbody > tr > td {
    display: flex;
    flex-wrap: wrap; /* a long value moves under its label instead of pushing the card wider (CRM-N04) */
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-1) 0;
    border: 0;
    text-align: right;
    overflow-wrap: anywhere;
}

.table-stack.is-stacked > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 45%;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
}

.table-stack.is-stacked > tbody > tr > td > * {
    min-width: 0;
    max-width: 100%;
}

/* a value on its own line stays right-aligned */
.table-stack.is-stacked > tbody > tr > td[data-label]:not([data-label=""]) > :only-child {
    margin-left: auto;
}

.table-stack.is-stacked > tbody > tr > td[data-label=""]::before,
.table-stack.is-stacked > tbody > tr > td:not([data-label])::before {
    content: none;
}

.table-stack.is-stacked > tbody > tr > td.cell-primary {
    display: block;
    text-align: left;
    font-weight: 600;
    font-size: var(--fs-md);
    padding-bottom: var(--space-2);
}

.table-stack.is-stacked > tbody > tr > td.cell-primary::before {
    content: none;
}

.table-stack.is-stacked > tbody > tr > td.cell-actions {
    justify-content: flex-end;
    padding-top: var(--space-2);
}

.table-stack.is-stacked > tbody > tr > td.cell-actions::before {
    content: none;
}

.table-stack.is-stacked tr.empty-row,
.table-stack.is-stacked tr.empty-row td {
    display: block;
    border: 0;
    padding: 0;
    text-align: center;
}

.table-stack.is-stacked > tbody > tr:not(.empty-row):hover {
    background: var(--bg-secondary);
}

.line-items.table-stack.is-stacked > tbody > tr > td:first-child {
    display: block;
    text-align: left;
    font-size: var(--fs-md);
    padding-bottom: var(--space-2);
}

.line-items.table-stack.is-stacked > tbody > tr > td:first-child::before {
    content: none;
}

.line-items.table-stack.is-stacked tr.line-addon td:first-child,
.line-items.table-stack.is-stacked tr.line-addon--child td:first-child {
    padding-left: 0;
}

.line-items.table-stack.is-stacked tr.line-addon td:first-child::before {
    position: static;
    content: '↳ ';
    color: var(--text-tertiary);
}

.line-items.table-stack.is-stacked tr.line-addon--child td:first-child::before {
    content: '↳ ↳ ';
}

.line-items.table-stack.is-stacked tr.line-total,
.line-items.table-stack.is-stacked tr.line-subtotal {
    border-width: 2px;
}

.line-items.table-stack.is-stacked tr.line-total td,
.line-items.table-stack.is-stacked tr.line-subtotal td {
    border-top: 0;
}

.line-items.table-stack.is-stacked tr.line-total td[colspan],
.line-items.table-stack.is-stacked tr.line-subtotal td[colspan] {
    display: none;
}

/* Cards from 768 px up (a table that does not fit its column on a desktop or tablet): the title first, then the
   label → value pairs side by side, each value right next to its label, in as many 18rem columns as the card fits.
   Phones keep the label-left / value-right card of the media query in §32. */
@media (min-width: 768px) {
    .table-stack.is-stacked > tbody > tr:not(.empty-row) {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(18rem, 100%), 1fr));
        column-gap: var(--space-5);
        align-items: baseline;
    }

    .table-stack.is-stacked > tbody > tr > td {
        justify-content: flex-start;
        text-align: left;
    }

    .table-stack.is-stacked > tbody > tr > td::before {
        width: 8rem;
        max-width: 45%;
    }

    .table-stack.is-stacked > tbody > tr > td[data-label]:not([data-label=""]) > :only-child {
        margin-left: 0;
    }

    .table-stack.is-stacked > tbody > tr > td.cell-primary,
    .table-stack.is-stacked > tbody > tr > td.cell-actions,
    .table-stack.is-stacked > tbody > tr > td[colspan],
    .table-stack.is-stacked > tbody > tr > th,
    .line-items.table-stack.is-stacked > tbody > tr > td:first-child {
        grid-column: 1 / -1;
    }

    .table-stack.is-stacked > tbody > tr > td.cell-primary {
        order: -1;
    }

    .table-stack.is-stacked > tbody > tr > td.cell-actions {
        order: 1;
    }
}

/* Row link: the name cell's link covers the row; other controls sit above it */
tr.has-row-link {
    position: relative;
}

a.row-link::after {
    content: '';
    position: absolute;
    inset: 0;
}

tr.has-row-link:hover a.row-link {
    text-decoration: underline;
}

tr.has-row-link a:not(.row-link),
tr.has-row-link button,
tr.has-row-link input,
tr.has-row-link select,
tr.has-row-link form {
    position: relative;
    z-index: 1;
}

/* Sortable headers: th[aria-sort] > a.sort-link > span.sort-indicator */
.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: inherit;
    text-decoration: none;
}

.sort-link:hover {
    color: var(--text-primary);
    text-decoration: none;
}

.sort-indicator::after {
    content: '↕';
    font-size: 10px;
    color: var(--text-tertiary);
}

th[aria-sort="ascending"] .sort-indicator::after {
    content: '▲';
    color: var(--accent-primary);
}

th[aria-sort="descending"] .sort-indicator::after {
    content: '▼';
    color: var(--accent-primary);
}

th[aria-sort="ascending"],
th[aria-sort="descending"] {
    color: var(--text-primary);
}

/* Line items: base package → add-on hierarchy */
.line-items tbody td {
    vertical-align: top;
}

.line-items tr.line-base td {
    font-weight: 600;
}

.line-items tr.line-addon td:first-child {
    position: relative;
    padding-left: 28px;
}

.line-items tr.line-addon td:first-child::before {
    content: '↳';
    position: absolute;
    left: 10px;
    color: var(--text-tertiary);
}

.line-items tr.line-addon--child td:first-child {
    padding-left: 44px;
}

.line-items tr.line-addon--child td:first-child::before {
    left: 26px;
}

.line-items tr.line-carried td {
    color: var(--text-secondary);
}

.line-items tr.line-charge td:first-child {
    font-style: italic;
}

.line-items tr.line-subtotal td,
.line-items tr.line-total td {
    border-top: 2px solid var(--border-default);
    font-weight: 600;
}

.line-items tr.line-total td {
    font-size: var(--fs-md);
}

.line-items tr.line-subtotal:hover,
.line-items tr.line-total:hover {
    background: transparent;
}

.price {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: flex-end;
    gap: 2px 6px;
    font-variant-numeric: tabular-nums;
}

.price__list {
    color: var(--text-tertiary);
    font-size: var(--fs-sm);
}

.price__net {
    font-weight: 600;
}

.line-notes {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ============================================
   13. ALERTS + FLASH REGION
   ============================================ */
.alert {
    position: relative;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid;
    font-size: 14px;
}

/* Structured alerts (flash region, or any alert with .alert__body): icon · body · close */
.flash-region .alert,
.alert:has(> .alert__body) {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
}

.alert.alert-dismissible {
    padding-right: var(--space-4);
}

.alert-dismissible .btn-close {
    position: static;
    margin-left: auto;
    padding: 4px;
    width: 1em;
    height: 1em;
    flex: none;
}

.alert__icon {
    flex: none;
    font-weight: 700;
    line-height: 20px;
}

.alert__body {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.alert-success {
    background: var(--accent-success-bg);
    border-color: var(--accent-success);
    color: #116329;
}

.alert-warning {
    background: var(--accent-warning-bg);
    border-color: var(--accent-warning);
    color: var(--warning-text);
}

.alert-danger {
    background: var(--accent-danger-bg);
    border-color: var(--accent-danger);
    color: #a40e26;
}

.alert-info {
    background: var(--accent-info-bg);
    border-color: var(--accent-info);
    color: #0550ae;
}

.flash-region {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.flash-region .alert {
    margin: 0;
    box-shadow: var(--shadow-sm);
}

.flash-region .alert.is-leaving {
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.flash-link {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

/* ============================================
   14. BADGES, CHIPS, STATUS LABELS
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    white-space: nowrap;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    vertical-align: middle;
}

.badge[class*="bg-"] {
    color: #fff;
}

.badge-primary { background: var(--accent-info-bg); color: var(--accent-primary); }
.badge-success { background: var(--accent-success-bg); color: var(--accent-success); }
.badge-warning { background: var(--accent-warning-bg); color: var(--warning-text); }
.badge-danger { background: var(--accent-danger-bg); color: var(--accent-danger); }
.badge-secondary { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-info { background: var(--accent-info-bg); color: #0550ae; }

/* Semantic badges */
.badge-base { background: var(--accent-info-bg); color: #0550ae; font-weight: 600; }
.badge-addon { background: transparent; border-color: var(--accent-purple); color: var(--accent-purple-text); }
.badge-included { background: var(--accent-success-bg); color: var(--accent-success); }
.badge-no-effect { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-required { background: var(--accent-warning-bg); color: var(--warning-text); }
.badge-owned { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--border-default); }
.badge-manual { background: var(--accent-warning-bg); color: var(--warning-text); }
.badge-proposed { background: var(--accent-purple-bg); color: var(--accent-purple-text); }
.badge-special { background: var(--accent-success-bg); color: #116329; font-weight: 600; }
.badge-recommended { background: var(--accent-info-bg); color: #0550ae; }
.badge-nis2 { background: #e8f1ff; color: #0550ae; font-weight: 600; }
.badge-dora { background: #fff1e5; color: #9a3c00; font-weight: 600; }
.badge-version { font-family: var(--font-mono); background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-deploy-cloud { background: #e8f1ff; color: #0550ae; }
.badge-deploy-va { background: #f3efff; color: var(--accent-purple-text); }
.badge-deploy-hw { background: var(--bg-tertiary); color: var(--text-primary); }
.badge-deploy-addax { background: var(--accent-teal-bg); color: var(--accent-teal); }
.badge-deploy-managed { background: var(--accent-success-bg); color: var(--accent-success); } /* 1Click, #122 */

/* Level badge: neutral pill with a colour dot (style="--dot:#ffd700") */
.badge-level {
    background: var(--bg-primary);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.badge-level::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dot, var(--text-tertiary));
    box-shadow: inset 0 0 0 1px rgba(31, 35, 40, 0.2);
}

.badge-count {
    font-variant-numeric: tabular-nums;
}

/* Partner type badges (AA contrast) */
.badge-role {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-role-vendor { background: #cf222e; color: #fff; }
.badge-role-distributor { background: #8250df; color: #fff; }
.badge-role-msp { background: #0969da; color: #fff; }
.badge-role-var { background: #0e7490; color: #fff; }
.badge-role-reseller { background: #57606a; color: #fff; }

/* Legacy tier badges (deprecated: use .badge-level) */
.badge-tier-bronze { background: #cd7f32; color: #1f2328; }
.badge-tier-silver { background: #c0c0c0; color: #1f2328; }
.badge-tier-gold { background: #ffd700; color: #1f2328; }
.badge-tier-platinum { background: #e5e4e2; color: #1f2328; border: 1px solid #c0c0c0; }

/* Chips: filters and toggles */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 500;
    line-height: 20px;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

a.chip:hover,
button.chip:hover {
    background: var(--bg-tertiary);
    text-decoration: none;
}

.chip[aria-current="true"],
.chip[aria-pressed="true"],
.chip.is-active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.chip-count {
    min-width: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.chip[aria-current="true"] .chip-count,
.chip[aria-pressed="true"] .chip-count,
.chip.is-active .chip-count,
.tabs__tab[aria-selected="true"] .chip-count {
    background: rgba(255, 255, 255, 0.25);
    color: inherit;
}

.chip--removable {
    padding-right: 4px;
}

.chip__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.chip__remove:hover {
    background: rgba(31, 35, 40, 0.1);
}

/* Status badges: <span class="status-badge status-<lower(NAME)>"> (fragments/status :: badge) */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.status-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    flex: none;
    border-radius: 50%;
    background: currentColor;
}

/* neutral / finished-without-success */
.status-draft, .status-terminated, .status-inactive, .status-cancelled, .status-expired,
.status-decommissioned, .status-disabled, .status-unverified, .status-withdrawn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* informational / waiting on someone */
.status-applied, .status-submitted, .status-sent, .status-enrolled, .status-renewed, .status-new,
.status-invited, .status-assigned, .status-provisioning, .status-pending_approval, .status-open {
    background: var(--accent-info-bg);
    color: #0550ae;
}

/* needs action / in progress */
.status-approved, .status-requested, .status-in_progress, .status-expiring-soon, .status-expiring_soon,
.status-proposal, .status-maintenance, .status-pending_payment, .status-drift {
    background: var(--accent-warning-bg);
    color: var(--warning-text);
}

/* positive */
.status-active, .status-completed, .status-paid, .status-won, .status-online, .status-available,
.status-used, .status-verified, .status-closed {
    background: var(--accent-success-bg);
    color: var(--accent-success);
}

/* negative */
.status-suspended, .status-rejected, .status-lost, .status-overdue, .status-revoked, .status-blocked {
    background: var(--accent-danger-bg);
    color: var(--accent-danger);
}

.status-failed {
    background: var(--accent-danger-bg);
    color: var(--accent-danger);
    font-weight: 600;
}

/* pipeline stages with their own hue */
.status-quoted, .status-contacted, .status-waiting_for_reporter {
    background: rgba(130, 80, 223, 0.1);
    color: var(--accent-purple-text);
}

.status-po_received, .status-qualified {
    background: rgba(8, 145, 178, 0.1);
    color: #0e7490;
}

.status-ordered {
    background: rgba(8, 145, 178, 0.15);
    color: #0e7490;
}

.status-trial {
    background: var(--accent-purple-bg);
    color: var(--accent-purple-text);
}

/* ============================================
   15. EMPTY STATES
   ============================================ */
.empty-state {
    text-align: center;
    padding: var(--space-6);
}

.empty-state .empty-icon {
    font-size: 48px;
    line-height: 1;
    color: var(--text-tertiary);
    margin-bottom: var(--space-3);
}

.empty-state .empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 var(--space-2);
}

.empty-state .empty-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 auto var(--space-4);
    max-width: 52ch;
}

.empty-state__cta {
    justify-content: center;
}

.empty-state--filtered {
    padding: var(--space-5);
}

tr.empty-row:hover {
    background: transparent;
}

/* ============================================
   16. FILTER BAR, SEGMENTED CONTROL, CLIENT FILTER
   ============================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-2) var(--space-3);
    margin: 0 0 var(--space-3);
}

.filter-bar__field {
    display: flex;
    flex-direction: column;
    flex: 1 1 180px;
    min-width: 0;
    max-width: 280px;
}

.filter-bar__field--search {
    flex: 2 1 240px;
    max-width: 420px;
}

.filter-bar__field .form-label {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.filter-bar__apply {
    flex: none;
}

.filter-bar__summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin: 0 0 var(--space-3);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.filter-bar__clear {
    font-weight: 500;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-3);
}

.filter-field {
    flex: 1 1 180px;
    min-width: 0;
}

.filter-actions {
    display: flex;
    gap: var(--space-2);
}

/* Segmented control: fieldset.segmented > input.segmented__input + label.segmented__option */
.segmented {
    display: inline-flex;
    flex-wrap: nowrap;
    max-width: 100%;
    gap: 2px;
    padding: 3px;
    margin: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    overflow-x: auto;
    scrollbar-width: thin;
}

.segmented__input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.segmented__option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.segmented__option:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.segmented__input:checked + .segmented__option {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.segmented__input:focus-visible + .segmented__option {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

.segmented__input:disabled + .segmented__option {
    opacity: 0.5;
    cursor: not-allowed;
}

.segmented__count {
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    padding: 0 5px;
    line-height: 16px;
    border-radius: var(--radius-full);
    background: rgba(31, 35, 40, 0.08);
    text-align: center;
}

.segmented__input:checked + .segmented__option .segmented__count {
    background: rgba(255, 255, 255, 0.25);
}

[data-filter-count] {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

/* ============================================
   17. PAGINATION
   ============================================ */
.pagination-portal {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    margin-top: var(--space-4);
}

.pagination-portal__pages {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.pagination-portal .page-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 14px;
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.pagination-portal .page-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.pagination-portal .page-link.active,
.pagination-portal .page-link[aria-current="page"] {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.pagination-portal .page-link.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.pagination-portal .page-gap {
    padding: 0 var(--space-1);
    color: var(--text-tertiary);
}

.pagination-portal__summary {
    flex-basis: 100%;
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

/* ============================================
   18. DROPDOWNS, MODALS, TOASTS
   ============================================ */
.dropdown-menu {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-2) 0;
    min-width: 200px;
    --bs-dropdown-link-active-bg: var(--accent-info-bg);
    --bs-dropdown-link-active-color: var(--text-primary);
}

.dropdown-menu form {
    margin: 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: 14px;
    color: var(--text-primary);
    background: transparent;
    border: 0;
    text-align: left;
    transition: background var(--transition-fast);
}

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

.dropdown-item:active,
.dropdown-item.active {
    background: var(--accent-info-bg);
    color: var(--text-primary);
}

.dropdown-item--danger,
.dropdown-item--danger:hover,
.dropdown-item--danger:focus {
    color: var(--accent-danger);
}

.dropdown-item--danger:hover {
    background: var(--accent-danger-bg);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-2) 0;
    border: 0;
}

.dropdown-header {
    color: var(--text-secondary);
}

.modal-content {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}

.modal-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: var(--space-4);
}

.modal-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    gap: var(--space-2);
}

.modal-footer > * {
    margin: 0;
}

.qs-confirm__message {
    margin: 0 0 var(--space-3);
    white-space: pre-line;
}

.qs-confirm__reason,
.qs-confirm__match {
    margin: var(--space-3) 0 0;
}

.qs-confirm--danger .modal-header {
    border-bottom-color: var(--accent-danger-bg);
}

.qs-confirm--danger .modal-title {
    color: #a40e26;
}

.qs-confirm--warning .modal-title {
    color: var(--warning-text);
}

/* Toasts (QS.toast) */
.toast-region {
    position: fixed;
    right: var(--space-4);
    bottom: var(--space-4);
    z-index: 1090;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-2);
    width: min(420px, calc(100vw - 2 * var(--space-4)));
    pointer-events: none;
}

/* Above the sticky .action-bar / .summary-bar at every width, so a toast never covers their buttons (CP-09) */
body:has(.action-bar) .toast-region,
body:has(.summary-bar) .toast-region {
    bottom: calc(var(--action-bar-h) + var(--space-4) + env(safe-area-inset-bottom));
}

.qs-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
    background: #1f2328;
    color: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    border-left: 4px solid var(--accent-primary);
    font-size: 14px;
    animation: qs-toast-in var(--transition-slow) ease-out;
}

.qs-toast--success { border-left-color: #2da44e; }
.qs-toast--warning { border-left-color: #d4a72c; }
.qs-toast--danger { border-left-color: #ff5f59; }

.qs-toast__message {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
    overflow-wrap: anywhere;
}

.qs-toast__action {
    flex: none;
    padding: 2px 8px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-sm);
    background: transparent;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

.qs-toast__action:hover {
    background: rgba(255, 255, 255, 0.12);
}

.qs-toast__close {
    flex: none;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    line-height: 1;
}

.qs-toast__close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.qs-toast.is-leaving {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

@keyframes qs-toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ============================================
   19. OPTION CARDS (radio cards)
   ============================================ */
.option-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-3);
}

.option-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

.option-card:hover {
    border-color: var(--border-muted);
    box-shadow: var(--shadow-md);
}

.option-card__input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.option-card:focus-within {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.option-card:has(.option-card__input:checked) {
    border: 2px solid var(--accent-primary);
    padding: calc(var(--space-3) - 1px) calc(var(--space-4) - 1px);
    background: var(--accent-info-bg);
}

.option-card:has(.option-card__input:checked)::after {
    content: '✓'; /* engines without alt text for generated content */
    content: '✓' / ''; /* decorative: not part of the card's accessible name (CP-11) */
    position: absolute;
    top: 8px;
    right: 10px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
}

.option-card:has(.option-card__input:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.option-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-right: 28px;
}

.option-card__title {
    font-size: var(--fs-md);
    font-weight: 600;
    margin: 0;
}

.option-card__badge {
    margin-left: auto;
}

.option-card__price {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    font-variant-numeric: tabular-nums;
}

.option-card__body {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.option-card__reason {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--warning-text);
}

.option-card--recommended {
    border-color: var(--accent-primary);
}

.option-card--recommended::before {
    content: attr(data-ribbon);
    position: absolute;
    top: -10px;
    left: var(--space-3);
    padding: 0 8px;
    border-radius: var(--radius-full);
    background: var(--accent-primary);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 18px;
}

.option-card--recommended:not([data-ribbon])::before {
    content: none;
}

/* ============================================
   20. CHOICE LIST ROWS (checklists with state, qty, price)
   ============================================ */
.choice-group {
    margin: 0 0 var(--space-4);
}

.choice-group__title {
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0 0 var(--space-2);
}

.choice-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.choice-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
}

.choice-row:last-child {
    border-bottom: 0;
}

.choice-row__input {
    margin: 0;
    width: 18px;
    height: 18px;
}

.choice-row__label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    cursor: pointer;
}

.choice-row__name {
    font-weight: 500;
}

.choice-row__desc {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.choice-row__state:empty {
    display: none;
}

/* The reason chip takes its colour from the row state — no per-state badge classes needed */
.choice-row[data-state="included"] .choice-row__state { background: var(--accent-success-bg); color: var(--accent-success); }
.choice-row[data-state="no_effect"] .choice-row__state,
.choice-row[data-state="locked"] .choice-row__state { background: var(--bg-tertiary); color: var(--text-secondary); }
.choice-row[data-state="requires"] .choice-row__state,
.choice-row[data-state="required"] .choice-row__state { background: var(--accent-warning-bg); color: var(--warning-text); }
.choice-row[data-state="owned"] .choice-row__state { background: var(--bg-primary); color: var(--text-primary); border-color: var(--border-default); }
.choice-row[data-state="protected"] .choice-row__state { background: var(--accent-danger-bg); color: var(--accent-danger); }

.choice-row__qty,
.choice-row__price,
.choice-row__total {
    justify-self: end;
}

.choice-row__price,
.choice-row__total {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.choice-row__total {
    font-weight: 600;
    min-width: 7ch;
    text-align: right;
}

.choice-row[data-state="selected"] {
    background: #f5faff;
}

.choice-row[data-state="included"] {
    background: #f4fdf6;
}

.choice-row[data-state="included"] .choice-row__price,
.choice-row[data-state="included"] .choice-row__total {
    visibility: hidden;
}

.choice-row[data-state="no_effect"],
.choice-row[data-state="requires"],
.choice-row[data-state="locked"],
.choice-row[data-state="protected"] {
    background: var(--bg-secondary);
}

.choice-row[data-state="no_effect"] .choice-row__label,
.choice-row[data-state="requires"] .choice-row__label,
.choice-row[data-state="locked"] .choice-row__label,
.choice-row[data-state="protected"] .choice-row__label {
    cursor: not-allowed;
    color: var(--text-secondary);
}

.choice-row[data-state="required"] {
    background: #fffdf0;
}

.choice-row[data-state="owned"] .choice-row__name::after {
    content: '';
}

.choice-row--child {
    position: relative;
    padding-left: calc(var(--space-3) + 28px);
}

.choice-row--child::before {
    content: '';
    position: absolute;
    left: calc(var(--space-3) + 10px);
    top: 0;
    bottom: 50%;
    width: 12px;
    border-left: 1px solid var(--border-default);
    border-bottom: 1px solid var(--border-default);
    border-bottom-left-radius: 4px;
}

/* ============================================
   21. QUANTITY STEPPER
   ============================================ */
.qty-stepper {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-primary);
}

.qty-stepper__btn.btn {
    width: 32px;
    min-height: 32px;
    padding: 0;
    border: 0;
    border-radius: 0;
    font-size: 16px;
    line-height: 1;
}

.qty-stepper__input.form-control {
    width: 52px;
    min-height: 32px;
    padding: 4px 6px;
    border: 0;
    border-left: 1px solid var(--border-default);
    border-right: 1px solid var(--border-default);
    border-radius: 0;
    text-align: center;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
    appearance: textfield;
}

.qty-stepper__input::-webkit-outer-spin-button,
.qty-stepper__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.qty-stepper__input.form-control:focus {
    box-shadow: inset var(--focus-ring);
}

/* ============================================
   22. ACTION BAR, DIRTY STATE, SUMMARY ASIDE / BAR
   ============================================ */
.action-bar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-default);
    box-shadow: 0 -4px 12px rgba(31, 35, 40, 0.06);
}

.action-bar__start {
    display: flex;
    gap: var(--space-2);
}

.action-bar__status {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

form.is-dirty .action-bar__status {
    color: var(--warning-text);
    font-weight: 500;
}

.action-bar__end {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-left: auto;
}

.summary-aside {
    position: sticky;
    top: var(--space-4);
}

.shell--partner .summary-aside {
    top: calc(var(--topbar-h) + var(--space-4));
}

.summary-aside .card-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.summary-tree {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.summary-tree li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    font-size: var(--fs-sm);
}

.summary-row--base {
    font-weight: 600;
    font-size: var(--fs-base) !important;
}

.summary-row--addon {
    padding-left: var(--space-4);
    color: var(--text-secondary);
}

.summary-row--addon::before {
    content: '↳ ';
    color: var(--text-tertiary);
}

.summary-row--support {
    border-top: 1px dashed var(--border-subtle);
    padding-top: var(--space-1);
}

.summary-totals {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px var(--space-3);
    margin: 0;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-sm);
}

.summary-totals dt {
    font-weight: 500;
    color: var(--text-secondary);
}

.summary-totals dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.summary-total--value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.summary-entitlements {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.summary-messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--fs-sm);
}

.summary-messages:empty {
    display: none;
}

.summary-live {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

.summary-aside.is-loading .summary-totals {
    opacity: 0.6;
}

/* Narrow container (< 960 px): the aside is hidden and .summary-bar sticks to the viewport bottom inside the
   composer. Put the Bootstrap .offcanvas-bottom sheet OUTSIDE .composer (fixed descendants of a size container
   may be positioned against it). */
.summary-bar {
    display: none;
    position: sticky;
    bottom: 0;
    z-index: 1020;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-top: var(--space-4);
    padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
    background: var(--bg-primary);
    border-top: 1px solid var(--border-default);
    box-shadow: 0 -4px 12px rgba(31, 35, 40, 0.08);
}

.summary-bar__total {
    font-size: var(--fs-lg);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.summary-bar__count {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.summary-bar__actions {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
}

.summary-sheet.offcanvas-bottom {
    height: auto;
    max-height: 85vh;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
}

/* ============================================
   23. LIFECYCLE STEPPER, NEXT STEP, DANGER ZONE
   ============================================ */
/* Every step always shows: the steps share the width (labels wrap) and the stepper turns vertical when its own width is
   below 720 px (container query below; the phone media query in §32 does the same without container queries). */
.stepper {
    container: stepper / inline-size;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-3) 0;
    list-style: none;
    margin: 0 0 var(--space-4);
    padding: 0;
}

.stepper__step {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 0 var(--space-1);
    text-align: center;
    min-width: 0;
}

.stepper__step::before {
    content: '';
    position: absolute;
    top: 13px;
    left: calc(-50% + 16px);
    right: calc(50% + 16px);
    height: 2px;
    background: var(--border-default);
}

.stepper__step:first-child::before {
    content: none;
}

.stepper__step.is-done::before,
.stepper__step.is-current::before {
    background: var(--accent-success);
}

.stepper__marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    background: var(--bg-primary);
    border: 2px solid var(--border-default);
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
}

.stepper__step.is-done .stepper__marker {
    background: var(--accent-success);
    border-color: var(--accent-success);
    color: #fff;
}

.stepper__step.is-current .stepper__marker {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 0 4px var(--accent-info-bg);
}

.stepper__label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.stepper__step.is-upcoming .stepper__label {
    color: var(--text-secondary);
    font-weight: 500;
}

.stepper__meta {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.stepper__label,
.stepper__meta {
    max-width: 100%;
    overflow-wrap: anywhere;
    hyphens: auto;
}

/* Vertical variant: one step per line, marker beside its label, once the stepper's own width leaves less than ~100 px
   a step: below 720 px with 6 or more steps (the deal lifecycle), below 480 px with 4–5, below 360 px otherwise. */
@container stepper (max-width: 719.98px) {
    .stepper:has(> .stepper__step:nth-child(6)) > .stepper__step {
        flex: 0 0 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        text-align: left;
        gap: var(--space-1) var(--space-2);
        padding: 0;
    }

    .stepper:has(> .stepper__step:nth-child(6)) > .stepper__step::before {
        content: none;
    }
}

@container stepper (max-width: 479.98px) {
    .stepper:has(> .stepper__step:nth-child(4)) > .stepper__step {
        flex: 0 0 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        text-align: left;
        gap: var(--space-1) var(--space-2);
        padding: 0;
    }

    .stepper:has(> .stepper__step:nth-child(4)) > .stepper__step::before {
        content: none;
    }
}

@container stepper (max-width: 359.98px) {
    .stepper__step {
        flex: 0 0 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        text-align: left;
        gap: var(--space-1) var(--space-2);
        padding: 0;
    }

    .stepper__step::before {
        content: none;
    }
}

.stepper__outcome--rejected,
.stepper__outcome--lost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--accent-danger-bg);
    color: var(--accent-danger);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.next-step {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-3) var(--space-4);
    margin: 0 0 var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--accent-primary);
    border-left-width: 4px;
    border-radius: var(--radius-lg);
    background: #f5faff;
}

.next-step__icon {
    flex: none;
    font-size: 24px;
    line-height: 1;
}

.next-step__body {
    flex: 1 1 260px;
    min-width: 0;
}

.next-step__title {
    font-size: var(--fs-md);
    font-weight: 600;
    margin: 0 0 var(--space-1);
}

.next-step__help {
    margin: 0;
    color: var(--text-secondary);
}

.next-step__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.next-step__actions form {
    margin: 0;
}

.next-step--waiting {
    border-color: var(--border-default);
    background: var(--bg-secondary);
}

.next-step--blocked {
    border-color: var(--accent-warning);
    background: var(--accent-warning-bg);
}

.danger-zone {
    border-color: rgba(209, 36, 47, 0.45);
}

.danger-zone__title {
    padding: var(--space-3) var(--space-4);
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    color: #a40e26;
    background: var(--accent-danger-bg);
    border-bottom: 1px solid rgba(209, 36, 47, 0.25);
}

.danger-zone__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.danger-zone__row:last-child {
    border-bottom: 0;
}

.danger-zone__row > div {
    flex: 1 1 280px;
    min-width: 0;
}

.danger-zone__row form {
    margin: 0;
}

.blockers {
    margin: var(--space-1) 0 0;
    padding-left: var(--space-4);
    font-size: var(--fs-sm);
    color: var(--warning-text);
}

/* ============================================
   24. TABS (deep-linkable), TIMELINE
   ============================================ */
/* The tab row wraps instead of scrolling, so no tab is ever hidden (PCOM-F06); a single tab wider than the row
   wraps its own label. */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-1);
    margin: 0 0 var(--space-4);
    border-bottom: 1px solid var(--border-default);
}

.tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    margin-bottom: -1px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.tabs__tab:hover {
    color: var(--text-primary);
    border-bottom-color: var(--border-default);
}

.tabs__tab[aria-selected="true"] {
    color: var(--text-primary);
    font-weight: 600;
    border-bottom-color: var(--accent-primary);
}

.tabs__tab[aria-selected="true"] .chip-count {
    background: var(--accent-primary);
    color: #fff;
}

.tabs__panel:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 4px;
}

.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border-subtle);
}

.timeline__item {
    position: relative;
    padding: 0 0 var(--space-4) var(--space-5);
}

.timeline__item:last-child {
    padding-bottom: 0;
}

.timeline__dot {
    position: absolute;
    left: 0;
    top: 5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
    background: var(--dot-system);
    box-shadow: 0 0 0 1px var(--border-default);
}

.timeline__item[data-category="deal"] .timeline__dot { background: var(--dot-deal); }
.timeline__item[data-category="invoice"] .timeline__dot { background: var(--dot-invoice); }
.timeline__item[data-category="partner"] .timeline__dot { background: var(--dot-partner); }
.timeline__item[data-category="training"] .timeline__dot { background: var(--dot-training); }
.timeline__item[data-category="license"] .timeline__dot { background: var(--dot-license); }
.timeline__item[data-category="registration"] .timeline__dot { background: var(--dot-registration); }
.timeline__item[data-category="system"] .timeline__dot { background: var(--dot-system); }

.timeline__title {
    font-weight: 600;
}

.timeline__meta {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.timeline__body {
    margin-top: var(--space-1);
    font-size: var(--fs-sm);
    overflow-wrap: anywhere;
}

.timeline-empty {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

/* ============================================
   25. COPY TO CLIPBOARD, SECRET FIELD
   ============================================ */
.secret-field {
    display: inline-block;
    max-width: 100%;
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.04em;
    word-spacing: 0.3em;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    overflow-wrap: anywhere;
    user-select: all;
}

.secret-field__note {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--fs-sm);
    color: var(--warning-text);
}

[data-copy-target].is-copied,
[data-copy-text].is-copied {
    color: var(--accent-success);
}

/* ============================================
   26. MESSAGES: INBOX + THREAD BUBBLES
   ============================================ */
.message-list {
    display: flex;
    flex-direction: column;
}

.message-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    text-decoration: none;
    color: inherit;
    transition: background var(--transition-fast);
    min-width: 0;
}

.message-row:hover {
    background: var(--bg-secondary);
    text-decoration: none;
    color: inherit;
}

.message-unread {
    background: var(--accent-info-bg);
    font-weight: 600;
}

.message-unread:hover {
    background: #c8ecff;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.message-unread .message-avatar {
    background: var(--accent-info);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 2px;
}

.message-sender {
    font-size: 13px;
    font-weight: 600;
}

.message-subject {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-preview {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.message-meta {
    flex-shrink: 0;
    text-align: right;
}

.message-date {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.message-type-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.message-type-upsell { color: #6639ba; background: #f3e8ff; }
.message-type-cross_sell { color: #0550ae; background: #ddf4ff; }
.message-type-alert { color: #7d4e00; background: #fff8c5; }
.message-type-system { color: #57606a; background: #f0f3f6; }
.message-type-general { color: #57606a; background: #f0f3f6; }

.msg-thread {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.msg-bubble {
    max-width: 72ch;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    overflow-wrap: anywhere;
}

.msg-bubble--vendor {
    align-self: flex-start;
    background: var(--bg-secondary);
    border-top-left-radius: 4px;
}

.msg-bubble--own {
    align-self: flex-end;
    background: var(--accent-info-bg);
    border-color: #b6e3ff;
    border-top-right-radius: 4px;
}

.msg-bubble--system {
    align-self: center;
    max-width: 60ch;
    background: transparent;
    border-style: dashed;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: center;
}

.msg-bubble--withdrawn {
    font-style: italic;
    color: var(--text-tertiary);
    background: transparent;
}

.msg-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.msg-read {
    font-size: var(--fs-xs);
    color: var(--accent-success);
}

/* ============================================
   27. RISK: BADGE, GAUGE, SCORE BAR, SCALE + CALCULATOR
   ============================================ */
.risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.risk-badge--low { background: var(--risk-low-bg); color: var(--risk-low-text); }
.risk-badge--moderate { background: var(--risk-moderate-bg); color: var(--risk-moderate-text); }
.risk-badge--high { background: var(--risk-high-bg); color: var(--risk-high-text); }
.risk-badge--critical { background: var(--risk-critical-bg); color: var(--risk-critical-text); }

.score-bar {
    position: relative;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    overflow: hidden;
}

.score-bar::after {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: calc(var(--value, 0) / 5 * 100%);
    border-radius: inherit;
    background: var(--score-color, var(--accent-primary));
}

.risk-scale {
    display: flex;
    justify-content: space-between;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.risk-gauge {
    position: relative;
    width: 200px;
    height: 100px;
    margin: 0 auto var(--space-4);
}

.risk-gauge-fill {
    width: 200px;
    height: 100px;
    border-radius: 100px 100px 0 0;
    background: linear-gradient(90deg, var(--risk-low-bg) 0%, var(--risk-moderate-bg) 33%, var(--risk-high-bg) 66%, var(--risk-critical-bg) 100%);
    border: 1px solid var(--border-default);
    position: relative;
    overflow: hidden;
}

.risk-gauge-needle {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 4px;
    height: 90px;
    background: var(--text-primary);
    transform-origin: bottom center;
    border-radius: 2px;
    margin-left: -2px;
    transition: transform var(--transition-slow);
}

.risk-score {
    text-align: center;
    font-size: 28px;
    font-weight: 700;
}

.risk-label {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.risk-low { color: var(--risk-low-text); }
.risk-medium { color: var(--risk-moderate-text); }
.risk-high { color: var(--risk-high-text); }
.risk-critical { color: var(--risk-critical-text); }

.risk-slider {
    width: 100%;
}

.risk-slider::-webkit-slider-thumb {
    cursor: pointer;
}

/* ============================================
   28. EXAM KIT
   ============================================ */
.exam-container {
    max-width: 720px;
    margin: 0 auto;
}

.exam-timer {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-elevated);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.shell--partner .exam-timer {
    top: calc(var(--topbar-h) + var(--space-2));
}

.exam-timer-value {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.exam-timer-warning,
.exam-timer.exam-timer-warning .exam-timer-value {
    color: var(--accent-danger);
}

.exam-timer.exam-timer-warning {
    border-color: var(--accent-danger);
    background: var(--accent-danger-bg);
}

.exam-progress {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.exam-question-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin: 0 0 var(--space-4);
    min-width: 0;
}

fieldset.exam-question-card > legend {
    float: none;
    width: auto;
}

.exam-question-number {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-2);
}

.exam-question-text {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: var(--space-3);
}

.exam-answer {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.exam-answer:hover {
    border-color: var(--accent-primary);
    background: var(--accent-info-bg);
}

.exam-answer.selected,
.exam-answer:has(:checked) {
    border-color: var(--accent-primary);
    background: var(--accent-info-bg);
    font-weight: 500;
}

.exam-nav {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.exam-nav-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.exam-nav-btn.answered {
    background: var(--accent-success-bg);
    border-color: var(--accent-success);
}

.exam-nav-btn.current {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-info-bg);
}

/* ============================================
   29. PROSE (rendered Markdown, legal text)
   ============================================ */
.prose {
    max-width: 72ch;
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.prose h1 { font-size: var(--fs-xl); margin: var(--space-5) 0 var(--space-3); }
.prose h2 { font-size: var(--fs-lg); margin: var(--space-5) 0 var(--space-2); }
.prose h3 { font-size: var(--fs-md); margin: var(--space-4) 0 var(--space-2); }
.prose h4 { font-size: var(--fs-md); margin: var(--space-4) 0 var(--space-2); }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin: 0 0 var(--space-3); }
.prose ul, .prose ol { padding-left: var(--space-5); }
.prose li + li { margin-top: var(--space-1); }
.prose blockquote {
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--border-default);
    color: var(--text-secondary);
}
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border-subtle); padding: var(--space-1) var(--space-2); text-align: left; }
.prose th { background: var(--bg-secondary); }
.prose img { max-width: 100%; height: auto; }

/* ============================================
   30. DEAL COMPOSER LAYOUT KIT (see dealComposerBrief)
   ============================================ */
/* .summary-host: the same container behaviour for other editors with a live summary (invoice editor, upscale) */
.composer,
.summary-host {
    container-type: inline-size;
    container-name: composer;
}

.composer__layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}

/* the aside spans the whole row, so a sticky .summary-aside inside it stays in view while the main column scrolls */
.composer__aside {
    align-self: stretch;
}

.composer__main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.composer__aside {
    display: none;
    min-width: 0;
}

.composer-nav {
    display: none;
}

.composer-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    scroll-margin-top: calc(var(--topbar-h) + var(--space-4));
}

.composer-section__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.composer-section__number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 700;
}

.composer-section[data-status="done"] .composer-section__number {
    background: var(--accent-success);
    color: #fff;
}

.composer-section[data-status="problems"] .composer-section__number {
    background: var(--accent-danger);
    color: #fff;
}

.composer-section__title {
    font-size: var(--fs-md);
    font-weight: 600;
    margin: 0;
}

.composer-section__status {
    margin-left: auto;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.composer-section[data-status="done"] .composer-section__status { color: var(--accent-success); }
.composer-section[data-status="required"] .composer-section__status { color: var(--warning-text); }
.composer-section[data-status="problems"] .composer-section__status { color: var(--accent-danger); }

.composer-section__body {
    padding: var(--space-4);
}

.composer-section[data-disabled="true"] .composer-section__body > :not(.composer-section__placeholder) {
    opacity: 0.45;
    pointer-events: none;
}

.composer-section__placeholder {
    display: none;
    padding: var(--space-3);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-align: center;
}

.composer-section[data-disabled="true"] .composer-section__placeholder {
    display: block;
}

.package-line {
    margin: 0 0 var(--space-4);
}

.package-line:last-child {
    margin-bottom: 0;
}

.package-line__title {
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0 0 var(--space-2);
}

.option-card--package .package-tier {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.package-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.package-includes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.package-delta {
    font-size: var(--fs-sm);
    color: var(--accent-success);
    font-weight: 500;
}

.price-period {
    font-size: var(--fs-sm);
    font-weight: 400;
    color: var(--text-secondary);
}

.discount-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
}

.discount-pill::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dot, var(--text-tertiary));
}

.entitlements-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.delta--up {
    color: var(--accent-success);
    font-weight: 600;
}

.composer-hint {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

@container composer (min-width: 960px) {
    .composer__layout {
        grid-template-columns: minmax(0, 1fr) 340px;
        gap: var(--space-5);
    }

    .composer__aside {
        display: block;
    }

    .composer-nav {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        position: sticky;
        top: var(--space-2);
        z-index: 4;
        padding: var(--space-2) 0;
        background: var(--bg-primary);
    }

    .summary-bar {
        display: none !important;
    }
}

@container composer (max-width: 959.98px) {
    .summary-bar {
        display: flex;
    }

    /* the bar carries the primary action; the sheet carries Save draft / Cancel */
    .action-bar--summarised {
        display: none;
    }
}

/* ============================================
   31. EXISTING PAGE KITS (kept for current templates)
   ============================================ */
/* Partner finder (public) */
.partner-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: box-shadow var(--transition-base), transform var(--transition-base), border-color var(--transition-base);
    min-width: 0;
}

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

.partner-card .partner-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.partner-card .partner-location {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.partner-card .partner-meta {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Quick actions */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-width: 0;
}

.quick-action-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--border-muted);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

.quick-action-btn .action-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    font-size: 18px;
    background: var(--accent-info-bg);
    color: var(--accent-primary);
}

.quick-action-btn .action-text {
    flex: 1;
    min-width: 0;
}

.quick-action-btn .action-title {
    font-weight: 600;
    font-size: 14px;
}

.quick-action-btn .action-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Vendor checklist */
.checklist-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.checklist-item:last-child {
    border-bottom: none;
}

.checklist-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    flex-shrink: 0;
}

.checklist-done { background: var(--accent-success-bg); color: var(--accent-success); }
.checklist-pending { background: var(--accent-danger-bg); color: var(--accent-danger); }

.checklist-label {
    flex: 1;
    font-size: 14px;
}

/* Product specs */
.spec-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    white-space: nowrap;
}

.product-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    transition: box-shadow var(--transition-fast);
    min-width: 0;
}

.product-card:hover {
    box-shadow: var(--shadow-md);
}

/* Category filter (legacy button row) */
.category-filter {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.category-filter .btn {
    font-size: 13px;
    padding: var(--space-1) var(--space-3);
}

/* Financial charts */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 300px;
    padding: var(--space-3);
}

.chart-container canvas {
    max-width: 100%;
}

.year-selector {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.year-selector select {
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

/* Max-width utilities */
.mw-md { max-width: 28rem; }
.mw-lg { max-width: 32rem; }
.mw-2xl { max-width: 42rem; }
.mw-3xl { max-width: 48rem; }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn var(--transition-slow) ease-out;
}

/* ============================================
   32. RESPONSIVE
   ============================================ */
@media (max-width: 1199.98px) {
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-aside--first {
        order: 0;
    }
}

@media (min-width: 1200px) {
    .detail-aside {
        position: sticky;
        top: var(--space-4);
    }

    .shell--partner .detail-aside {
        top: calc(var(--topbar-h) + var(--space-4));
    }
}

@media (min-width: 768px) and (max-width: 1100px) {
    .form-grid--4 {
        --cols: 2;
    }
}

/* Tablet + phone: both layouts switch to the off-canvas drawer */
@media (max-width: 991.98px) {
    .detail-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .detail-aside--first {
        order: -1;
    }

    /* --- admin --- */
    .admin-topbar {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        position: sticky;
        top: 0;
        z-index: 1000;
        min-height: var(--admin-topbar-h);
        padding: 0 var(--space-3);
        background: var(--bg-primary);
        border-bottom: 1px solid var(--border-default);
    }

    .admin-topbar__brand {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        min-width: 0;
        margin-right: auto;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
    }

    .admin-topbar__brand span {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .admin-topbar__brand:hover {
        text-decoration: none;
    }

    .admin-content {
        margin-left: 0;
    }

    .admin-sidebar {
        width: min(86vw, 300px);
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--transition-base), visibility 0s linear 150ms;
    }

    .admin-sidebar.open {
        transform: translateX(0);
        visibility: visible;
        box-shadow: 2px 0 18px rgba(1, 4, 9, 0.2);
        transition: transform var(--transition-base), visibility 0s;
    }

    .shell--admin .drawer-close {
        display: inline-flex;
        margin-right: var(--space-2);
        width: var(--tap);
        height: var(--tap);
    }

    /* --- partner --- */
    .pp-sidebar-toggle {
        display: inline-flex;
    }

    .partner-layout {
        display: block;
    }

    .partner-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: auto;
        align-self: auto; /* align-self applies to fixed boxes too: flex-start would size it to its content */
        width: min(86vw, 300px);
        z-index: 1045;
        padding: 0;
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--transition-base), visibility 0s linear 150ms;
    }

    .partner-sidebar.open {
        transform: translateX(0);
        visibility: visible;
        box-shadow: 2px 0 18px rgba(1, 4, 9, 0.2);
        transition: transform var(--transition-base), visibility 0s;
    }

    .partner-sidebar .drawer-header,
    .partner-sidebar .drawer-footer,
    .partner-sidebar .drawer-close {
        display: flex;
    }

    .partner-sidebar .drawer-close {
        width: var(--tap);
        height: var(--tap);
    }

    .partner-sidebar-nav {
        padding: var(--space-2) 0;
    }

    .partner-content {
        width: 100%;
    }

    .navbar-portal .lang-selector,
    .user-menu-name {
        display: none;
    }
}

/* Phones */
@media (max-width: 767.98px) {
    :root {
        --action-bar-h: 112px; /* status row + full-width buttons */
    }

    .page-container {
        padding: var(--space-4) var(--space-3);
    }

    .navbar-portal {
        padding: 0 var(--space-3);
    }

    .navbar-portal__end {
        gap: var(--space-1);
    }

    .stat-card .stat-value {
        font-size: 24px;
    }

    .admin-main > .flash-region,
    .partner-content > .flash-region {
        margin-top: var(--space-4);
        padding: 0 var(--space-3);
    }

    /* Grids collapse to one column */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: minmax(0, 1fr);
    }

    .form-grid,
    .form-grid--3,
    .form-grid--4 {
        --cols: 1;
    }

    .info-grid--2 {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Page headers + action rows stack (legacy inline-flex headers included) */
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }

    .page-header > div:last-child {
        width: 100%;
    }

    /* header action rows written with Bootstrap .d-flex wrap instead of pushing the page wider */
    .page-header .d-flex,
    .page-header > div:last-child,
    .card-header.d-flex {
        flex-wrap: wrap;
    }

    .page-header--split {
        align-items: stretch !important;
    }

    /* in the stacked (column) header a flex-basis would become a height */
    .page-header--split > .page-header__main,
    .page-header--split > .page-header__actions {
        flex: 0 1 auto;
    }

    .page-header__actions {
        justify-content: flex-start;
        width: 100%;
    }

    .page-header__actions > .btn-primary,
    .page-header__actions > a.btn-primary {
        flex: 1 1 100%;
    }

    /* Tables: unwrapped tables scroll inside themselves; their cells may wrap */
    .table:not(.table-stack) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        background:
            linear-gradient(to right, var(--bg-primary) 30%, rgba(255, 255, 255, 0)) left center / 40px 100% no-repeat local,
            linear-gradient(to left, var(--bg-primary) 30%, rgba(255, 255, 255, 0)) right center / 40px 100% no-repeat local,
            radial-gradient(farthest-side at 0 50%, rgba(31, 35, 40, 0.18), rgba(31, 35, 40, 0)) left center / 12px 100% no-repeat scroll,
            radial-gradient(farthest-side at 100% 50%, rgba(31, 35, 40, 0.18), rgba(31, 35, 40, 0)) right center / 12px 100% no-repeat scroll;
    }

    .table:not(.table-stack) thead th {
        white-space: nowrap;
    }

    .table-wrap > .table:not(.table-stack) {
        display: table;
    }

    /* Stacked tables: each row becomes a card of label/value pairs. The no-JS twin of `.table-stack.is-stacked` (§12):
       keep the two in step. */
    .table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    .table-stack,
    .table-stack tbody,
    .table-stack tr,
    .table-stack td {
        display: block;
        width: 100%;
    }

    .table-stack tbody tr {
        margin: 0 0 var(--space-3);
        padding: var(--space-3);
        border: 1px solid var(--border-default);
        border-radius: var(--radius-md);
        background: var(--bg-primary);
    }

    .table-stack tbody tr:last-child {
        margin-bottom: 0;
    }

    .table-stack tbody td {
        display: flex;
        flex-wrap: wrap; /* a long value moves under its label instead of pushing the card wider (CRM-N04) */
        align-items: baseline;
        justify-content: space-between;
        gap: var(--space-1) var(--space-3);
        padding: var(--space-1) 0;
        border: 0;
        text-align: right;
        overflow-wrap: anywhere;
    }

    .table-stack tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
    }

    .table-stack tbody td > * {
        min-width: 0;
        max-width: 100%;
    }

    .table-stack tbody td[data-label]:not([data-label=""]) > :only-child {
        margin-left: auto;
    }

    .table-stack tbody td[data-label=""]::before,
    .table-stack tbody td:not([data-label])::before {
        content: none;
    }

    .table-stack tbody td.cell-primary {
        display: block;
        text-align: left;
        font-weight: 600;
        font-size: var(--fs-md);
        padding-bottom: var(--space-2);
    }

    .table-stack tbody td.cell-primary::before {
        content: none;
    }

    .table-stack tbody td.cell-actions {
        justify-content: flex-end;
        padding-top: var(--space-2);
    }

    .table-stack tbody td.cell-actions::before {
        content: none;
    }

    .table-stack tr.empty-row,
    .table-stack tr.empty-row td {
        display: block;
        border: 0;
        padding: 0;
        text-align: center;
    }

    /* line items: the product cell is the card title; add-ons keep their arrow; totals show one labelled value */
    .line-items.table-stack tbody td:first-child {
        display: block;
        text-align: left;
        font-size: var(--fs-md);
        padding-bottom: var(--space-2);
    }

    .line-items.table-stack tbody td:first-child::before {
        content: none;
    }

    .line-items.table-stack tr.line-addon td:first-child,
    .line-items.table-stack tr.line-addon--child td:first-child {
        padding-left: 0;
    }

    .line-items.table-stack tr.line-addon td:first-child::before {
        position: static;
        content: '↳ ';
        color: var(--text-tertiary);
    }

    .line-items.table-stack tr.line-addon--child td:first-child::before {
        content: '↳ ↳ ';
    }

    .line-items.table-stack tr.line-total,
    .line-items.table-stack tr.line-subtotal {
        border-width: 2px;
    }

    .line-items.table-stack tr.line-total td,
    .line-items.table-stack tr.line-subtotal td {
        border-top: 0;
    }

    .line-items.table-stack tr.line-total td[colspan],
    .line-items.table-stack tr.line-subtotal td[colspan] {
        display: none;
    }

    /* Filter bar stacks */
    .filter-bar__field,
    .filter-bar__field--search {
        flex: 1 1 100%;
        max-width: none;
    }

    /* Choice rows: name + line total on top, the reason chip under the name, then qty and unit price */
    .choice-row {
        grid-template-columns: 24px minmax(0, 1fr) auto;
        grid-template-areas:
            "input label total"
            ".     state state"
            ".     qty   price";
        row-gap: 0;
        align-items: start;
    }

    .choice-row__input {
        grid-area: input;
        margin-top: 2px;
    }

    .choice-row__label {
        grid-area: label;
    }

    .choice-row__total {
        grid-area: total;
    }

    .choice-row__state {
        grid-area: state;
        justify-self: start;
        margin-top: var(--space-1);
        white-space: normal;
    }

    .choice-row__qty {
        grid-area: qty;
        justify-self: start;
        margin-top: var(--space-2);
    }

    .choice-row__qty:empty {
        display: none;
    }

    .choice-row__price {
        grid-area: price;
        justify-self: end;
        align-self: center;
        margin-top: var(--space-2);
        font-size: var(--fs-sm);
        color: var(--text-secondary);
    }

    /* Stepper turns vertical */
    .stepper {
        flex-direction: column;
        gap: var(--space-3);
        overflow: visible;
    }

    .stepper__step {
        flex: none;
        flex-direction: row;
        align-items: center;
        text-align: left;
        gap: var(--space-2);
        padding: 0;
    }

    .stepper__step::before {
        content: none;
    }

    /* Action bar fixed at the bottom */
    .action-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
        z-index: 1020;
    }

    .action-bar__end {
        flex: 1 1 100%;
        margin-left: 0;
    }

    .action-bar__end > .btn {
        flex: 1 1 0;
    }

    body:has(.action-bar) .footer-portal,
    body:has(.action-bar) main {
        padding-bottom: calc(var(--action-bar-h) + var(--space-5) + env(safe-area-inset-bottom));
    }

    .summary-bar {
        margin-left: calc(-1 * var(--space-3));
        margin-right: calc(-1 * var(--space-3));
    }

    /* Toasts: full width (above the bottom bars: §18) */
    .toast-region {
        left: var(--space-3);
        right: var(--space-3);
        bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
        width: auto;
        align-items: stretch;
    }

    body:has(.action-bar) .toast-region,
    body:has(.summary-bar) .toast-region {
        bottom: calc(var(--action-bar-h) + var(--space-3) + env(safe-area-inset-bottom));
    }

    /* Comfortable touch targets */
    .btn {
        min-height: var(--tap);
    }

    .btn-sm {
        min-height: 36px;
    }

    .btn-icon,
    .qty-stepper__btn.btn {
        width: var(--tap);
        height: var(--tap);
        min-height: var(--tap);
    }

    .qty-stepper__input.form-control {
        min-height: var(--tap);
    }

    .partner-nav-link,
    .sidebar-link {
        min-height: var(--tap);
    }

    .partner-nav-link {
        padding: 10px 16px;
        font-size: 15px;
    }

    .form-control,
    .form-select {
        min-height: 42px;
        font-size: 16px; /* 16px avoids iOS zoom-on-focus */
    }

    .chip {
        min-height: 36px;
    }

    .modal-footer > .btn {
        flex: 1 1 0;
    }

    .message-top {
        flex-wrap: wrap;
    }
}

@media (max-width: 575.98px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .segmented {
        display: flex;
    }

    .auth-shell {
        padding: var(--space-3);
    }
}

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

*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ============================================
   34. PRINT
   ============================================ */
@media print {
    .navbar-portal, .admin-topbar, .admin-sidebar, .partner-sidebar, .pp-sidebar-toggle, .pp-backdrop,
    .lang-selector, .skip-link, .footer-portal, .flash-region, .alert, .btn, form, .action-bar, .summary-bar,
    .toast-region, .filter-bar, .filter-chips, .pagination-portal, .composer-nav, .tabs, .modal {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .admin-content {
        margin-left: 0;
    }

    .page-container {
        max-width: 100%;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }

    .detail-layout,
    .composer__layout {
        display: block;
    }

    .tabs__panel[hidden] {
        display: block !important;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        color: #57606a;
    }
}
