/* =========================================================================
 * common/style.css
 *
 * Lead — single stylesheet for the entire application.
 *
 * Contents:
 *   1.  Design tokens (--zx-*)
 *   2.  Theme modes (dark / light / auto)
 *   3.  Reset + base
 *   4.  Layout shell (sidebar, topbar, content, mobile nav)
 *   5.  Buttons
 *   6.  Forms (inputs, selects, textareas, labels, help text)
 *   7.  Cards + panels
 *   8.  Tables
 *   9.  Badges + status pills
 *   10. Alerts / flash messages
 *   11. Utility classes
 *   12. Responsive (mobile drawer + bottom nav)
 *
 * Conventions:
 *   - All color/spacing/radius tokens use --zx-* prefix
 *   - No hardcoded hex values outside section 1
 *   - Theme is stored per tenant as tenants.theme_primary / theme_secondary
 *     / theme_mode and injected into <html data-theme> at render time
 * ========================================================================= */

/* =========================================================================
 * 1. Design tokens
 * ========================================================================= */
:root {
    /* Brand colors (default theme — override per tenant) */
    --zx-orange:       #ff7a18;
    --zx-orange-dark:  #e06500;
    --zx-orange-soft:  #fff2e6;
    --zx-gold:         #e0a800;
    --zx-gold-soft:    #fff8e1;

    /* Neutral scale */
    --zx-bg:           #f7f7f9;
    --zx-surface:      #ffffff;
    --zx-surface-2:    #f1f1f4;
    --zx-border:       #e4e4e8;
    --zx-border-soft:  #efeff2;

    /* Text */
    --zx-text:         #1a1a1f;
    --zx-text-2:       #4a4a52;
    --zx-text-3:       #7a7a85;
    --zx-text-invert:  #ffffff;

    /* Semantic */
    --zx-success:      #1a9c5b;
    --zx-success-soft: #e6f7ee;
    --zx-warning:      #c98a00;
    --zx-warning-soft: #fff4d6;
    --zx-danger:       #d33a3a;
    --zx-danger-soft:  #fdecec;
    --zx-info:         #2670c9;
    --zx-info-soft:    #e8f1fb;

    /* Spacing */
    --zx-space-1: 4px;
    --zx-space-2: 8px;
    --zx-space-3: 12px;
    --zx-space-4: 16px;
    --zx-space-5: 24px;
    --zx-space-6: 32px;
    --zx-space-7: 48px;

    /* Radius */
    --zx-radius-sm: 4px;
    --zx-radius:    8px;
    --zx-radius-lg: 14px;
    --zx-radius-pill: 999px;

    /* Shadows */
    --zx-shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --zx-shadow:    0 2px 8px rgba(0,0,0,.06);
    --zx-shadow-lg: 0 8px 24px rgba(0,0,0,.10);

    /* Typography */
    --zx-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --zx-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --zx-fs-xs:  12px;
    --zx-fs-sm:  13px;
    --zx-fs:     14px;
    --zx-fs-lg:  16px;
    --zx-fs-xl:  20px;
    --zx-fs-2xl: 26px;
    --zx-fs-3xl: 34px;

    /* Layout */
    --zx-sidebar-w: 240px;
    --zx-topbar-h:  56px;
    --zx-mobile-nav-h: 60px;
}

/* =========================================================================
 * 2. Theme modes
 * ========================================================================= */

/* Auto mode: follow OS preference unless overridden */
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --zx-bg:          #0f0f13;
        --zx-surface:     #1a1a20;
        --zx-surface-2:   #23232b;
        --zx-border:      #2d2d36;
        --zx-border-soft: #26262e;
        --zx-text:        #f1f1f4;
        --zx-text-2:      #c5c5cd;
        --zx-text-3:      #8a8a95;
        --zx-shadow-sm:   0 1px 2px rgba(0,0,0,.4);
        --zx-shadow:      0 2px 8px rgba(0,0,0,.5);
        --zx-shadow-lg:   0 8px 24px rgba(0,0,0,.6);
        --zx-orange-soft: #2a1a10;
        --zx-gold-soft:   #2a2210;
        --zx-success-soft:#0f2a1c;
        --zx-warning-soft:#2a2210;
        --zx-danger-soft: #2a1414;
        --zx-info-soft:   #0f1d2a;
    }
}

html[data-theme="dark"] {
    --zx-bg:          #0f0f13;
    --zx-surface:     #1a1a20;
    --zx-surface-2:   #23232b;
    --zx-border:      #2d2d36;
    --zx-border-soft: #26262e;
    --zx-text:        #f1f1f4;
    --zx-text-2:      #c5c5cd;
    --zx-text-3:      #8a8a95;
    --zx-shadow-sm:   0 1px 2px rgba(0,0,0,.4);
    --zx-shadow:      0 2px 8px rgba(0,0,0,.5);
    --zx-shadow-lg:   0 8px 24px rgba(0,0,0,.6);
    --zx-orange-soft: #2a1a10;
    --zx-gold-soft:   #2a2210;
    --zx-success-soft:#0f2a1c;
    --zx-warning-soft:#2a2210;
    --zx-danger-soft: #2a1414;
    --zx-info-soft:   #0f1d2a;
}

/* =========================================================================
 * 3. Reset + base
 * ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

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

a {
    color: var(--zx-orange);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 var(--zx-space-3); font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--zx-fs-2xl); }
h2 { font-size: var(--zx-fs-xl); }
h3 { font-size: var(--zx-fs-lg); }

p { margin: 0 0 var(--zx-space-3); }

code, pre { font-family: var(--zx-font-mono); font-size: var(--zx-fs-sm); }

/* =========================================================================
 * 4. Layout shell
 * ========================================================================= */
.nsb-layout {
    display: flex;
    min-height: 100vh;
}

.nsb-sidebar {
    width: var(--zx-sidebar-w);
    flex-shrink: 0;
    background: var(--zx-surface);
    border-right: 1px solid var(--zx-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transition: transform .2s ease;
}

.nsb-sidebar__brand {
    height: var(--zx-topbar-h);
    padding: 0 var(--zx-space-4);
    display: flex;
    align-items: center;
    gap: var(--zx-space-2);
    border-bottom: 1px solid var(--zx-border);
    font-weight: 700;
    color: var(--zx-text);
    font-size: var(--zx-fs-lg);
}
.nsb-sidebar__brand img { height: 24px; width: auto; }
.nsb-sidebar__brand .accent { color: var(--zx-orange); }

.nsb-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--zx-space-3) 0;
}

.nsb-nav-group {
    padding: var(--zx-space-3) var(--zx-space-4) var(--zx-space-1);
    font-size: var(--zx-fs-xs);
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--zx-text-3);
    font-weight: 600;
}

.nsb-nav-item {
    display: flex;
    align-items: center;
    gap: var(--zx-space-3);
    padding: 10px var(--zx-space-4);
    color: var(--zx-text-2);
    font-size: var(--zx-fs);
    border-left: 3px solid transparent;
}
.nsb-nav-item:hover {
    background: var(--zx-surface-2);
    color: var(--zx-text);
    text-decoration: none;
}
.nsb-nav-item.is-active {
    background: var(--zx-orange-soft);
    color: var(--zx-orange-dark);
    border-left-color: var(--zx-orange);
    font-weight: 600;
}
.nsb-nav-item svg, .nsb-nav-item i { width: 18px; height: 18px; flex-shrink: 0; }

.nsb-sidebar__footer {
    border-top: 1px solid var(--zx-border);
    padding: var(--zx-space-3) var(--zx-space-4);
    font-size: var(--zx-fs-xs);
    color: var(--zx-text-3);
}

.nsb-main {
    flex: 1;
    margin-left: var(--zx-sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.nsb-topbar {
    height: var(--zx-topbar-h);
    background: var(--zx-surface);
    border-bottom: 1px solid var(--zx-border);
    display: flex;
    align-items: center;
    padding: 0 var(--zx-space-4);
    gap: var(--zx-space-3);
    position: sticky;
    top: 0;
    z-index: 30;
}

.nsb-topbar__title { font-weight: 600; font-size: var(--zx-fs-lg); flex: 1; }

.nsb-topbar__user {
    display: flex;
    align-items: center;
    gap: var(--zx-space-2);
    font-size: var(--zx-fs-sm);
    color: var(--zx-text-2);
}

.nsb-page-content {
    flex: 1;
    padding: var(--zx-space-5);
}

.zx-container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* =========================================================================
 * 5. Buttons
 * ========================================================================= */
.zx-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--zx-space-2);
    padding: 8px 14px;
    font-family: inherit;
    font-size: var(--zx-fs);
    font-weight: 500;
    border-radius: var(--zx-radius);
    border: 1px solid transparent;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
    text-decoration: none;
}
.zx-btn:hover { text-decoration: none; }

.zx-btn--primary {
    background: var(--zx-orange);
    color: var(--zx-text-invert);
}
.zx-btn--primary:hover { background: var(--zx-orange-dark); color: var(--zx-text-invert); }

.zx-btn--secondary {
    background: var(--zx-surface);
    border-color: var(--zx-border);
    color: var(--zx-text);
}
.zx-btn--secondary:hover { background: var(--zx-surface-2); }

.zx-btn--danger {
    background: var(--zx-danger);
    color: var(--zx-text-invert);
}
.zx-btn--danger:hover { filter: brightness(.92); }

.zx-btn--ghost {
    background: transparent;
    color: var(--zx-text-2);
}
.zx-btn--ghost:hover { background: var(--zx-surface-2); color: var(--zx-text); }

.zx-btn--sm { padding: 4px 10px; font-size: var(--zx-fs-sm); }
.zx-btn--lg { padding: 12px 20px; font-size: var(--zx-fs-lg); }

.zx-btn:disabled { opacity: .5; cursor: not-allowed; }

/* =========================================================================
 * 6. Forms
 * ========================================================================= */
.zx-field { margin-bottom: var(--zx-space-4); }

.zx-label {
    display: block;
    margin-bottom: var(--zx-space-1);
    font-size: var(--zx-fs-sm);
    font-weight: 500;
    color: var(--zx-text-2);
}

.zx-input, .zx-select, .zx-textarea {
    width: 100%;
    padding: 8px 12px;
    font-family: inherit;
    font-size: var(--zx-fs);
    color: var(--zx-text);
    background: var(--zx-surface);
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.zx-input:focus, .zx-select:focus, .zx-textarea:focus {
    border-color: var(--zx-orange);
    box-shadow: 0 0 0 3px var(--zx-orange-soft);
}
.zx-textarea { min-height: 100px; resize: vertical; }

.zx-help {
    margin-top: var(--zx-space-1);
    font-size: var(--zx-fs-xs);
    color: var(--zx-text-3);
}

.zx-error {
    margin-top: var(--zx-space-1);
    font-size: var(--zx-fs-xs);
    color: var(--zx-danger);
}

/* =========================================================================
 * 7. Cards + panels
 * ========================================================================= */
.zx-card {
    background: var(--zx-surface);
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius-lg);
    box-shadow: var(--zx-shadow-sm);
    padding: var(--zx-space-5);
    margin-bottom: var(--zx-space-4);
}

.zx-card__title {
    font-size: var(--zx-fs-lg);
    font-weight: 600;
    margin-bottom: var(--zx-space-3);
}

.zx-card__subtitle {
    font-size: var(--zx-fs-sm);
    color: var(--zx-text-3);
    margin-top: calc(-1 * var(--zx-space-2));
    margin-bottom: var(--zx-space-3);
}

/* =========================================================================
 * 8. Tables
 * ========================================================================= */
.zx-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius);
    background: var(--zx-surface);
}

.zx-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--zx-fs-sm);
}
.zx-table th, .zx-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--zx-border-soft);
}
.zx-table th {
    background: var(--zx-surface-2);
    font-weight: 600;
    color: var(--zx-text-2);
    font-size: var(--zx-fs-xs);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.zx-table tr:last-child td { border-bottom: none; }
.zx-table tbody tr:hover { background: var(--zx-surface-2); }

/* =========================================================================
 * 9. Badges + status pills
 * ========================================================================= */
.zx-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--zx-fs-xs);
    font-weight: 600;
    border-radius: var(--zx-radius-pill);
    background: var(--zx-surface-2);
    color: var(--zx-text-2);
    line-height: 1.6;
}
.zx-badge--success { background: var(--zx-success-soft); color: var(--zx-success); }
.zx-badge--warning { background: var(--zx-warning-soft); color: var(--zx-warning); }
.zx-badge--danger  { background: var(--zx-danger-soft);  color: var(--zx-danger); }
.zx-badge--info    { background: var(--zx-info-soft);    color: var(--zx-info); }
.zx-badge--orange  { background: var(--zx-orange-soft);  color: var(--zx-orange-dark); }
.zx-badge--gold    { background: var(--zx-gold-soft);    color: var(--zx-gold); }

/* =========================================================================
 * 10. Alerts / flash messages
 * ========================================================================= */
.zx-alert {
    padding: 10px 14px;
    border-radius: var(--zx-radius);
    border: 1px solid transparent;
    font-size: var(--zx-fs-sm);
    margin-bottom: var(--zx-space-4);
}
.zx-alert--success { background: var(--zx-success-soft); color: var(--zx-success); border-color: var(--zx-success); }
.zx-alert--error   { background: var(--zx-danger-soft);  color: var(--zx-danger);  border-color: var(--zx-danger); }
.zx-alert--warning { background: var(--zx-warning-soft); color: var(--zx-warning); border-color: var(--zx-warning); }
.zx-alert--info    { background: var(--zx-info-soft);    color: var(--zx-info);    border-color: var(--zx-info); }

/* =========================================================================
 * 11. Utility classes
 * ========================================================================= */
.zx-flex        { display: flex; }
.zx-flex-col    { flex-direction: column; }
.zx-items-center{ align-items: center; }
.zx-justify-between { justify-content: space-between; }
.zx-gap-2       { gap: var(--zx-space-2); }
.zx-gap-3       { gap: var(--zx-space-3); }
.zx-gap-4       { gap: var(--zx-space-4); }
.zx-mt-3        { margin-top: var(--zx-space-3); }
.zx-mt-4        { margin-top: var(--zx-space-4); }
.zx-mb-4        { margin-bottom: var(--zx-space-4); }
.zx-text-sm     { font-size: var(--zx-fs-sm); }
.zx-text-xs     { font-size: var(--zx-fs-xs); }
.zx-text-muted  { color: var(--zx-text-3); }
.zx-text-center { text-align: center; }
.zx-text-right  { text-align: right; }

/* =========================================================================
 * 12. Responsive — mobile drawer + bottom nav
 * ========================================================================= */
.nsb-mobile-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--zx-mobile-nav-h);
    background: var(--zx-surface);
    border-top: 1px solid var(--zx-border);
    z-index: 50;
}
.nsb-mobile-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 11px;
    color: var(--zx-text-3);
}
.nsb-mobile-nav__item.is-active { color: var(--zx-orange); }
.nsb-mobile-nav__item svg, .nsb-mobile-nav__item i { width: 20px; height: 20px; }

.nsb-sidebar__toggle {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--zx-text-2);
}

.nsb-sidebar__overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 35;
}

@media (max-width: 900px) {
    .nsb-sidebar {
        transform: translateX(-100%);
    }
    .nsb-sidebar.is-open {
        transform: translateX(0);
    }
    .nsb-sidebar__toggle { display: inline-flex; }
    .nsb-sidebar__overlay.is-open { display: block; }

    .nsb-main {
        margin-left: 0;
        padding-bottom: var(--zx-mobile-nav-h);
    }
    .nsb-page-content { padding: var(--zx-space-3); }
    .nsb-mobile-nav { display: flex; }

    h1 { font-size: var(--zx-fs-xl); }
    h2 { font-size: var(--zx-fs-lg); }
}

@media (max-width: 600px) {
    .zx-card { padding: var(--zx-space-4); }
    .zx-table th, .zx-table td { padding: 8px 10px; }
}
/* =========================================================================
 * 13. Login modal overlay (JS-triggered)
 *
 * Hidden by default. Shown when .is-open is added by login_modal.php's JS
 * (either via a data-zx-login-trigger click, or auto on protected pages).
 * ========================================================================= */
body.zx-modal-open {
    overflow: hidden;
}

body.zx-modal-open .nsb-main,
body.zx-modal-open .auth-page-bg {
    filter: blur(3px);
    pointer-events: none;
    user-select: none;
}

.zx-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--zx-space-4);
}

.zx-modal-backdrop.is-open {
    display: flex;
    opacity: 0;
    animation: zx-modal-fade .18s ease forwards;
}

@keyframes zx-modal-fade {
    to { opacity: 1; }
}

.zx-modal-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: var(--zx-surface);
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius-lg);
    box-shadow: var(--zx-shadow-lg);
    padding: var(--zx-space-6);
    transform: translateY(8px);
    animation: zx-modal-rise .2s ease forwards;
}

@keyframes zx-modal-rise {
    to { transform: translateY(0); }
}

.zx-modal-brand {
    text-align: center;
    margin-bottom: var(--zx-space-5);
}
.zx-modal-brand__name {
    font-size: var(--zx-fs-2xl);
    font-weight: 700;
    color: var(--zx-text);
}
.zx-modal-brand__name .accent { color: var(--zx-orange); }
.zx-modal-brand__tag {
    font-size: var(--zx-fs-sm);
    color: var(--zx-text-3);
    margin-top: var(--zx-space-1);
}

.zx-modal-links {
    margin-top: var(--zx-space-4);
    text-align: center;
    font-size: var(--zx-fs-sm);
    color: var(--zx-text-3);
}

.zx-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--zx-text-3);
    font-size: 22px;
    line-height: 1;
    padding: 4px 10px;
    cursor: pointer;
    border-radius: var(--zx-radius-sm);
}
.zx-modal-close:hover {
    background: var(--zx-surface-2);
    color: var(--zx-text);
}
/* =========================================================================
 * 14. Responsive grids
 *
 * Used by lead-detail, lead-new, lead-edit, dashboard, etc.
 * Collapse to single column under 900px.
 * ========================================================================= */
.zx-grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--zx-space-4);
}
.zx-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--zx-space-4);
}
.zx-grid-2-1 {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--zx-space-4);
    align-items: start;
}
.zx-grid-detail {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: var(--zx-space-3) var(--zx-space-4);
    font-size: var(--zx-fs-sm);
}

/* Stack the two-column page shell (left main + right sidebar) on mobile. */
@media (max-width: 900px) {
    .zx-grid-2,
    .zx-grid-3,
    .zx-grid-2-1 {
        grid-template-columns: minmax(0, 1fr);
    }
    /* Detail rows: label above value on narrow screens. */
    .zx-grid-detail {
        grid-template-columns: 1fr;
        gap: 2px;
    }
    .zx-grid-detail > div:nth-child(odd) {
        margin-top: var(--zx-space-3);
    }
    .zx-grid-detail > div:nth-child(odd):first-child {
        margin-top: 0;
    }
}

/* Reduce card padding on very small screens. */
@media (max-width: 600px) {
    .zx-card {
        padding: var(--zx-space-4) var(--zx-space-3);
    }
    /* Make the header actions stack. */
    .nsb-topbar {
        padding: 0 var(--zx-space-3);
    }
    /* Form fields: force single column even when a parent uses
       grid-template-columns: 1fr 1fr 1fr inline. */
    .zx-form-row {
        grid-template-columns: 1fr !important;
    }
}

/* Force any inline `display:grid;grid-template-columns:repeat(N, 1fr)` inside
   forms to stack on mobile by giving them this class. */
@media (max-width: 900px) {
    .zx-form-row {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}
/* =========================================================================
 * 15. Button + toolbar polish
 *
 * Guarantees consistent heights across .zx-btn, .zx-btn--sm, .zx-btn--lg
 * regardless of the icon/glyph inside, and gives us a canonical toolbar.
 * ========================================================================= */
.zx-btn {
    min-height: 34px;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
}
.zx-btn--sm { min-height: 28px; padding: 4px 10px; font-size: var(--zx-fs-sm); }
.zx-btn--lg { min-height: 42px; padding: 12px 20px; font-size: var(--zx-fs-lg); }

/* Toolbar: consistent gap, wrap, vertical alignment. */
.zx-toolbar {
    display: flex;
    align-items: center;
    gap: var(--zx-space-2);
    flex-wrap: wrap;
}
.zx-toolbar--right { justify-content: flex-end; }
.zx-toolbar--between { justify-content: space-between; }

/* Prevent double-click selection of button text. */
.zx-btn, .zx-row-action, .zx-tab { user-select: none; }

/* Make headings not inherit weird line-height from grids. */
h1, h2, h3 { line-height: 1.2; }

/* Metadata strip (e.g. "Source: Manual · Status: Active · Created ...") */
.zx-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    align-items: center;
    font-size: var(--zx-fs-sm);
    color: var(--zx-text-3);
}
.zx-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.zx-meta strong { color: var(--zx-text); font-weight: 600; }

/* Badges align nicer inside meta rows. */
.zx-meta .zx-badge { vertical-align: middle; }

/* Consistent card title + action row. */
.zx-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--zx-space-3);
    margin-bottom: var(--zx-space-3);
    flex-wrap: wrap;
}
.zx-card__head .zx-card__title { margin: 0; }

/* Stat cards — fixed padding and centered numerals. */
.zx-stat {
    text-align: center;
    padding: var(--zx-space-4);
}
.zx-stat__label {
    font-size: var(--zx-fs-xs);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
    color: var(--zx-text-3);
}
.zx-stat__value {
    font-size: var(--zx-fs-2xl);
    font-weight: 700;
    margin-top: 6px;
    color: var(--zx-text);
}
.zx-stat__value--orange  { color: var(--zx-orange); }
.zx-stat__value--info    { color: var(--zx-info); }
.zx-stat__value--warning { color: var(--zx-warning); }
.zx-stat__value--success { color: var(--zx-success); }

/* Fix any inline padding inside page-header blocks that fight with grids. */
.zx-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--zx-space-3);
    flex-wrap: wrap;
    margin-bottom: var(--zx-space-4);
}
/* =========================================================================
 * 16. Modal system (AJAX-loaded forms)
 *
 * Usage:
 *   <div class="zx-modal" id="my-modal"> ... </div>
 *   JS: zxModal.open('#my-modal'); zxModal.close('#my-modal');
 * ========================================================================= */
.zx-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: var(--zx-space-5) var(--zx-space-4);
    z-index: 900;
    overflow-y: auto;
}
.zx-modal.is-open {
    display: flex;
    animation: zx-modal-fade .15s ease;
}
@keyframes zx-modal-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.zx-modal__panel {
    background: var(--zx-surface);
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius-lg);
    box-shadow: var(--zx-shadow-lg);
    width: 100%;
    max-width: 640px;
    margin: auto;
    position: relative;
    transform: translateY(8px);
    animation: zx-modal-rise .2s ease forwards;
    max-height: calc(100vh - var(--zx-space-5) * 2);
    display: flex;
    flex-direction: column;
}
.zx-modal__panel--wide { max-width: 880px; }
.zx-modal__panel--narrow { max-width: 420px; }

@keyframes zx-modal-rise {
    to { transform: translateY(0); }
}

.zx-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--zx-space-4) var(--zx-space-5);
    border-bottom: 1px solid var(--zx-border-soft);
    flex-shrink: 0;
}
.zx-modal__title {
    font-size: var(--zx-fs-lg);
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--zx-space-2);
}
.zx-modal__close {
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--zx-text-3);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--zx-radius-sm);
}
.zx-modal__close:hover { background: var(--zx-surface-2); color: var(--zx-text); }

.zx-modal__body {
    padding: var(--zx-space-5);
    overflow-y: auto;
    flex: 1;
}
.zx-modal__foot {
    display: flex;
    gap: var(--zx-space-2);
    justify-content: flex-end;
    padding: var(--zx-space-4) var(--zx-space-5);
    border-top: 1px solid var(--zx-border-soft);
    background: var(--zx-surface-2);
    border-radius: 0 0 var(--zx-radius-lg) var(--zx-radius-lg);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.zx-modal__foot--between { justify-content: space-between; }

.zx-modal__loading {
    padding: var(--zx-space-7) var(--zx-space-5);
    text-align: center;
    color: var(--zx-text-3);
    font-size: var(--zx-fs-sm);
}

/* Body scroll lock while a modal is open. */
body.zx-modal-locked { overflow: hidden; }

@media (max-width: 600px) {
    .zx-modal { padding: var(--zx-space-3); }
    .zx-modal__body { padding: var(--zx-space-4); }
    .zx-modal__head,
    .zx-modal__foot { padding: var(--zx-space-3) var(--zx-space-4); }
    .zx-modal__panel { max-height: calc(100vh - var(--zx-space-3) * 2); }
}

/* =========================================================================
 * 17. Live-search helper
 * ========================================================================= */
.zx-search-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.zx-search-wrap .zx-input { padding-right: 32px; }
.zx-search-spinner {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--zx-border);
    border-top-color: var(--zx-orange);
    animation: zx-spin .7s linear infinite;
    display: none;
}
.zx-search-wrap.is-loading .zx-search-spinner { display: block; }
@keyframes zx-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Content swap target */
.zx-swap.is-loading { opacity: .55; pointer-events: none; }

/* =========================================================================
 * 18. Avatar sizes
 * ========================================================================= */
.zx-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--zx-orange);
    color: #fff;
    font-weight: 600;
    flex-shrink: 0;
}
.zx-avatar--xs { width: 22px; height: 22px; font-size: 10px; }
.zx-avatar--sm { width: 28px; height: 28px; font-size: 12px; }
.zx-avatar--md { width: 40px; height: 40px; font-size: 15px; }
.zx-avatar--lg { width: 56px; height: 56px; font-size: 20px; }

/* =========================================================================
 * 19. Dropdown polish (row action menus)
 * ========================================================================= */
.zx-dropdown { display: inline-block; position: relative; }
.zx-dropdown__toggle {
    padding: 4px 10px;
    font-size: 16px;
    line-height: 1;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--zx-radius-sm);
    color: var(--zx-text-2);
    cursor: pointer;
    min-height: 28px;
}
.zx-dropdown__toggle:hover { background: var(--zx-surface-2); }

.zx-dropdown__menu {
    position: fixed;
    background: var(--zx-surface);
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius);
    box-shadow: var(--zx-shadow-lg);
    min-width: 170px;
    padding: 4px 0;
    display: none;
    z-index: 1100;
}
.zx-dropdown__menu.is-open { display: block; }
.zx-dropdown__menu form { margin: 0; }
.zx-dropdown__menu button,
.zx-dropdown__menu a {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    font-size: var(--zx-fs-sm);
    color: var(--zx-text);
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}
.zx-dropdown__menu button:hover,
.zx-dropdown__menu a:hover {
    background: var(--zx-surface-2);
    text-decoration: none;
}
/* =========================================================================
 * 23. Table overflow — the wrapper scrolls, the card clips nothing
 * ========================================================================= */

/* Cards that contain a table wrap should not clip overflow — the wrap
   handles it. Remove overflow:hidden from .zx-card when it contains a
   .zx-table-wrap. */
.zx-card:has(> .zx-table-wrap),
.zx-card:has(.zx-table-wrap) {
    overflow: visible;
}

/* The wrapper is a scroll container. */
.zx-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    border-radius: var(--zx-radius);
}

/* Prevent the table from shrinking columns; let it scroll. */
.zx-table-wrap > .zx-table {
    min-width: max-content;
}