/**
 * Ecombooster — Shared UI Components
 *
 * Reusable component styles for all modern admin views (hubs and standalone).
 * Prefix: ecb-*
 *
 * Components:
 *   Layout:   ecb-layout, ecb-sidebar, ecb-main, ecb-grid-2, ecb-grid-3
 *   KPI:      ecb-kpis, ecb-kpi-card, ecb-kpi-value, ecb-kpi-label, ecb-kpi-trend
 *   Sections: ecb-section, ecb-section-title
 *   Tables:   ecb-table, ecb-sortable (sortable headers)
 *   Badges:   ecb-badge (.draft/.approved/.published/.rejected/.info/.warning)
 *   Scores:   ecb-score (.excellent/.good/.average/.poor)
 *   Tabs:     ecb-tabs, ecb-tab, ecb-tab-panel
 *   Buttons:  ecb-btn, ecb-btn-primary, ecb-btn-secondary, ecb-btn-danger, ecb-btn-sm
 *   Modals:   ecb-modal-overlay, ecb-modal, ecb-modal-header/body/footer
 *   Loading:  ecb-loading, ecb-spinner
 *   Charts:   ecb-chart-container
 *   Toast:    ecb-toast
 *   Search:   ecb-search-dropdown, ecb-search-item
 *   Forms:    ecb-form-group, ecb-explanation
 */

/* ==========================================================================
   Design tokens — modern UI palette
   --------------------------------------------------------------------------
   These mirror the tokens shipped by the Tailwind build (frontend/tailwind.config.js)
   so non-`.twp`-scoped views (hubs, classic admin) get the same brand colors
   that Tailwind utilities produce inside `.twp`. The Tailwind config references
   these via `var(--ecb-*, <fallback>)` — defining them here makes the variable
   path active globally, not just inside the Tailwind bundle.
   ========================================================================== */
:root {
    --ecb-primary: #417690;
    --ecb-primary-dark: #2d5468;
    --ecb-text: #1f2937;
    --ecb-text-soft: #4b5563;
    --ecb-bg: #ffffff;
    --ecb-bg-soft: #f9fafb;
    --ecb-border: #e5e7eb;
    --ecb-success: #059669;
    --ecb-warning: #d97706;
    --ecb-danger: #dc2626;

    /* Theme tokens — light defaults. Switched in [data-theme="dark"] block below.
       The FOUC-prevention script in modern/base.html + common/hub_base.html sets
       data-theme on <html> from localStorage before CSS loads, so dark renders
       on first paint without flashing the light palette. */
    --theme-bg:             #f8fafc;  /* page background (slate-50) */
    --theme-bg-elevated:    #ffffff;  /* card / panel background */
    --theme-bg-subtle:      #f1f5f9;  /* hover background, secondary fill (slate-100) */
    --theme-fg:             #0f172a;  /* primary text (slate-900) */
    --theme-fg-muted:       #475569;  /* secondary text (slate-600) */
    --theme-fg-subtle:      #94a3b8;  /* tertiary text, placeholders (slate-400) */
    --theme-border:         #e2e8f0;  /* default border (slate-200) */
    --theme-border-strong:  #cbd5e1;  /* focused border (slate-300) */
    --theme-shadow-1:       0 1px 0 rgba(16, 24, 40, 0.03), 0 1px 2px rgba(16, 24, 40, 0.05);
    --theme-shadow-2:       0 4px 12px rgba(15, 23, 42, 0.08);
    --theme-primary:        var(--ecb-primary, #417690);
    --theme-primary-soft:   rgba(65, 118, 144, 0.10);  /* primary tinted background */
    --theme-success:        #15803d;  /* green-700 */
    --theme-warning:        #b45309;  /* amber-700 */
    --theme-danger:         #b91c1c;  /* red-700 */
}

[data-theme="dark"] {
    --theme-bg:             #0f172a;  /* slate-900 */
    --theme-bg-elevated:    #1e293b;  /* slate-800 */
    --theme-bg-subtle:      #334155;  /* slate-700 */
    --theme-fg:             #f1f5f9;  /* slate-100 */
    --theme-fg-muted:       #cbd5e1;  /* slate-300 */
    --theme-fg-subtle:      #94a3b8;  /* slate-400 */
    --theme-border:         #334155;  /* slate-700 */
    --theme-border-strong:  #475569;  /* slate-600 */
    --theme-shadow-1:       0 1px 0 rgba(0, 0, 0, 0.30), 0 2px 4px rgba(0, 0, 0, 0.40);
    --theme-shadow-2:       0 4px 12px rgba(0, 0, 0, 0.45);
    --theme-primary:        #6fa9c2;  /* lighter ecb-primary for dark bg contrast */
    --theme-primary-soft:   rgba(111, 169, 194, 0.15);
    --theme-success:        #4ade80;  /* green-400 */
    --theme-warning:        #fbbf24;  /* amber-400 */
    --theme-danger:         #f87171;  /* red-400 */
}

/* Body / shell paints the page background in the current theme. Modern shell
   templates and hub_base.html set body bg directly; those can stay as
   var(--theme-bg) once migrated. This rule is the default for any body
   that doesn't override. */
html[data-theme] body { background: var(--theme-bg); color: var(--theme-fg); }

/* Brand logo swap — show the blue mark on light, the white mark on dark. */
.theme-logo-light { display: inline-block; }
.theme-logo-dark { display: none; }
[data-theme="dark"] .theme-logo-light { display: none; }
[data-theme="dark"] .theme-logo-dark { display: inline-block; }

/* Alpine.js compatibility — needs the [x-cloak] rule to hide elements until
   Alpine initialises, and a button reset inside .twp so Tailwind utility
   classes work on <button> without inheriting browser default bg/borders.
   Lived in modern/base.html only; moved here so hub_base.html (which extends
   admin/base_site.html, not modern/base.html) also gets them. */
[x-cloak] { display: none !important; }
.twp button { background: none; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; }
.twp button:disabled { cursor: not-allowed; }
.twp a { color: inherit; text-decoration: none; }
.twp *, .twp *::before, .twp *::after { box-sizing: border-box; }

/* ==========================================================================
   Fix Django admin select/input overrides
   ========================================================================== */

.ecb-main select,
.ecb-main input[type="text"],
.ecb-main input[type="number"],
.ecb-main input[type="month"],
.ecb-main textarea {
    box-sizing: border-box;
    height: auto;
    min-height: 38px;
    line-height: 1.4;
    font-size: 14px;
}

.ecb-main select {
    padding: 8px 12px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
    padding-right: 32px;
}

/* ==========================================================================
   Layout: sidebar + main
   ========================================================================== */

.ecb-layout {
    display: flex;
    gap: 20px;
    min-height: 600px;
    margin: 0;
}

/* Sidebar navigation — uses theme tokens so it switches with light/dark mode. */
.ecb-sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--theme-bg-elevated);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    padding: 12px 0 8px 0;
    box-shadow: var(--theme-shadow-1);
    align-self: flex-start;
}

.ecb-nav,
.ecb-sidebar .ecb-nav,
.ecb-sidebar ul.ecb-nav {
    list-style: none !important;
    list-style-type: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ecb-nav-item,
.ecb-sidebar .ecb-nav-item,
.ecb-sidebar ul.ecb-nav li.ecb-nav-item {
    display: block !important;
    list-style: none !important;
    list-style-type: none !important;
    list-style-image: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ecb-nav-item::marker,
.ecb-sidebar li::marker { content: '' !important; display: none !important; }
.ecb-nav-item::before,
.ecb-sidebar li::before { content: none !important; }

.ecb-nav-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--theme-fg-muted);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ecb-nav-item a:hover {
    background: var(--theme-bg-subtle);
    color: var(--theme-fg);
}

.ecb-nav-item.active a {
    background: var(--theme-bg-subtle);
    color: var(--theme-primary);
    font-weight: 600;
    border-left-color: var(--theme-primary);
}

.ecb-nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    color: var(--theme-fg-subtle);
}

.ecb-nav-item.active .ecb-nav-icon { color: var(--theme-primary); }

.ecb-nav-label {
    flex: 1;
}

.ecb-badge-su {
    font-size: 9px;
    font-weight: 700;
    background: var(--theme-bg-subtle);
    color: var(--theme-fg-subtle);
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ecb-nav-group-label {
    margin: 14px 16px 6px 16px;
    color: var(--theme-fg-subtle);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.ecb-nav-group-label:first-child {
    margin-top: 4px;
}

.ecb-nav-group-divider {
    margin: 10px 16px;
    border-top: 1px solid var(--theme-border);
}

/* Dark theme overrides for Tailwind utilities used inside the modern shell header.
   The header (in templates/modern/base.html and templates/common/hub_base.html)
   uses utility classes like bg-white/90, border-slate-200, text-slate-600, hover:bg-slate-100.
   In dark mode we remap those utilities to theme tokens. Scoped to .twp > header so
   we don't accidentally touch utilities used in modern view content. */
[data-theme="dark"] .twp > header {
    background: rgba(15, 23, 42, 0.92) !important;   /* slate-900/92 */
    border-color: var(--theme-border) !important;
}
[data-theme="dark"] .twp > header .text-slate-600 { color: var(--theme-fg-muted) !important; }
[data-theme="dark"] .twp > header .text-slate-500 { color: var(--theme-fg-subtle) !important; }
[data-theme="dark"] .twp > header .text-slate-900 { color: var(--theme-fg) !important; }
[data-theme="dark"] .twp > header .text-slate-400 { color: var(--theme-fg-subtle) !important; }
[data-theme="dark"] .twp > header .border-slate-200 { border-color: var(--theme-border) !important; }
[data-theme="dark"] .twp > header .hover\:bg-slate-100:hover { background: var(--theme-bg-subtle) !important; }
[data-theme="dark"] .twp > header .bg-slate-100 { background: var(--theme-bg-subtle) !important; }
[data-theme="dark"] .twp > header .hover\:text-ecb-primary:hover { color: var(--theme-primary) !important; }

/* Broad Tailwind-utility dark overrides for any .twp-scoped element (modern
   catalog list/detail, modern components, hub shell header dropdowns).
   Scoped to `.twp` so legacy admin chrome is unaffected. */
[data-theme="dark"] .twp .bg-white { background: var(--theme-bg-elevated) !important; }
[data-theme="dark"] .twp .bg-slate-50 { background: var(--theme-bg) !important; }
[data-theme="dark"] .twp .bg-slate-100 { background: var(--theme-bg-subtle) !important; }
[data-theme="dark"] .twp .bg-slate-200 { background: var(--theme-bg-subtle) !important; }

[data-theme="dark"] .twp .text-slate-300 { color: var(--theme-fg-subtle) !important; }
[data-theme="dark"] .twp .text-slate-400 { color: var(--theme-fg-subtle) !important; }
[data-theme="dark"] .twp .text-slate-500 { color: var(--theme-fg-muted) !important; }
[data-theme="dark"] .twp .text-slate-600 { color: var(--theme-fg-muted) !important; }
[data-theme="dark"] .twp .text-slate-700 { color: var(--theme-fg) !important; }
[data-theme="dark"] .twp .text-slate-800 { color: var(--theme-fg) !important; }
[data-theme="dark"] .twp .text-slate-900 { color: var(--theme-fg) !important; }

[data-theme="dark"] .twp .border-slate-100 { border-color: var(--theme-border) !important; }
[data-theme="dark"] .twp .border-slate-200 { border-color: var(--theme-border) !important; }
[data-theme="dark"] .twp .border-slate-300 { border-color: var(--theme-border-strong) !important; }
[data-theme="dark"] .twp .border-slate-400 { border-color: var(--theme-border-strong) !important; }
[data-theme="dark"] .twp .divide-slate-100 > * { border-color: var(--theme-border) !important; }
[data-theme="dark"] .twp .divide-slate-200 > * { border-color: var(--theme-border) !important; }

[data-theme="dark"] .twp .hover\:bg-slate-50:hover { background: var(--theme-bg-subtle) !important; }
[data-theme="dark"] .twp .hover\:bg-slate-100:hover { background: var(--theme-bg-subtle) !important; }
[data-theme="dark"] .twp .hover\:text-slate-700:hover { color: var(--theme-fg) !important; }
[data-theme="dark"] .twp .hover\:text-slate-900:hover { color: var(--theme-fg) !important; }

[data-theme="dark"] .twp .placeholder\:text-slate-400::placeholder,
[data-theme="dark"] .twp input::placeholder,
[data-theme="dark"] .twp textarea::placeholder { color: var(--theme-fg-subtle) !important; }

/* Tinted "soft" semantic backgrounds (badges, banners) — darken slightly so
   light tints (rose-50, amber-50, sky-50, emerald-50) read on a dark page. */
[data-theme="dark"] .twp .bg-rose-50 { background: rgba(244, 63, 94, 0.15) !important; }
[data-theme="dark"] .twp .bg-rose-100 { background: rgba(244, 63, 94, 0.20) !important; }
[data-theme="dark"] .twp .bg-amber-50 { background: rgba(245, 158, 11, 0.15) !important; }
[data-theme="dark"] .twp .bg-amber-100 { background: rgba(245, 158, 11, 0.20) !important; }
[data-theme="dark"] .twp .bg-emerald-50 { background: rgba(16, 185, 129, 0.15) !important; }
[data-theme="dark"] .twp .bg-emerald-100 { background: rgba(16, 185, 129, 0.20) !important; }
[data-theme="dark"] .twp .bg-sky-50 { background: rgba(14, 165, 233, 0.15) !important; }
[data-theme="dark"] .twp .bg-blue-50 { background: rgba(59, 130, 246, 0.15) !important; }
[data-theme="dark"] .twp .bg-blue-100 { background: rgba(59, 130, 246, 0.20) !important; }

/* Main content area */
.ecb-main {
    flex: 1;
    padding: 0;
    background: transparent;
    border-radius: 0;
    min-width: 0;
}

/* ==========================================================================
   KPI Cards
   ========================================================================== */

.ecb-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.ecb-kpi-card {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px 20px;
    text-align: center;
}

.ecb-kpi-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    color: #333;
}

.ecb-kpi-value.good { color: #0a7e0a; }
.ecb-kpi-value.warning { color: #a87000; }
.ecb-kpi-value.bad { color: #c00; }

.ecb-kpi-label {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ecb-kpi-trend {
    font-size: 12px;
    margin-top: 4px;
}

.ecb-kpi-trend.up { color: #0a7e0a; }
.ecb-kpi-trend.down { color: #c00; }

/* ==========================================================================
   Section containers
   ========================================================================== */

.ecb-section {
    margin-bottom: 28px;
}

.ecb-section-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #e0e0e0;
}

/* ==========================================================================
   Tables
   ========================================================================== */

.ecb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ecb-table th {
    text-align: left;
    padding: 8px 12px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    font-weight: 600;
    color: #555;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ecb-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.ecb-table tr:hover td {
    background: #f8f9fa;
}

/* Sortable table headers */
.ecb-table th.ecb-sortable {
    cursor: pointer;
    user-select: none;
}

.ecb-table th.ecb-sortable:hover {
    color: var(--header-bg, #417690);
}

.ecb-table th .ecb-sort-arrow {
    font-size: 10px;
    margin-left: 3px;
    color: #999;
}

.ecb-table th.ecb-sort-active .ecb-sort-arrow {
    color: var(--header-bg, #417690);
}

/* ==========================================================================
   Status badges
   ========================================================================== */

.ecb-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.ecb-badge.draft { background: #fff3cd; color: #856404; }
.ecb-badge.approved { background: #d4edda; color: #155724; }
.ecb-badge.published { background: #cce5ff; color: #004085; }
.ecb-badge.rejected { background: #f8d7da; color: #721c24; }
.ecb-badge.info { background: #e3f2fd; color: #1565c0; }
.ecb-badge.warning { background: #fff3cd; color: #856404; }

/* ==========================================================================
   Score indicators
   ========================================================================== */

.ecb-score {
    display: inline-block;
    font-weight: 700;
    font-size: 13px;
}

.ecb-score.excellent { color: #0a7e0a; }
.ecb-score.good { color: #2e7d32; }
.ecb-score.average { color: #a87000; }
.ecb-score.poor { color: #c00; }

/* ==========================================================================
   Tabs
   ========================================================================== */

.ecb-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

.ecb-tab {
    padding: 10px 20px;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    cursor: pointer;
}

.ecb-tab:hover {
    color: #333;
}

.ecb-tab.active {
    color: var(--header-bg, #417690);
    border-bottom-color: var(--header-bg, #417690);
    font-weight: 600;
}

/* ==========================================================================
   Charts
   ========================================================================== */

.ecb-chart-container {
    position: relative;
    height: 250px;
    max-width: 100%;
}

/* ==========================================================================
   Grid sections
   ========================================================================== */

.ecb-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.ecb-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 24px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.ecb-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.ecb-btn-primary {
    background: var(--header-bg, #417690);
    color: #fff !important;
}

.ecb-btn-primary:hover {
    background: #205067;
    color: #fff !important;
}

.ecb-btn,
.ecb-btn-secondary {
    background: var(--theme-bg-subtle);
    color: var(--theme-fg);
}

.ecb-btn:hover,
.ecb-btn-secondary:hover {
    background: var(--theme-border);
}

/* Restore explicit primary / danger backgrounds.
   `.ecb-btn` and `.ecb-btn-secondary` share a `background: subtle` rule
   defined after `.ecb-btn-primary` above. Same specificity (one class
   each) means the later rule wins, which silently turns primary buttons
   into subtle/grey ones. The compound `.ecb-btn.ecb-btn-primary`
   selector below has higher specificity (two classes) and pins both the
   background and colour back to the intended primary/danger values. */
.ecb-btn.ecb-btn-primary {
    background: var(--header-bg, #417690);
    color: #fff !important;
}
.ecb-btn.ecb-btn-primary:hover {
    background: #205067;
}
.ecb-btn.ecb-btn-danger {
    background: #c62828;
    color: #fff !important;
}
.ecb-btn.ecb-btn-danger:hover {
    background: #962020;
}

.ecb-btn-danger {
    background: #c62828;
    color: #fff !important;
}

.ecb-btn-danger:hover {
    background: #9a1c1c;
    color: #fff !important;
}

.ecb-btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.ecb-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Modals
   ========================================================================== */

.ecb-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ecb-modal {
    background: #fff;
    border-radius: 10px;
    width: 600px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.ecb-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #e0e0e0;
}

.ecb-modal-header h3 {
    font-size: 18px;
    margin: 0;
}

.ecb-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #888;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.ecb-modal-close:hover { color: #333; }

.ecb-modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.ecb-modal-footer {
    padding: 12px 24px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ==========================================================================
   Loading states
   ========================================================================== */

.ecb-loading {
    text-align: center;
    padding: 40px 20px;
    color: #888;
}

.ecb-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--header-bg, #417690);
    border-radius: 50%;
    animation: ecb-spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Toast notifications
   ========================================================================== */

.ecb-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    min-width: 280px;
    max-width: 420px;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 13px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.ecb-toast.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.ecb-toast.success { background: #28a745; }
.ecb-toast.error { background: #dc3545; }
.ecb-toast.info { background: var(--header-bg, #417690); }
.ecb-toast.warning { background: #e65100; }

/* ==========================================================================
   Search dropdown (autocomplete)
   ========================================================================== */

.ecb-search-dropdown {
    display: none;
    position: absolute;
    z-index: 200;
    left: 0; right: 0;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .1);
}

.ecb-search-dropdown.open {
    display: block;
}

.ecb-search-item {
    padding: 8px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
}

.ecb-search-item:hover,
.ecb-search-item.highlighted {
    background: #f0f7ff;
}

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

/* ==========================================================================
   Form groups & explanations
   ========================================================================== */

.ecb-form-group {
    margin-bottom: 12px;
}

.ecb-form-group label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    font-weight: 600;
}

.ecb-explanation {
    background: #f0f7ff;
    border: 1px solid #cce5ff;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 13px;
    color: #333;
    margin-bottom: 16px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
    .ecb-layout {
        flex-direction: column;
        margin: -10px -20px;
    }
    .ecb-sidebar {
        width: 100%;
        min-width: 100%;
        border-radius: 4px 4px 0 0;
        padding: 4px 0;
    }
    .ecb-nav {
        display: flex;
        overflow-x: auto;
    }
    .ecb-nav-item a {
        padding: 8px 16px;
        white-space: nowrap;
    }
    .ecb-nav-item.active a {
        border-left: none;
        border-bottom: 3px solid #fff;
        padding-left: 16px;
    }
    .ecb-main {
        border-radius: 0 0 4px 4px;
        padding: 16px;
    }
    .ecb-grid-2,
    .ecb-grid-3 {
        grid-template-columns: 1fr;
    }
    .ecb-kpis {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}

/* ==========================================================================
   Dark mode
   ========================================================================== */

/* Dark theme overrides for shared hub components.
   Driven by [data-theme="dark"] which is set on <html> by the FOUC-prevention
   script in modern/base.html + hub_base.html (which honours either an explicit
   localStorage choice or the system prefers-color-scheme). Replaces the old
   @media (prefers-color-scheme: dark) block which used unrelated #2d2d2d-era
   greys — these tokens are slate-* aligned. */
[data-theme="dark"] .ecb-main { background: var(--theme-bg); }

[data-theme="dark"] .ecb-kpi-card { background: var(--theme-bg-elevated); border-color: var(--theme-border); }
[data-theme="dark"] .ecb-kpi-value { color: var(--theme-fg); }
[data-theme="dark"] .ecb-kpi-label { color: var(--theme-fg-muted); }
[data-theme="dark"] .ecb-kpi-value.good { color: var(--theme-success); }
[data-theme="dark"] .ecb-kpi-value.warning { color: var(--theme-warning); }
[data-theme="dark"] .ecb-kpi-value.bad { color: var(--theme-danger); }
[data-theme="dark"] .ecb-kpi-trend.up { color: var(--theme-success); }
[data-theme="dark"] .ecb-kpi-trend.down { color: var(--theme-danger); }

[data-theme="dark"] .ecb-section { background: var(--theme-bg-elevated); border-color: var(--theme-border); }
[data-theme="dark"] .ecb-section-title { color: var(--theme-fg); border-bottom-color: var(--theme-border); }

[data-theme="dark"] .ecb-table { background: var(--theme-bg-elevated); }
[data-theme="dark"] .ecb-table th { background: var(--theme-bg-subtle); border-bottom-color: var(--theme-border); color: var(--theme-fg-muted); }
[data-theme="dark"] .ecb-table td { border-bottom-color: var(--theme-border); color: var(--theme-fg); }
[data-theme="dark"] .ecb-table tr:hover td { background: var(--theme-bg-subtle); }
/* Defeat any zebra-striping (Django admin's nth-child rules etc.) by giving each
   row an explicit theme background. Hover wins via specificity below. */
[data-theme="dark"] .ecb-table tbody tr:nth-child(odd) td,
[data-theme="dark"] .ecb-table tbody tr:nth-child(even) td { background: var(--theme-bg-elevated); }
[data-theme="dark"] .ecb-table tbody tr:hover td,
[data-theme="dark"] .ecb-table tbody tr:nth-child(odd):hover td,
[data-theme="dark"] .ecb-table tbody tr:nth-child(even):hover td { background: var(--theme-bg-subtle); }

/* Universal zebra-striping defeat for ANY table inside .ecb-main in dark mode.
   Django admin's base CSS sets odd/even row backgrounds (white / #f9f9f9) on
   tables it considers part of the admin shell — those leak into our hub
   tables (.sa-table, .sh-table, .gp-table, .fc-matrix, .ai-preview-table etc.)
   and render light text on light bg. This rule wipes them so the hub's own
   colours show through. Hub-specific overrides win via more-specific selectors. */
[data-theme="dark"] .ecb-main table tbody tr,
[data-theme="dark"] .ecb-main table tbody tr td,
[data-theme="dark"] .ecb-main table tbody tr:nth-child(odd),
[data-theme="dark"] .ecb-main table tbody tr:nth-child(even),
[data-theme="dark"] .ecb-main table tbody tr:nth-child(odd) td,
[data-theme="dark"] .ecb-main table tbody tr:nth-child(even) td { background: transparent; color: var(--theme-fg); }
[data-theme="dark"] .ecb-main table tbody tr:hover td,
[data-theme="dark"] .ecb-main table tbody tr:nth-child(odd):hover td,
[data-theme="dark"] .ecb-main table tbody tr:nth-child(even):hover td { background: var(--theme-bg-subtle); }
/* Headers get a subtle theme-aware bg so they read as distinct from body rows
   without being jarring (matches the .sph-mini-table treatment). */
[data-theme="dark"] .ecb-main table thead th,
[data-theme="dark"] .ecb-main table thead tr,
[data-theme="dark"] .ecb-main table thead tr th { background: var(--theme-bg-subtle); color: var(--theme-fg-muted); border-bottom-color: var(--theme-border); }

/* Inline `<code>` / `<pre>` inside hub tables — keep text bright (not the
   muted fg-muted some admin CSS slips in), with a subtle bg tint so the
   monospace runs read as code. */
[data-theme="dark"] .ecb-main code,
[data-theme="dark"] .ecb-main pre,
[data-theme="dark"] .ecb-main td code,
[data-theme="dark"] .ecb-main td pre {
    color: var(--theme-fg);
    background: var(--theme-bg-subtle);
    padding: 1px 4px;
    border-radius: 3px;
}
[data-theme="dark"] .ecb-main pre,
[data-theme="dark"] .ecb-main td pre { padding: 8px 12px; }

[data-theme="dark"] .ecb-modal { background: var(--theme-bg-elevated); }
[data-theme="dark"] .ecb-modal-header { border-bottom-color: var(--theme-border); }
[data-theme="dark"] .ecb-modal-header h3 { color: var(--theme-fg); }
[data-theme="dark"] .ecb-modal-close { color: var(--theme-fg-subtle); }
[data-theme="dark"] .ecb-modal-close:hover { color: var(--theme-fg); }
[data-theme="dark"] .ecb-modal-body { color: var(--theme-fg); }
[data-theme="dark"] .ecb-modal-footer { border-top-color: var(--theme-border); }

[data-theme="dark"] .ecb-tab { color: var(--theme-fg-muted); }
[data-theme="dark"] .ecb-tab:hover { color: var(--theme-fg); }
[data-theme="dark"] .ecb-tab.active { color: var(--theme-primary); border-bottom-color: var(--theme-primary); }

[data-theme="dark"] .ecb-btn-secondary { background: var(--theme-bg-subtle); color: var(--theme-fg); border-color: var(--theme-border); }
[data-theme="dark"] .ecb-btn-secondary:hover { background: var(--theme-bg-elevated); }

[data-theme="dark"] .ecb-search-dropdown { background: var(--theme-bg-elevated); border-color: var(--theme-border); }
[data-theme="dark"] .ecb-search-item { border-bottom-color: var(--theme-border); color: var(--theme-fg); }
[data-theme="dark"] .ecb-search-item:hover,
[data-theme="dark"] .ecb-search-item.highlighted { background: var(--theme-bg-subtle); }

[data-theme="dark"] .ecb-explanation { background: var(--theme-bg-subtle); border-color: var(--theme-border); color: var(--theme-fg); }
[data-theme="dark"] .ecb-form-group label { color: var(--theme-fg-muted); }

[data-theme="dark"] .ecb-main input[type="text"],
[data-theme="dark"] .ecb-main input[type="number"],
[data-theme="dark"] .ecb-main input[type="month"],
[data-theme="dark"] .ecb-main input[type="date"],
[data-theme="dark"] .ecb-main input[type="datetime-local"],
[data-theme="dark"] .ecb-main input[type="email"],
[data-theme="dark"] .ecb-main input[type="search"],
[data-theme="dark"] .ecb-main input[type="tel"],
[data-theme="dark"] .ecb-main input[type="time"],
[data-theme="dark"] .ecb-main input[type="url"],
[data-theme="dark"] .ecb-main input[type="password"],
[data-theme="dark"] .ecb-main textarea {
    background: var(--theme-bg-subtle);  /* one notch lighter than .ecb-section cards (mirrors light-mode: white input on slate-50 page) */
    color: var(--theme-fg);
    border-color: var(--theme-border-strong);
}
/* Date pickers — invert the native calendar icon so it's visible on dark bg. */
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] .ecb-main input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] .ecb-main input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.85); }

/* Placeholder + date-input native sub-parts. Browsers render the "yyyy-mm-dd"
   pieces inside <input type="date"> via shadow-DOM substyles that don't inherit
   the parent color. Set them explicitly so empty/filled date inputs look the
   same as the text inputs next to them. */
[data-theme="dark"] .ecb-main input::placeholder,
[data-theme="dark"] .ecb-main textarea::placeholder { color: var(--theme-fg-subtle); }
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-datetime-edit,
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-datetime-edit-text,
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-datetime-edit-year-field,
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-datetime-edit-month-field,
[data-theme="dark"] .ecb-main input[type="date"]::-webkit-datetime-edit-day-field,
[data-theme="dark"] .ecb-main input[type="datetime-local"]::-webkit-datetime-edit,
[data-theme="dark"] .ecb-main input[type="datetime-local"]::-webkit-datetime-edit-text,
[data-theme="dark"] .ecb-main input[type="time"]::-webkit-datetime-edit,
[data-theme="dark"] .ecb-main input[type="time"]::-webkit-datetime-edit-text { color: var(--theme-fg-subtle); }
/* When the field has a value, parts read in regular fg colour. */
[data-theme="dark"] .ecb-main input[type="date"]:valid::-webkit-datetime-edit-year-field,
[data-theme="dark"] .ecb-main input[type="date"]:valid::-webkit-datetime-edit-month-field,
[data-theme="dark"] .ecb-main input[type="date"]:valid::-webkit-datetime-edit-day-field { color: var(--theme-fg); }
/* Select gets the shorthand kept intact so background-repeat: no-repeat and
   background-position: right 12px center stick (otherwise the SVG arrow tiles
   across the whole control). */
[data-theme="dark"] .ecb-main select {
    background: var(--theme-bg-subtle) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23cbd5e1' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
    color: var(--theme-fg);
    border-color: var(--theme-border-strong);
}

[data-theme="dark"] .ecb-toast { background: var(--theme-bg-elevated); color: var(--theme-fg); border-color: var(--theme-border); box-shadow: var(--theme-shadow-2); }

[data-theme="dark"] .ecb-loading { color: var(--theme-fg-muted); }
[data-theme="dark"] .ecb-spinner { border-color: var(--theme-border); border-top-color: var(--theme-primary); }

/* Select2 widgets — ship their own CSS bundle that's hardcoded white/light.
   Remap the surfaces to theme tokens in dark mode. Scoped broadly so admin,
   modern and hub uses all switch consistently. */
[data-theme="dark"] .select2-container--default .select2-selection--single,
[data-theme="dark"] .select2-container--default .select2-selection--multiple {
    background: var(--theme-bg-subtle);  /* lighter than .ecb-section card so the input stands out */
    border-color: var(--theme-border-strong);
    color: var(--theme-fg);
}
[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__rendered { color: var(--theme-fg); }
[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__placeholder,
[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__placeholder { color: var(--theme-fg-subtle); }
[data-theme="dark"] .select2-container--default .select2-selection__arrow b { border-top-color: var(--theme-fg-subtle); }
[data-theme="dark"] .select2-container--default .select2-selection__clear { color: var(--theme-fg-subtle); }
[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: var(--theme-bg-subtle);
    border-color: var(--theme-border);
    color: var(--theme-fg);
}
[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove { color: var(--theme-fg-subtle); }

/* Dropdown panel + search input + result rows. */
[data-theme="dark"] .select2-dropdown {
    background: var(--theme-bg-elevated);
    border-color: var(--theme-border);
    color: var(--theme-fg);
}
[data-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--theme-bg);
    border-color: var(--theme-border);
    color: var(--theme-fg);
}
[data-theme="dark"] .select2-results__option { color: var(--theme-fg); }
[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected],
[data-theme="dark"] .select2-container--default .select2-results__option--highlighted {
    background: var(--theme-primary);
    color: #fff;
}
[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected="true"] {
    background: var(--theme-bg-subtle);
    color: var(--theme-fg);
}
[data-theme="dark"] .select2-container--default .select2-results__group { color: var(--theme-fg-muted); }
[data-theme="dark"] .select2-container--focus .select2-selection,
[data-theme="dark"] .select2-container--default.select2-container--focus .select2-selection--multiple { border-color: var(--theme-primary); }

/* Summernote rich-text editor — content area needs explicit light text in
   dark mode. The toolbar stays as-is (it's iconographic with its own pale bg
   that reads on dark). */
[data-theme="dark"] .note-editor .note-editing-area .note-editable,
[data-theme="dark"] .note-editable {
    background: var(--theme-bg-subtle);
    color: var(--theme-fg);
}
[data-theme="dark"] .note-editor .note-editing-area .note-codable {
    background: var(--theme-bg-subtle);
    color: var(--theme-fg);
    border-color: var(--theme-border-strong);
}
[data-theme="dark"] .note-editor.note-frame { border-color: var(--theme-border); }
[data-theme="dark"] .note-editor .note-statusbar { background: var(--theme-bg-subtle); border-top-color: var(--theme-border); }
[data-theme="dark"] .note-editor .note-placeholder { color: var(--theme-fg-subtle); }
