/**
 * base.css — UDG Design System
 * ============================================================
 * LAYER 1 · Variables & Reset
 * LAYER 2 · Structural Shell  (header, footer, page layout)
 * LAYER 3 · UDG Components    (namespaced udg-*)
 * LAYER 4 · LLM Content Scope (.llm-content)
 * LAYER 5 · Responsive
 * ============================================================
 *
 * Rules for contributors:
 *  - Never use !important outside the mega-menu and a11y blocks
 *  - All colours MUST reference a --theme-* variable
 *  - Component classes MUST be prefixed udg-
 *  - Dynamic pages inherit theme via :root; they do NOT need !important to override
 */


/* ============================================================
   LAYER 1 · CSS CUSTOM PROPERTIES
   ============================================================ */

:root {
    /* ─────────────────────────────────────────────────────────────
     * BRAND PALETTE
     * These are the ONLY values you should ever need to change.
     * The theme modal in the Fidy editor writes directly to these
     * via CSS custom property injection (postMessage + direct DOM).
     * ───────────────────────────────────────────────────────────── */

    /* Primary — main CTA colour, links, active states */
    --theme-primary:          #1c2264;
    --theme-primary-hover:    #2c338c;

    /* Secondary — supporting actions, badges */
    --theme-secondary:        #2b3498;
    --theme-secondary-hover:  #1f2670;

    /* Accent / Tertiary — highlights, tags, decorative elements */
    --theme-accent:           #DBEAFE;
    --theme-accent-light:     #EFF6FF;
    --theme-accent-mid:       #DBEAFE;

    /* ─────────────────────────────────────────────────────────────
     * SURFACE & BACKGROUND
     * surface-raised sits one level above surface (cards on pages,
     * dropdowns on panels). Never use hard-coded whites/greys.
     *
     * --theme-surface-raised-text is the guaranteed-contrast text
     * colour for use ON TOP of --theme-surface-raised. It is computed
     * by application_preview.html (surfaceRaisedText()) using the
     * WCAG 2.1 relative luminance formula and saved to the database
     * as part of the theme — exactly like primaryHover, successHover,
     * and other derived tokens. The static fallback below assumes a
     * light theme and is overwritten when the theme loads from the DB.
     *
     * Pair rule: wherever you set `background: var(--theme-surface-raised)`
     * you MUST use `color: var(--theme-surface-raised-text)` on that
     * element or a text child.
     * ───────────────────────────────────────────────────────────── */
    --theme-background:                #FFFFFF;
    --theme-surface:                   #F8FAFC;
    --theme-surface-raised:            #EFF6FF;
    --theme-surface-raised-text:       #0F172A;   /* light-theme fallback; DB value takes over on load */

    /* ─────────────────────────────────────────────────────────────
     * TEXT
     * Use text-secondary for captions/labels, text-muted for
     * placeholder and disabled copy. Never use pure #000000.
     * ───────────────────────────────────────────────────────────── */
    --theme-text:             #0F172A;
    --theme-text-secondary:   #596579;
    --theme-text-muted:       #94A3B8;

    /* ─────────────────────────────────────────────────────────────
     * BORDERS
     * border-focus is always --theme-primary so focus rings match
     * whatever brand colour the user has chosen.
     * ───────────────────────────────────────────────────────────── */
    --theme-border:           #E2E8F0;
    --theme-border-focus:     var(--theme-primary);

    /* ─────────────────────────────────────────────────────────────
     * SEMANTIC STATUS COLOURS
     * These are intentionally independent of the brand palette so
     * a bright-red brand doesn't collide with danger states.
     * ───────────────────────────────────────────────────────────── */
    --theme-success:          #059669;
    --theme-success-hover:    #047857;
    --theme-warning:          #FF9F43;
    --theme-danger:           #EF4444;
    --theme-danger-hover:     #DC2626;
    --theme-info:             #3B82F6;

    /* ─────────────────────────────────────────────────────────────
     * SHADOWS
     * Tinted with on-surface colour, not pure black.
     * ───────────────────────────────────────────────────────────── */
    --theme-shadow-sm:        0 1px 3px  rgba(15, 23, 42, 0.08);
    --theme-shadow-md:        0 4px 12px rgba(15, 23, 42, 0.10);
    --theme-shadow-lg:        0 8px 25px rgba(15, 23, 42, 0.12);

    /* ─────────────────────────────────────────────────────────────
     * TYPOGRAPHY
     * --theme-font-family is replaced at runtime when the user
     * picks a different font in the theme modal.
     * ───────────────────────────────────────────────────────────── */
    --theme-font-family:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --theme-line-height:      1.6;

    /* ─────────────────────────────────────────────────────────────
     * BORDER RADIUS
     * --theme-radius is the base. sm / lg / xl / pill are derived
     * and also overwritten by the theme modal slider.
     * ───────────────────────────────────────────────────────────── */
    --theme-radius-sm:        4px;
    --theme-radius:           8px;
    --theme-radius-lg:        12px;
    --theme-radius-xl:        16px;
    --theme-radius-pill:      9999px;

    /* ─────────────────────────────────────────────────────────────
     * SPACING SCALE  (8px base)
     * ───────────────────────────────────────────────────────────── */
    --theme-space-xs:         0.25rem;   /*  4px */
    --theme-space-sm:         0.5rem;    /*  8px */
    --theme-space-md:         1rem;      /* 16px */
    --theme-space-lg:         1.5rem;    /* 24px */
    --theme-space-xl:         2rem;      /* 32px */
    --theme-space-2xl:        3rem;      /* 48px */

    /* ─────────────────────────────────────────────────────────────
     * TRANSITIONS
     * ───────────────────────────────────────────────────────────── */
    --theme-transition:       all 0.2s ease;
    --theme-transition-slow:  all 0.3s ease;

    /* ─────────────────────────────────────────────────────────────
     * LAYOUT
     * ───────────────────────────────────────────────────────────── */
    --theme-max-width:        1200px;
    --theme-header-height:    64px;

    /* ─────────────────────────────────────────────────────────────
     * DERIVED CONTRAST TOKENS
     * Computed by application_preview.html (contrastText()), saved to
     * the DB, and injected into the store iframe via _pushThemeToIframe()
     * on every theme load or change — same pipeline as primaryHover etc.
     *
     * Never hard-code white/black in component CSS for any of these
     * surfaces. Always use the corresponding var() so the computed
     * value from the DB is used and dark/light brand colours work.
     *
     *  --theme-on-primary    text ON --theme-primary
     *  --theme-on-secondary  text ON --theme-secondary
     *  --theme-on-accent     alias for --theme-on-primary (same surface)
     *  --theme-on-success    text ON --theme-success
     *  --theme-on-warning    text ON --theme-warning
     *  --theme-on-danger     text ON --theme-danger
     *  --theme-on-info       text ON --theme-info
     *  --theme-card-bg       card/panel surface (= --theme-surface-raised)
     *  --theme-card-text     text ON --theme-card-bg (= --theme-surface-raised-text)
     *  --theme-card-muted    secondary text ON --theme-card-bg
     * ───────────────────────────────────────────────────────────── */
    /* on-* tokens: text colour guaranteed to contrast against the
     * corresponding background token. All computed by application_preview.html
     * (contrastText()) and saved to DB / pushed to iframe with the theme.
     * Fallbacks assume a mid-light brand colour → white text is safe. */
    --theme-on-primary:          #ffffff;   /* text ON --theme-primary   */
    --theme-on-secondary:        #ffffff;   /* text ON --theme-secondary */
    --theme-on-accent:           #ffffff;   /* alias for on-primary      */
    --theme-on-success:          #ffffff;   /* text ON --theme-success   */
    --theme-on-warning:          #ffffff;   /* warning is often light → dark text fallback */
    --theme-on-danger:           #ffffff;   /* text ON --theme-danger    */
    --theme-on-info:             #ffffff;   /* text ON --theme-info      */
    --theme-card-bg:             #ffffff;
    --theme-card-text:           #0F172A;
    --theme-card-muted:          #475569;
}

/* Dark mode token overrides */
@media (prefers-color-scheme: dark) {
    :root {
        --theme-background:              #0F172A;
        --theme-surface:                 #1E293B;
        --theme-surface-raised:          #334155;
        --theme-surface-raised-text:     #F8FAFC;   /* dark-theme fallback; DB value takes over on load */
        --theme-text:                    #F8FAFC;
        --theme-text-secondary:          #CBD5E1;
        --theme-text-muted:              #94A3B8;
        --theme-border:                  #334155;
        /* on-warning: dark surfaces → dark text may not contrast; light fallback safer */
        --theme-on-warning:                 #F8FAFC;
    }
}


/* ============================================================
   LAYER 1 · RESET
   ============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--theme-font-family);
    line-height: var(--theme-line-height);
    color: var(--theme-text);
    background: var(--theme-background);
    overflow-x: hidden;
}

img,
video {
    max-width: 100%;
    height: auto;
    display: block;
}

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


/* ============================================================
   LAYER 1 · ANIMATIONS
   ============================================================ */

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

@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0   rgba(234, 84, 85, 0.7); }
    70%  { box-shadow: 0 0 0 6px rgba(234, 84, 85, 0); }
    100% { box-shadow: 0 0 0 0   rgba(234, 84, 85, 0); }
}

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


/* ============================================================
   LAYER 2 · STRUCTURAL SHELL
   ============================================================ */

/* --- Page wrapper ------------------------------------------ */
.page-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-wrap {
    flex: 1;
    padding-top: var(--theme-header-height);
}


/* --- Header ----------------------------------------------- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: var(--theme-background);
    border-bottom: 1px solid var(--theme-border);
    box-shadow: var(--theme-shadow-sm);
    z-index: 100;
}

/* .header-container kept for protected-layout offset override below */
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    gap: 1.5rem;
}

/* ── Desktop top bar: logo (left) | search + auth (right)
   Hidden by default (mobile-first); shown at ≥ 992px          ── */
.header-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.6rem 2rem;
    gap: 1.5rem;
}

.header-logo {
    flex: 0 0 200px;
    min-width: 0;
}

.header-logo a {
    display: flex;
    align-items: center;
}

.header-logo img {
    height: 44px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    display: block;
    transition: var(--theme-transition);
}

.header-logo:hover img {
    transform: scale(1.05);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 0 0 200px;
    justify-content: flex-end;
    padding-right: 1.25rem;
}

.header-right .search-container {
    flex: 0 1 200px;
    min-width: 200px;
}

.header-right .navbar-nav {
    margin: 0;
    flex-shrink: 0;
}

/* ── Mobile top bar: hamburger + logo ─────────────────────── */
.header-mobile-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
}

.logo-mobile img {
    height: 36px;
    width: auto;
    object-fit: contain;
    display: block;
}

/* ── Legacy / kept for compatibility ─────────────────────── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Legacy .logo class — used by mobile .logo-mobile fallback only */
.logo img {
    object-fit: contain;
    transition: var(--theme-transition);
}

.logo:hover img {
    transform: scale(1.05);
}

/* --- Desktop nav ------------------------------------------ */
.nav {
    display: flex;
    align-items: center;
    list-style: none;
}

/* When nav lives inside the topbar row — takes all remaining space
   so it sits perfectly centred between the fixed-width logo and right cluster */
.header-nav {
    flex: 1 1 0;
    justify-content: center;
    overflow: visible;
    min-width: 0;
}

.nav-list {
    display: flex;
    justify-content: center;
    align-items: center;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
}

.nav-list a {
    text-decoration: none;
    color: var(--theme-text);
    font-weight: 500;
    padding: 0.75rem 1rem;
    border-radius: var(--theme-radius-sm);
    transition: var(--theme-transition);
}

.nav-list a:hover,
.nav-list a:focus {
    color: var(--theme-primary);
}

/* ── Sign Up button — bordered pill in the nav ─────────────── */
.nav-signup-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.45rem 1.1rem;
    border-radius: var(--theme-radius-pill);
    border: 2px solid var(--theme-primary);
    color: var(--theme-primary);
    background: transparent;
    transition: var(--theme-transition);
    white-space: nowrap;
}

.nav-signup-btn:hover,
.nav-signup-btn:focus {
    background: var(--theme-primary);
    color: var(--theme-on-primary);
}

/* --- Header icon buttons ---------------------------------- */
.header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: var(--theme-text);
    text-decoration: none;
    transition: var(--theme-transition);
    background: transparent;
    border: 2px solid transparent;
}

.header-icon:hover,
.header-icon:focus {
    color: var(--theme-primary);
}

/* --- Search ----------------------------------------------- */
.search-container {
    position: relative;
}

.search-container form {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 0.45rem 2.5rem 0.45rem 0.85rem;
    border: 2px solid var(--theme-border);
    border-radius: var(--theme-radius-pill);
    transition: border-color 0.2s ease;
    font-size: 0.8rem;
    min-width: 120px;
    background: var(--theme-background);
    color: var(--theme-text);
}

.search-input:focus {
    outline: none;
    border-color: var(--theme-primary);
}

.search-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--theme-primary);
    cursor: pointer;
    transition: var(--theme-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--theme-surface-raised);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-lg);
    box-shadow: var(--theme-shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--theme-transition-slow);
}

.search-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--theme-border);
    cursor: pointer;
    transition: var(--theme-transition);
    text-decoration: none;
    color: inherit;
}

.search-result-item:hover {
    background: var(--theme-surface);
}

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

/* --- Hamburger -------------------------------------------- */
/* Lives inside .header-mobile-bar which is hidden on desktop (≥992px).
   No need to default to display:none — visibility is controlled by
   .header-mobile-bar show/hide. */
.hamburger-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.hamburger-toggle span {
    width: 24px;
    height: 2px;
    background: var(--theme-primary);
    transition: var(--theme-transition-slow);
    border-radius: 1px;
    display: block;
}

.hamburger-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}
.hamburger-toggle.active span:nth-child(2) {
    opacity: 0;
}
.hamburger-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* --- Mobile drawer ---------------------------------------- */
.mobile-menu {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
    z-index: 999;
    transition: left 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-menu.open {
    left: 0;
}

.mobile-menu::-webkit-scrollbar { width: 6px; }
.mobile-menu::-webkit-scrollbar-track { background: var(--theme-surface); }
.mobile-menu::-webkit-scrollbar-thumb { background: var(--theme-border); border-radius: 3px; }

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--theme-border);
}

.mobile-menu-title {
    font-weight: 600;
    color: var(--theme-text-secondary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-menu-close {
    background: transparent;
    border: none;
    font-size: 28px;
    color: var(--theme-primary);
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.mobile-menu-close:hover {
    color: var(--theme-secondary);
}

/* --- Mobile nav items ------------------------------------- */
.mobile-nav {
    list-style: none;
    padding: 1rem 0;
}

.mobile-nav li {
    margin: 0;
}

.mobile-nav > li > a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 14px 1rem;
    color: var(--theme-text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
    transition: var(--theme-transition);
    border-left: 3px solid transparent;
}

.mobile-nav > li > a:hover,
.mobile-nav > li > a.active {
    background-color: var(--theme-surface);
    color: var(--theme-primary);
    border-left-color: var(--theme-primary);
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: var(--theme-transition-slow);
    pointer-events: none;
}

.menu-backdrop.open {
    background: rgba(0, 0, 0, 0.5);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Mobile submenu — controlled via JS display:none/block */
/* submenu-toggle handles its own arrow via ::after — see .submenu-toggle::after below */

.mobile-submenu {
    display: none;
    background: var(--theme-surface);
    overflow: hidden;
}

.mobile-submenu.active {
    display: block;
}

.mobile-submenu a {
    padding: 0.5rem 1.5rem 0.5rem 2rem;
    font-size: 14px;
    font-weight: 400;
    color: var(--theme-text-muted);
    display: block;
    text-decoration: none;
    transition: var(--theme-transition);
    border-left: 3px solid transparent;
}

.mobile-submenu a:hover,
.mobile-submenu a.active {
    color: var(--theme-primary);
    background-color: var(--theme-surface-raised);
}


/* ============================================================
   MEGA MENU
   !important is justified here: these must survive Tailwind/
   Bootstrap resets on pages that load third-party frameworks.
   ============================================================ */

.nav-item.has-dropdown {
    position: relative !important;
}

.nav-item.has-dropdown > a {
    cursor: pointer !important;
}

.nav-item.has-dropdown > a::after {
    content: '' !important;
    display: inline-block !important;
    width: 0 !important;
    height: 0 !important;
    margin-left: 0.5rem !important;
    vertical-align: middle !important;
    border-top: 4px solid !important;
    border-right: 4px solid transparent !important;
    border-left: 4px solid transparent !important;
    transition: transform 0.2s ease !important;
}

.nav-item.has-dropdown:hover > a::after {
    transform: rotate(180deg) !important;
}

.subcategories-mega-menu,
.subcategories-mega-menu *,
.subcategories-mega-menu *::before,
.subcategories-mega-menu *::after {
    box-sizing: border-box !important;
}

.subcategories-mega-menu {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    background-color: var(--theme-surface-raised, #fff) !important;
    box-shadow: var(--theme-shadow-lg, 0 4px 20px rgba(0,0,0,0.1)) !important;
    border-radius: var(--theme-radius, 8px) !important;
    width: 880px !important;
    max-width: 90vw !important;
    margin: 0 !important;
    margin-top: 0.5rem !important;
    padding: 0 !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 9999 !important;
    display: none !important;
    pointer-events: none;
    border: none !important;
}

.nav-item.has-dropdown:hover .subcategories-mega-menu {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) !important;
    display: block !important;
    pointer-events: auto !important;
}

.subcategories-content {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    width: 100% !important;
    min-height: 300px !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
}

.category-wrapper {
    width: 35% !important;
    min-width: 280px !important;
    max-width: 35% !important;
    flex: 0 0 35% !important;
    background-color: var(--theme-surface-raised, #fff) !important;
    border-right: 1px solid var(--theme-border, #f0f0f0) !important;
    border-radius: var(--theme-radius, 8px) 0 0 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

.category-list {
    list-style: none !important;
    padding: 8px 0 !important;   /* top/bottom breathing room inside the panel */
    margin: 0 !important;
}

.category-list li,
.category-list > li {
    list-style: none !important;
    margin: 0 !important;
    /* padding intentionally not set here — .category-item handles it */
}

.category-list li::before,
.category-list > li::before {
    content: none !important;
    display: none !important;
}

.category-item {
    font-size: 15px !important;
    padding: 14px 25px !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
    border-left: 3px solid transparent !important;
    color: var(--theme-text, #333) !important;
    font-weight: 400 !important;
    font-family: var(--theme-font-family, sans-serif) !important;
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    box-sizing: border-box !important;
    width: 100% !important;
}

.category-item:hover,
.category-item.active {
    background-color: var(--theme-surface, #f9f9f9) !important;
    border-left-color: var(--theme-primary, #667eea) !important;
    color: var(--theme-primary, #667eea) !important;
}

.category-item.active {
    font-weight: 500 !important;
}

.category-link-icon {
    opacity: 0;
    transition: opacity 0.2s ease;
    margin-left: 8px !important;
    color: var(--theme-text-muted, #666) !important;
    font-size: 14px !important;
    flex-shrink: 0 !important;
}

.category-item:hover .category-link-icon {
    opacity: 1;
}

.subcategories-section {
    flex: 1 1 auto !important;
    background-color: var(--theme-surface, #f9f9f9) !important;
    padding: 25px !important;
    border-radius: 0 var(--theme-radius, 8px) 0 0 !important;
    overflow-y: auto !important;
    max-height: 500px !important;
    box-sizing: border-box !important;
    min-width: 0 !important;
    margin: 0 !important;
}

.condition-list {
    list-style: none !important;
    padding: 4px 0 !important;   /* small top/bottom inset within the right panel */
    margin: 0 !important;
    display: none !important;
}

.condition-list.active {
    display: block !important;
}

.condition-list li,
.condition-list > li {
    list-style: none !important;
    margin: 0 !important;
    /* padding intentionally not set here — .subcategory-item handles it */
}

.condition-list li::before,
.condition-list > li::before {
    content: none !important;
    display: none !important;
}

.subcategory-item {
    font-size: 14px !important;
    padding: 10px 15px !important;
    transition: all 0.2s ease !important;
    border-radius: var(--theme-radius-sm, 4px) !important;
    cursor: pointer !important;
    color: var(--theme-text-secondary, #444) !important;
    font-family: var(--theme-font-family, sans-serif) !important;
    margin-bottom: 4px !important;
    box-sizing: border-box !important;
    display: block !important;
    width: 100% !important;
    background-color: transparent !important;
    border: none !important;
}

.subcategory-item:hover {
    background-color: var(--theme-surface-raised, #fff) !important;
    color: var(--theme-primary, #667eea) !important;
}

.subcategory-item a {
    text-decoration: none !important;
    color: inherit !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
}

.mega-menu-footer {
    padding: 15px 25px !important;
    border-top: 1px solid var(--theme-border, #f0f0f0) !important;
    display: flex !important;
    justify-content: flex-end !important;
    background-color: var(--theme-surface-raised, #fff) !important;
    border-radius: 0 0 var(--theme-radius, 8px) var(--theme-radius, 8px) !important;
}

.mega-menu-footer a {
    color: var(--theme-text, #333) !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    transition: color 0.2s ease !important;
    font-family: var(--theme-font-family, sans-serif) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
}

.mega-menu-footer a:hover {
    color: var(--theme-primary, #667eea) !important;
}

/* Mobile submenu for mega menu */
#mobileNav {
    list-style: none;
    padding: 0;
    margin: 0;
}

#mobileNav > li {
    border-bottom: 1px solid var(--theme-border);
}

#mobileNav > li > a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--theme-text);
    text-decoration: none;
    font-weight: 500;
}

.submenu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 1rem;
    color: var(--theme-text-secondary);
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
    transition: var(--theme-transition);
}

.submenu-toggle:hover,
.submenu-toggle.active {
    background-color: var(--theme-surface);
    color: var(--theme-primary);
    border-left-color: var(--theme-primary);
}

.submenu-toggle::after {
    content: '▼';
    font-size: 12px;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-left: auto;
}

.submenu-toggle.active::after {
    transform: rotate(180deg);
}

.mobile-category {
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    color: var(--theme-primary);
    font-size: 13px;
    margin-top: 0.75rem;
    background-color: var(--theme-surface-raised);
}

.mobile-category:first-child {
    margin-top: 0;
}

.mobile-subcategory {
    padding: 0;
}

.mobile-subcategory a {
    color: var(--theme-text-secondary);
    text-decoration: none;
    display: block;
    font-size: 14px;
    padding: 0.5rem 1.5rem 0.5rem 2rem;
    transition: background-color 0.2s ease;
}

.mobile-subcategory a:hover {
    background-color: var(--theme-surface-raised);
    color: var(--theme-primary);
}

.mobile-submenu-footer a {
    color: var(--theme-primary);
    font-weight: 600;
}

/* ── Drill-down panels ───────────────────────────────────────
   Panel 1 (.mobile-drill-categories): list of category buttons
   Panel 2 (.mobile-drill-subcategories): subcategory links for
   one category, with a back button at the top.
   JS toggles [hidden] to switch between panels.
──────────────────────────────────────────────────────────── */

.mobile-drill-panel {
    /* panels are block by default; JS hides with [hidden] */
}

/* Category drill button (replaces .mobile-category div) */
.mobile-category-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1.25rem 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 1px solid var(--theme-border);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--theme-primary);
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.mobile-category-btn:first-child {
    border-top: 1px solid var(--theme-border);
}

.mobile-category-btn:hover {
    background-color: var(--theme-surface-raised);
    color: var(--theme-primary-hover, var(--theme-primary));
}

.mobile-category-btn .ti {
    font-size: 14px;
    color: var(--theme-text-muted);
    flex-shrink: 0;
}

/* Back button at top of subcategory panel */
.mobile-drill-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--theme-surface-raised);
    border: none;
    border-bottom: 2px solid var(--theme-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--theme-primary);
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease;
}

.mobile-drill-back:hover {
    background-color: var(--theme-surface);
}

.mobile-drill-back .ti {
    font-size: 15px;
    flex-shrink: 0;
}


/* ============================================================
   LAYER 2 · FOOTER
   ============================================================ */

.footer {
    padding: 2rem 1rem 1.5rem;
    background: var(--theme-background);
    color: var(--theme-text);
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
}

.footer-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.footer-logo img {
    width: 100px;
    height: 40px;
    object-fit: contain;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-column h3 {
    color: var(--theme-text);
    font-weight: 600;
    margin-bottom: 1rem;
}

.footer-nav {
    list-style: none;
}

.footer-nav li {
    margin-bottom: 0.5rem;
}

.footer-nav a {
    color: var(--theme-text-secondary);
    text-decoration: none;
    transition: var(--theme-transition);
    display: inline-block;
}

.footer-nav a:hover,
.footer-nav a:focus {
    color: var(--theme-primary);
    transform: translateX(4px);
}

.newsletter-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.newsletter-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background);
    color: var(--theme-text);
    transition: var(--theme-transition);
    font-family: inherit;
}

.newsletter-input:focus {
    outline: none;
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.newsletter-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-hover));
    color: var(--theme-on-primary);
    border: none;
    border-radius: var(--theme-radius);
    font-weight: 500;
    cursor: pointer;
    transition: var(--theme-transition);
    white-space: nowrap;
    font-family: inherit;
}

.newsletter-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--theme-shadow-md);
}

.social-section {
    display: flex;
    justify-content: center;
    padding: 1.5rem 0;
}

.social-icons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 2rem 0;
}

.social-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--theme-primary);
    color: var(--theme-on-primary);
    border-radius: 50%;
    text-decoration: none;
    transition: var(--theme-transition);
}

.social-icon:hover,
.social-icon:focus {
    background: var(--theme-primary-hover);
    transform: translateY(-3px);
    box-shadow: var(--theme-shadow-md);
}

.copyright {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid var(--theme-border);
    color: var(--theme-text-muted);
    font-size: 0.875rem;
}

/* Footer mobile toggles (hidden on desktop) */
.footer-toggle,
.footer-icon {
    display: none;
}

/* Popup / Overlay */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--theme-transition);
}

.popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.popup-container {
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-xl);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--theme-shadow-lg);
    transform: scale(0.9);
    transition: var(--theme-transition);
    position: relative;
}

.popup-overlay.active .popup-container {
    transform: scale(1);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--theme-text-muted);
    transition: var(--theme-transition);
}

.close-btn:hover {
    color: var(--theme-text);
}

.form-section {
    margin-bottom: 3rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--theme-border);
}

.form-section:last-child {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.form-group {
    margin-bottom: 1rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--theme-text);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Form validation */
.field-error {
    color: var(--theme-danger);
    font-size: 0.875rem;
    margin-top: 4px;
    display: block;
}

input.error,
select.error,
textarea.error {
    border-color: var(--theme-danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

input.success,
select.success,
textarea.success {
    border-color: var(--theme-success);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--theme-text-muted);
}

.breadcrumb a {
    color: var(--theme-primary);
    text-decoration: none;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 32px 0;
}

.pagination a,
.pagination span {
    padding: 8px 16px;
    text-decoration: none;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-sm);
    color: var(--theme-text);
    transition: var(--theme-transition);
}

.pagination a:hover {
    background-color: var(--theme-primary);
    color: var(--theme-on-primary);
    border-color: var(--theme-primary);
}

.pagination .current {
    background-color: var(--theme-primary);
    color: var(--theme-on-primary);
    border-color: var(--theme-primary);
}

/* Enhancement data attribute hook */
[data-enhance] {
    transition: var(--theme-transition);
}


/* ============================================================
   LAYER 3 · UDG COMPONENTS  (namespaced, no !important)
   Dynamic pages may override any of these freely.
   ============================================================ */

/* --- udg-button ------------------------------------------- */
.udg-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 12px 24px;
    border: none;
    border-radius: var(--theme-radius);
    background: var(--theme-primary);
    color: var(--theme-on-primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--theme-transition);
    min-height: 44px;
}

.udg-button:hover {
    background: var(--theme-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--theme-shadow-md);
}

.udg-button:focus-visible {
    outline: 2px solid var(--theme-accent);
    outline-offset: 2px;
}

.udg-button--secondary {
    background: var(--theme-secondary);
    color: var(--theme-on-secondary);
}

.udg-button--secondary:hover {
    background: var(--theme-secondary-hover);
}

.udg-button--outline {
    background: transparent;
    border: 2px solid var(--theme-primary);
    color: var(--theme-primary);
}

.udg-button--outline:hover {
    background: var(--theme-primary);
    color: var(--theme-on-primary);
}

.udg-button--danger {
    background: var(--theme-danger);
    color: var(--theme-on-danger);
}

.udg-button--danger:hover {
    background: var(--theme-danger-hover);
}

.udg-button--success {
    background: var(--theme-success);
    color: var(--theme-on-success);
}

.udg-button--success:hover {
    background: var(--theme-success-hover);
}

/* --- udg-card --------------------------------------------- */
.udg-card {
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-lg);
    padding: 24px;
    box-shadow: var(--theme-shadow-sm);
    transition: var(--theme-transition);
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
}

.udg-card:hover {
    box-shadow: var(--theme-shadow-md);
    transform: translateY(-2px);
    border-color: var(--theme-primary);
}

/* --- udg-input -------------------------------------------- */
.udg-input {
    padding: 12px 16px;
    border: 2px solid var(--theme-border);
    border-radius: var(--theme-radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--theme-background);
    color: var(--theme-text);
    transition: border-color 0.2s ease;
    min-height: 44px;
    width: 100%;
}

.udg-input:focus {
    outline: none;
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* --- udg-badge -------------------------------------------- */
.udg-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--theme-primary);
    color: var(--theme-on-primary);
    border-radius: var(--theme-radius-pill);
    font-size: 0.875rem;
    font-weight: 500;
}

.udg-badge--success {
    background: var(--theme-success);
    color: var(--theme-on-success);
}

.udg-badge--danger {
    background: var(--theme-danger);
    color: var(--theme-on-danger);
}

.udg-badge--warning {
    background: var(--theme-warning);
    color: var(--theme-on-warning);
}

/* --- udg-table -------------------------------------------- */
.udg-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-lg);
    overflow: hidden;
    box-shadow: var(--theme-shadow-sm);
}

.udg-table th,
.udg-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--theme-border);
}

.udg-table th {
    background: var(--theme-surface);
    font-weight: 600;
    color: var(--theme-text);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.udg-table tr:hover {
    background: var(--theme-surface);
}

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

/* --- udg-toggle ------------------------------------------- */
.udg-toggle {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.udg-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.udg-toggle .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--theme-border);
    transition: 0.4s;
    border-radius: 34px;
}

.udg-toggle .slider::before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.udg-toggle input:checked + .slider {
    background-color: var(--theme-primary);
}

.udg-toggle input:checked + .slider::before {
    transform: translateX(26px);
}

/* --- udg-tabs --------------------------------------------- */
.udg-tabs {
    border-bottom: 2px solid var(--theme-border);
}

.udg-tabs .udg-tab {
    display: inline-block;
    padding: 12px 24px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: var(--theme-transition);
    margin-bottom: -2px;
    color: var(--theme-text-muted);
}

.udg-tabs .udg-tab:hover,
.udg-tabs .udg-tab.active {
    border-bottom-color: var(--theme-primary);
    color: var(--theme-primary);
}

/* --- udg-dropdown ----------------------------------------- */
.udg-dropdown {
    position: relative;
    display: inline-block;
}

.udg-dropdown-content {
    display: none;
    position: absolute;
    background: var(--theme-surface-raised);
    min-width: 160px;
    box-shadow: var(--theme-shadow-md);
    border-radius: var(--theme-radius);
    border: 1px solid var(--theme-border);
    z-index: 10;
    top: 100%;
    left: 0;
}

.udg-dropdown:hover .udg-dropdown-content {
    display: block;
}

.udg-dropdown-content a {
    color: var(--theme-text);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    transition: var(--theme-transition);
}

.udg-dropdown-content a:hover {
    background: var(--theme-surface);
    color: var(--theme-primary);
}

/* --- udg-toast -------------------------------------------- */
.udg-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--theme-primary);
    color: var(--theme-on-primary);
    padding: 16px 24px;
    border-radius: var(--theme-radius);
    box-shadow: var(--theme-shadow-md);
    z-index: 1000;
    transform: translateX(110%);
    transition: transform 0.3s ease;
    max-width: 320px;
}

.udg-toast.show {
    transform: translateX(0);
}

/* --- udg-loader ------------------------------------------- */
.udg-loader {
    border: 4px solid var(--theme-surface);
    border-top: 4px solid var(--theme-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

/* --- udg-progress ----------------------------------------- */
.udg-progress {
    width: 100%;
    height: 8px;
    background: var(--theme-border);
    border-radius: var(--theme-radius-pill);
    overflow: hidden;
}

.udg-progress-bar {
    height: 100%;
    background: var(--theme-primary);
    transition: width 0.3s ease;
    border-radius: var(--theme-radius-pill);
}

/* --- udg-tooltip ------------------------------------------ */
.udg-tooltip {
    position: relative;
    cursor: help;
}

.udg-tooltip:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: var(--theme-radius-sm);
    white-space: nowrap;
    z-index: 1000;
    font-size: 14px;
    pointer-events: none;
}

/* --- udg-slider ------------------------------------------- */
.udg-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--theme-border);
    outline: none;
    transition: background 0.2s ease;
    -webkit-appearance: none;
}

.udg-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--theme-primary);
    cursor: pointer;
}

/* --- udg-media -------------------------------------------- */
.udg-media {
    max-width: 100%;
    height: auto;
    border-radius: var(--theme-radius);
}

/* --- udg-list --------------------------------------------- */
.udg-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.udg-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--theme-border);
    color: var(--theme-text);
}

.udg-list li:last-child {
    border-bottom: none;
}

/* --- Layout primitives ------------------------------------ */
.udg-container {
    max-width: var(--theme-max-width);
    margin: 0 auto;
    padding: 0 20px;
}

.udg-section {
    margin: 40px 0;
    padding: 20px 0;
}

.udg-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.udg-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.udg-cluster {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.udg-sidebar {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 24px;
}

/* --- High contrast mode ----------------------------------- */
@media (prefers-contrast: high) {
    .udg-button {
        border: 2px solid currentColor;
    }
    .udg-card {
        border: 2px solid var(--theme-text);
    }
}

/* --- udg-user-gradient ------------------------------------ */
.udg-user-rd {
    background: linear-gradient(135deg, var(--theme-primary), var(--theme-secondary));
}


/* ============================================================
   LAYER 4 · LLM CONTENT SCOPE
   Uses specificity (not !important) for element defaults so
   dynamic pages can still override with more specific selectors.
   ============================================================ */

.llm-content {
    color: var(--theme-text);
    background: var(--theme-background);
    min-height: calc(100vh - 200px);
}

/* Typography */
.llm-content h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--theme-text);
    margin-bottom: 0.75rem;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.llm-content h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--theme-text);
    margin-bottom: 1rem;
    line-height: 1.3;
}

.llm-content h3 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--theme-text);
    margin-bottom: 0.75rem;
}

.llm-content h4,
.llm-content h5,
.llm-content h6 {
    color: var(--theme-text);
    margin-bottom: 0.5rem;
}

.llm-content p {
    color: var(--theme-text);
    margin-bottom: 1rem;
    line-height: var(--theme-line-height);
}

/* Links */
.llm-content a {
    color: var(--theme-primary);
    transition: color 0.2s ease;
}

.llm-content a:hover {
    color: var(--theme-primary-hover);
}

/* Inline code & blockquote */
.llm-content pre,
.llm-content code {
    background: var(--theme-surface);
    color: var(--theme-text);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-sm);
    padding: 2px 6px;
    font-size: 0.9em;
}

.llm-content pre {
    padding: 1rem;
    overflow-x: auto;
}

.llm-content pre code {
    border: none;
    padding: 0;
    background: transparent;
}

.llm-content blockquote {
    border-left: 4px solid var(--theme-primary);
    background: var(--theme-surface);
    color: var(--theme-text);
    padding: 1rem 1.5rem;
    margin: 1rem 0;
    border-radius: 0 var(--theme-radius) var(--theme-radius) 0;
}

.llm-content ul li,
.llm-content ol li {
    color: var(--theme-text);
    margin-bottom: 0.25rem;
}

/* Containers & cards */
.llm-content .container,
.llm-content [class*="udg-container"] {
    max-width: var(--theme-max-width);
    margin: 0 auto;
    padding: 1rem;
}

.llm-content .bg-white,
.llm-content form,
.llm-content [class*="udg-card"] {
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-lg);
    padding: 2rem;
    box-shadow: var(--theme-shadow-sm);
    margin-bottom: 1.5rem;
}

/* Inputs & selects */


/* Buttons */


/* Tables */
.llm-content table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-lg);
    overflow: hidden;
    box-shadow: var(--theme-shadow-sm);
    border: 1px solid var(--theme-border);
    margin: 1.5rem 0;
}

.llm-content table th {
    background: var(--theme-surface);
    color: var(--theme-text);
    padding: 16px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 2px solid var(--theme-border);
}

.llm-content table td {
    padding: 16px;
    border-bottom: 1px solid var(--theme-border);
    font-size: 0.95rem;
    vertical-align: middle;
    color: var(--theme-text);
}

.llm-content table tbody tr {
    transition: var(--theme-transition);
    background: var(--theme-surface-raised);
}

.llm-content table tbody tr:hover {
    background: var(--theme-surface);
}

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

/* Table action buttons */
.llm-content table td .actions,
.llm-content table td [class*="action"] {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.llm-content table button,
.llm-content table .action-btn {
    padding: 8px 12px;
    min-height: 36px;
    font-size: 0.875rem;
}

/* Status badges */
.llm-content .status-badge,
.llm-content [class*="status-"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--theme-radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Filter forms */
.llm-content .filter-form,
.llm-content [class*="filter-form"] {
    background: var(--theme-surface-raised);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-lg);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--theme-shadow-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-end;
}

.llm-content .filter-field {
    display: flex;
    flex-direction: column;
    min-width: 140px;
    flex: 1;
}

.llm-content .filter-field label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--theme-text);
    margin-bottom: 0.5rem;
}

/* Pagination */
.llm-content .pagination,
.llm-content [class*="pagination"] {
    background: var(--theme-surface-raised);
    border-radius: var(--theme-radius-lg);
    padding: 1.5rem 2rem;
    box-shadow: var(--theme-shadow-sm);
    border: 1px solid var(--theme-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2rem 0;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Modal & overlays */
.llm-content .modal-content,
.llm-content .overlay,
.llm-content .popup {
    background: var(--theme-surface-raised);
    color: var(--theme-text);
}

/* Secondary / muted text helpers */
.llm-content [class*="text-muted"],
.llm-content [class*="text-secondary"],
.llm-content small,
.llm-content .help-text,
.llm-content .description {
    color: var(--theme-text-muted);
}

/* Focus ring inside llm content */
.llm-content *:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: 2px;
}


/* ============================================================
   LAYER 5 · RESPONSIVE
   ============================================================ */

/* --- Desktop (≥ 769px) ------------------------------------ */
@media (min-width: 769px) {
    .show-mobile {
        display: none;
    }

    .footer-column h3 {
        display: block;
        margin-bottom: 1rem;
        font-size: 1.1rem;
    }

    .footer-toggle,
    .footer-icon {
        display: none;
    }

    .footer-content {
        max-height: none;
        overflow: visible;
        padding: 0;
        display: block;
    }

    .footer-section {
        border-bottom: none;
    }

    .footer-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 2rem;
    }
}

/* --- Mega menu hidden on mobile --------------------------- */
@media (max-width: 991px) {
    .subcategories-mega-menu {
        display: none !important;
    }
}

/* --- Desktop header bars (≥ 992px) ----------------------- */
@media (min-width: 992px) {
    /* Show the two-zone top bar, hide mobile bar */
    .header-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    .header-mobile-bar {
        display: none !important;
    }
}

/* --- Tablet & Mobile (≤ 768px) ---------------------------- */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }

    .content-wrap {
        padding-top: 50px;
    }

    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
    }

    /* Desktop top bar is hidden on mobile — show mobile bar instead */
    .header-topbar {
        display: none !important;
    }

    .header-mobile-bar {
        display: flex;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }

    .logo-mobile img {
        height: 36px;
    }

    /* Hide desktop nav on mobile */
    .nav,
    .nav-list {
        display: none;
    }

    .header-right .avatar,
    .header-container .avatar {
        width: 40px;
        height: 40px;
        background: var(--theme-surface);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--theme-primary);
        font-weight: 500;
    }

    /* Content */
    .content {
        max-width: 100%;
    }

    .llm-content {
        padding: 1.5rem 0.75rem;
        background: var(--theme-background);
    }

    .llm-content .container,
    .llm-content [class*="container"] {
        padding: 0;
        margin: 0 auto;
    }

    /* Forms */
    .llm-content select,
    .llm-content input[type="text"],
    .llm-content input[type="email"],
    .llm-content input[type="date"],
    .llm-content input[type="number"],
    .llm-content input[type="search"],
    .llm-content textarea {
        font-size: 16px; /* prevent iOS zoom */
        padding: 12px;
    }

    .llm-content .filter-form {
        flex-direction: column;
        gap: 1rem;
    }

    .llm-content .filter-field {
        width: 100%;
        min-width: 100%;
    }

    /* Cards */
    .llm-content .bg-white,
    .llm-content form,
    .llm-content [class*="card"] {
        padding: 1.25rem;
        border-radius: var(--theme-radius);
        margin-bottom: 1rem;
    }



    /* Tables */
    .llm-content table {
        font-size: 0.8rem;
        margin: 1rem 0;
        border-radius: var(--theme-radius);
    }

    .llm-content table th {
        padding: 12px 8px;
        font-size: 0.7rem;
    }

    .llm-content table td {
        padding: 12px 8px;
        font-size: 0.85rem;
    }

    .llm-content table .action-btn,
    .llm-content table button {
        padding: 6px 8px;
        font-size: 0.75rem;
        min-height: 32px;
    }

    .llm-content table td .actions {
        flex-direction: column;
        gap: 4px;
    }

    /* Typography */
    .llm-content h1 {
        font-size: 1.75rem;
        margin-bottom: 0.5rem;
    }

    .llm-content h2 {
        font-size: 1.35rem;
    }

    .llm-content h3 {
        font-size: 1.1rem;
    }

    .newsletter-section {
        padding: 10px;
    }

    /* Newsletter */
    .newsletter-form {
        flex-direction: column;
    }

    .newsletter-input,
    .newsletter-btn {
        width: 100%;
        font-size: 16px;
    }

    /* Footer */
    .footer {
        padding: 0;
        margin-top: 2rem;
    }

    .footer-content {
        padding: 0;
    }

    .footer-section {
        border-bottom: 1px solid var(--theme-border);
    }

    .footer-column > h3 {
        display: none;
    }

    .footer-toggle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 15px;
        background: transparent;
        border: none;
        text-align: left;
        cursor: pointer;
        font-weight: 600;
        color: var(--theme-text);
        font-family: inherit;
    }

    .footer-logo img {
        width: 120px;
        height: 60px;
    }

    .footer-grid {
        display: block;
        gap: 0;
        margin-bottom: 0;
    }

    .footer-column {
        padding: 0;
    }

    .footer-column > .footer-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;
        padding: 0 15px;
    }

    .footer-column > .footer-content.active {
        max-height: 220px;
        padding-bottom: 15px;
    }

    .footer-icon {
        display: inline-block;
        font-size: 14px;
        margin-left: auto;
        transition: transform 0.3s ease;
    }

    .footer-icon.active {
        transform: rotate(180deg);
    }

    .footer-nav li {
        padding: 10px 0;
    }

    /* Pagination */
    .llm-content .pagination,
    .llm-content [class*="pagination"] {
        padding: 1rem;
        gap: 0.5rem;
        flex-direction: column;
    }

    /* Layout */
    .udg-sidebar {
        grid-template-columns: 1fr;
    }

    .udg-grid {
        grid-template-columns: 1fr;
    }

    /* Touch targets */
    .udg-button,
    .header-icon,
    .social-icon {
        min-width: 44px;
        min-height: 44px;
    }

    /* Mega menu sub category mobile */
    .subcategories-content {
        flex-direction: column;
        min-height: auto;
    }

    .category-wrapper {
        width: 100%;
        min-width: auto;
        border-right: none;
        border-bottom: 1px solid var(--theme-border);
    }

    .subcategories-section {
        width: 100%;
        max-height: 300px;
    }

    /* Misc */
    .hide-mobile {
        display: none !important;
    }

    body,
    html {
        max-width: 100vw;
    }

    /* overflow-x: hidden is already set on body globally (see :218). Do
       NOT also set it on html here — giving the root element any
       non-visible overflow breaks position: sticky for its descendants
       (the sticky header stopped sticking on mobile because of this). */
    body {
        overflow-x: hidden;
    }

    button:focus,
    input:focus,
    textarea:focus,
    select:focus {
        outline: 2px solid var(--theme-primary);
        outline-offset: 2px;
    }

    button:focus:not(:focus-visible),
    input:focus:not(:focus-visible),
    textarea:focus:not(:focus-visible),
    select:focus:not(:focus-visible) {
        outline: none;
    }
}

/* --- Extra small (≤ 480px) -------------------------------- */
@media (max-width: 480px) {
    .header-mobile-bar {
        gap: 0.3rem;
        padding: 0.4rem 0.5rem;
    }

    .logo-mobile img {
        height: 30px;
    }

    .header-mobile-bar .avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }

    .hamburger-toggle {
        min-width: 32px;
        min-height: 32px;
    }

    .hamburger-toggle span {
        width: 20px;
        height: 1.5px;
    }

    .llm-content {
        padding: 1rem 0.5rem;
    }

    .llm-content .bg-white,
    .llm-content form,
    .llm-content [class*="card"] {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }

    .llm-content h1 { font-size: 1.5rem; }
    .llm-content h2 { font-size: 1.2rem; }

    .llm-content table th {
        padding: 10px 6px;
        font-size: 0.65rem;
    }

    .llm-content table td {
        padding: 10px 6px;
        font-size: 0.8rem;
    }

    .social-icon {
        width: 40px;
        height: 40px;
    }

    .copyright {
        font-size: 12px;
        padding-top: 1rem;
    }
}

/* --- Landscape mobile (≤ 768px, landscape) ---------------- */
@media (max-width: 768px) and (orientation: landscape) {
    .content-wrap {
        padding-top: 50px;
    }

    .header-mobile-bar {
        padding: 0.4rem 1rem;
    }

    .llm-content {
        padding: 1rem 0.75rem;
    }

    .llm-content h1 {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
}

/* ============================================================
   LAYER 2 · PROTECTED SIDEBAR LAYOUT  (desktop only)
   ============================================================ */

:root {
    --sidebar-width: 240px;
}

/* Mobile: protected pages look identical to public — no changes below 769px */

/* Desktop only: sidebar layout kicks in */
@media (min-width: 769px) {
    .protected-layout {
        --theme-header-height: 80px;
    }

    .protected-layout .content-wrap {
        padding-top: 0;
        display: flex;
        min-height: 100vh;
    }

    .protected-layout .header {
        height: 80px;
        padding-top: 0;
        display: flex;
        align-items: center;
    }

    /* Offset header so logo/search clear the sidebar.
       Cancel the max-width centering — the topbar must fill the
       full header width, starting after the fixed sidebar. */
    .protected-layout .header-topbar,
    .protected-layout .header-container {
        max-width: none;
        margin: 0;
        width: 100%;
        padding-right: 1.25rem;
    }

    /* Hide top desktop nav — sidebar replaces it */
    .protected-layout .nav {
        display: none;
    }

    /* Hide hamburger on desktop — sidebar is always visible */
    .protected-layout .hamburger-toggle {
        display: none;
    }

    .protected-layout .content {
        margin-left: var(--sidebar-width);
        flex: 1;
        min-width: 0;
    }
}

.app-sidebar {
    display: none; /* hidden on mobile always */
}

@media (min-width: 769px) {
    .app-sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 80px;
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - 80px);
        background: var(--theme-surface);
        border-right: 1px solid var(--theme-border);
        box-shadow: var(--theme-shadow-sm);
        z-index: 90;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-sidebar::-webkit-scrollbar { width: 4px; }
    .app-sidebar::-webkit-scrollbar-track { background: transparent; }
    .app-sidebar::-webkit-scrollbar-thumb {
        background: var(--theme-border);
        border-radius: 2px;
    }
}

.sidebar-nav {
    list-style: none;
    padding: 1rem 0;
    margin: 0;
    flex: 1;
}

.sidebar-nav li { margin: 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--theme-text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: var(--theme-transition);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav a:hover {
    background: var(--theme-surface-raised);
    color: var(--theme-primary);
    border-left-color: var(--theme-primary);
}

.sidebar-nav a.active {
    background: var(--theme-accent-light);
    color: var(--theme-primary);
    border-left-color: var(--theme-primary);
    font-weight: 600;
}

.sidebar-nav a .ti {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--theme-border);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    color: var(--theme-text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: var(--theme-radius);
    transition: var(--theme-transition);
}

.sidebar-footer a:hover {
    background: var(--theme-surface-raised);
    color: var(--theme-danger);
}

.sidebar-footer a .ti { font-size: 1rem; }

/* ============================================================
   LAYER 6 · THEME RUNTIME BRIDGE
   ============================================================
   Listens for postMessage events from the Fidy editor
   (application_preview.html) and applies the new CSS variable
   values to :root so every component re-paints instantly.

   This is the counterpart to _pushThemeToIframe() in the editor.
   It works even when the iframe is cross-origin because no DOM
   access is required — only window.addEventListener.
   ============================================================ */

/*
 * The actual listener is injected by base.html (see {% block javascript %}).
 * This comment block documents the contract.
 *
 * ── HOW --theme-surface-raised-text IS COMPUTED ──────────────────────────────
 *
 * --theme-surface-raised-text is computed by application_preview.html
 * (surfaceRaisedText() in getCurrentTheme / applyThemeValues / _pushThemeToIframe)
 * and saved to the database as part of the theme object alongside all other
 * --theme-* tokens. base.html does NOT need to compute it — it arrives as a
 * plain hex value in the postMessage vars and in the fidy-injected-theme style.
 *
 * ── WHAT TO ADD TO base.html {% block javascript %} ─────────────────────────
 *
 * Expected postMessage shape:
 *   {
 *     type: 'fidy_theme_update',
 *     vars: {
 *       '--theme-primary':              '#...',
 *       '--theme-primary-hover':        '#...',
 *       '--theme-secondary':            '#...',
 *       '--theme-secondary-hover':      '#...',
 *       '--theme-accent':               '#...',
 *       '--theme-accent-light':         '#...',
 *       '--theme-accent-mid':           '#...',
 *       '--theme-background':           '#...',
 *       '--theme-surface':              '#...',
 *       '--theme-surface-raised':       '#...',
 *       '--theme-surface-raised-text':  '#...',   ← computed by the editor
 *       '--theme-on-primary':           '#...',   ← computed by the editor
 *       '--theme-on-secondary':         '#...',   ← computed by the editor
 *       '--theme-on-accent':            '#...',   ← computed by the editor
 *       '--theme-on-success':           '#...',   ← computed by the editor
 *       '--theme-on-warning':           '#...',   ← computed by the editor
 *       '--theme-on-danger':            '#...',   ← computed by the editor
 *       '--theme-on-info':              '#...',   ← computed by the editor
 *       '--theme-text':                 '#...',
 *       '--theme-text-secondary':       '#...',
 *       '--theme-text-muted':           '#...',
 *       '--theme-border':               '#...',
 *       '--theme-success':              '#...',
 *       '--theme-success-hover':        '#...',
 *       '--theme-warning':              '#...',
 *       '--theme-danger':               '#...',
 *       '--theme-danger-hover':         '#...',
 *       '--theme-info':                 '#...',
 *       '--theme-font-family':          '...',
 *       '--theme-radius':               '8px',
 *       '--theme-radius-sm':            '4px',
 *       '--theme-radius-lg':            '12px',
 *       '--theme-radius-xl':            '16px',
 *     }
 *   }
 *
 * Only properties prefixed '--theme-' are accepted. Any other
 * keys are silently ignored as a basic security guard.
 *
 * ── IMPLEMENTATION ───────────────────────────────────────────────────────────
 *
 * window.addEventListener('message', function(event) {
 *     if (!event.data || event.data.type !== 'fidy_theme_update') return;
 *     const vars = event.data.vars || {};
 *     const root = document.documentElement;
 *     Object.keys(vars).forEach(function(key) {
 *         if (key.startsWith('--theme-')) root.style.setProperty(key, vars[key]);
 *     });
 * });
 *
 * ─────────────────────────────────────────────────────────────────────────────
 */