﻿/* ============================================================
   AEMS Unified CSS v2.0 — Mint Emerald / Matte Navy System
   Single source of truth for all visual styling.
   No page-specific styles. No hardcoded values.
   ============================================================ */

/* ---- 1. RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: auto;
}

html, body {
    overflow-x: hidden;
}

/* ---- TEXTURE OVERLAY: subtle grain + dot grid + cross pattern on background ---- */
/* All background layers in a single declaration to prevent override bugs.
   Layer order (top to bottom): dot grid, fabric texture, cross pattern.
   Each layer has its own background-size and repeat. */
body {
    background-color: var(--clr-bg) !important;
    background-image:
        var(--bg-grid),
        var(--texture-fabric),
        var(--bg-cross) !important;
    background-size: 24px 24px, 4px 4px, 60px 60px;
    background-repeat: repeat, repeat, repeat;
    background-attachment: fixed, fixed, fixed;
}

/* ---- SCROLL LOCK: When any modal/overlay is visible, lock background scroll ---- */
/* CSS :has() approach — works in all modern browsers (Chrome 105+, Edge 105+) */
/* Lock on html (not body) to prevent background scroll without losing scroll position */
html:has(.modal-overlay.show),
html:has(.wizard-overlay.show),
html:has(.detail-panel.open),
html:has(.dash-modal.show),
html:has(.sa-modal.show),
html:has(.conn-modal-overlay.show),
html:has(.sec-modal-overlay.show),
html:has(.li-modal-overlay.show),
html:has(.usage-modal.show),
html:has(.bs-confirm-overlay.show),
html:has(.billing-modal-backdrop.active),
html:has(.is-cb458930[style*="display: flex"]),
html:has(.is-cb458930[style*="display:flex"]) {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}
/* Also lock body when any overlay is open — prevents both vertical and horizontal scrollbars on the page behind */
body:has(.modal-overlay.show),
body:has(.wizard-overlay.show),
body:has(.detail-panel.open),
body:has(.dash-modal.show),
body:has(.sa-modal.show),
body:has(.conn-modal-overlay.show),
body:has(.sec-modal-overlay.show),
body:has(.li-modal-overlay.show),
body:has(.usage-modal.show),
body:has(.bs-confirm-overlay.show),
body:has(.billing-modal-backdrop.active),
body:has(.modal-overlay.show) .aems-page-content,
body:has(.wizard-overlay.show) .aems-page-content,
body:has(.dash-modal.show) .aems-page-content,
body:has(.sa-modal.show) .aems-page-content,
body:has(.conn-modal-overlay.show) .aems-page-content,
body:has(.sec-modal-overlay.show) .aems-page-content,
body:has(.li-modal-overlay.show) .aems-page-content,
body:has(.usage-modal.show) .aems-page-content,
body:has(.bs-confirm-overlay.show) .aems-page-content,
body:has(.billing-modal-backdrop.active) .aems-page-content {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}
/* While ANY modal overlay is open, .aems-page-content must carry NO transform.
   App-shell wraps page markup (including the position:fixed modal overlays)
   inside .aems-page-content; overscroll.js translates that wrapper at the
   scroll boundary, and a transformed ancestor becomes the containing block
   for fixed descendants — the full-viewport overlay then slides with the
   content and uncovers the topbar/sidebar with no dim over them. overscroll.js
   gates on _modalOpen(); this rule is the stylesheet-level backstop for any
   path that misses (e.g. a modal opened while a rebound is still animating).
   !important is required — it must beat the inline style overscroll.js sets. */
body:has(.modal-overlay.show) .aems-page-content,
body:has(.wizard-overlay.show) .aems-page-content,
body:has(.dash-modal.show) .aems-page-content,
body:has(.sa-modal.show) .aems-page-content,
body:has(.conn-modal-overlay.show) .aems-page-content,
body:has(.sec-modal-overlay.show) .aems-page-content,
body:has(.li-modal-overlay.show) .aems-page-content,
body:has(.usage-modal.show) .aems-page-content,
body:has(.bs-confirm-overlay.show) .aems-page-content,
body:has(.billing-modal-backdrop.active) .aems-page-content,
body:has(.detail-panel.open) .aems-page-content,
body:has(.ch-sidepanel.show) .aems-page-content {
    transform: none !important;
}
/* Also lock body as fallback for JS-added .modal-open class */
body.modal-open {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}
/* Block touch scroll chaining from overlay backdrop to page */
.modal-overlay.show {
    display: flex;
    touch-action: none;
}
/* But allow touch scrolling inside the modal card itself */
.modal-overlay.show .modal {
    touch-action: pan-y;
}

/* No visible scrollbars anywhere — scrolling still works via wheel/trackpad/keyboard */
html, body, .aems-page-content,
.modal-overlay, .wizard-overlay, .conn-modal-overlay, .sec-modal-overlay,
.billing-modal-backdrop, .li-modal-overlay, .usage-modal,
.modal-overlay .modal, .wizard-overlay .wizard, .conn-modal-overlay .conn-modal,
.sec-modal-overlay .sec-modal, .modal-overlay .modal-card, .modal-overlay .mr-rule-modal,
.billing-modal-backdrop .billing-modal, .bs-confirm-overlay .bs-confirm-modal,
.bs-confirm-overlay .bs-deact-modal, .li-modal-overlay .li-modal,
.wiz-help-panel, .detail-panel, .alert-list {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar,
.aems-page-content::-webkit-scrollbar,
.modal-overlay::-webkit-scrollbar, .wizard-overlay::-webkit-scrollbar,
.conn-modal-overlay::-webkit-scrollbar, .sec-modal-overlay::-webkit-scrollbar,
.billing-modal-backdrop::-webkit-scrollbar, .li-modal-overlay::-webkit-scrollbar,
.usage-modal::-webkit-scrollbar,
.modal-overlay .modal::-webkit-scrollbar, .wizard-overlay .wizard::-webkit-scrollbar,
.conn-modal-overlay .conn-modal::-webkit-scrollbar, .sec-modal-overlay .sec-modal::-webkit-scrollbar,
.modal-overlay .modal-card::-webkit-scrollbar, .modal-overlay .mr-rule-modal::-webkit-scrollbar,
.billing-modal-backdrop .billing-modal::-webkit-scrollbar,
.bs-confirm-overlay .bs-confirm-modal::-webkit-scrollbar,
.bs-confirm-overlay .bs-deact-modal::-webkit-scrollbar,
.li-modal-overlay .li-modal::-webkit-scrollbar,
.wiz-help-panel::-webkit-scrollbar, .detail-panel::-webkit-scrollbar,
.alert-list::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

:root, [data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-normal);
    line-height: var(--leading-normal);
    color: var(--clr-text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* FOUC prevention and loading spinner styles moved to tokens.css
   (tokens.css loads in <head> before body renders, aems.css loads after body) */

/* Smooth reveal after shell positions everything */
body.aems-shell-loaded .aems-page-content {
    animation: aems-content-reveal 0.12s ease-out;
}
@keyframes aems-content-reveal {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes aems-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes aems-slide-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes aems-slide-down {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes aems-scale-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes aems-pulse-soft {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

@keyframes aems-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes aems-glow-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(20,184,137,0.0); }
    50%      { box-shadow: 0 0 10px 2px rgba(20,184,137,0.04); }
}

.aems-animate-fade-in    { animation: aems-fade-in var(--duration-normal) var(--ease-out); }
.aems-animate-slide-up   { animation: aems-slide-up var(--duration-normal) var(--ease-out); }
.aems-animate-slide-down { animation: aems-slide-down var(--duration-normal) var(--ease-out); }
.aems-animate-scale-in   { animation: aems-scale-in var(--duration-normal) var(--ease-spring); }
.aems-animate-pulse     { animation: aems-pulse-soft 2s var(--ease-in-out) infinite; }

img, svg, video { display: block; max-width: 100%; }

a {
    color: var(--clr-text-link);
    text-decoration: none;
    transition: color var(--duration-75) var(--ease-out);
}
a:hover { color: var(--clr-text-link-hover); }
/* Button-like anchors must keep their contrast color on hover (A-012) */
a.aems-btn-primary:hover,
a.aems-hero-cta:hover,
a.aems-btn:hover,
a.btn-primary:hover,
a.btn:hover,
button.aems-btn-primary:hover,
button.aems-hero-cta:hover,
button.aems-btn:hover,
button.btn-primary:hover,
button.btn:hover {
    color: var(--clr-accent-contrast);
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
/* Ensure ALL form elements have visible boxes in both themes */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not(.aems-input):not(.form-input):not([type="range"]),
select:not(.aems-select):not(.form-select),
textarea:not(.aems-textarea):not(.form-textarea) {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--clr-text);
    background: var(--clr-surface-input);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--duration-150) var(--ease-out), box-shadow var(--duration-150) var(--ease-out);
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not(.aems-input):not(.form-input):not([type="range"]):hover,
select:not(.aems-select):not(.form-select):hover,
textarea:not(.aems-textarea):not(.form-textarea):hover {
    border-color: var(--clr-border-hover);
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not(.aems-input):not(.form-input):not([type="range"]):focus,
select:not(.aems-select):not(.form-select):focus,
textarea:not(.aems-textarea):not(.form-textarea):focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px var(--clr-accent-muted);
}
input[type="checkbox"], input[type="radio"] { cursor: pointer; }
ul, ol { list-style: none; }

table { border-collapse: collapse; width: 100%; }

:focus-visible {
    outline: 2px solid var(--clr-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Eye-tracking separator lines for list items and table rows */
.aems-card-list > *, .aems-data-list > * { border-bottom: 1px solid var(--clr-divider); }
.aems-card-list > *:last-child, .aems-data-list > *:last-child { border-bottom: none; }
table.aems-table tr td, table.data-table tr td,
table.aems-table tr th, table.data-table tr th { border-bottom: 1px solid var(--clr-divider); }
table.aems-table tr:last-child td, table.data-table tr:last-child td,
table.aems-table tr:last-child th, table.data-table tr:last-child th { border-bottom: none; }
/* A-005: Universal table row separators for ALL tables (catches hashed/scoped class tables) */
table:not(.no-separators) > tbody > tr > td,
table:not(.no-separators) > tbody > tr > th { border-bottom: 1px solid var(--clr-divider); }
table:not(.no-separators) > tbody > tr:last-child > td,
table:not(.no-separators) > tbody > tr:last-child > th { border-bottom: none; }
table:not(.no-separators) > thead > tr > th { border-bottom: 2px solid var(--clr-border); }

::selection {
    background: var(--clr-accent-muted-strong);
    color: var(--clr-text);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- 2. APP LAYOUT ---- */
.aems-app-layout {
    display: flex;
    min-height: 100vh;
    background: transparent;
}

.aems-app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-w);
    height: 100vh;
    min-width: 0;
    overflow: hidden;
}

.aems-content {
    flex: 1;
    padding: var(--space-8) var(--space-6);
    overflow: visible;
}

/* ---- 2b. PUBLIC LAYOUT ---- */
.aems-public-layout {
    min-height: 100vh;
    background: transparent;
}

.aems-page-content {
    flex: 1;
    padding: var(--space-8) var(--space-6);
    padding-top: 60px;
    overflow: auto;
    min-width: 0;
}

/* App pages: content flows naturally, body is the only scroll container */
.aems-app-layout .aems-page-content {
    overflow: auto;
    touch-action: pan-y;
}

/* Public pages: no padding wrapper — content flows directly */
.aems-public-layout .aems-page-content {
    overflow: visible;
    padding: 0;
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
    touch-action: pan-y;
}

/* ---- STAT CARDS (Dashboard etc.) ---- */
.aems-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.aems-stat-card {
    background: var(--clr-surface);
    border: 1px solid var(--clr-card-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    transition: border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out), transform var(--duration-100) var(--ease-out);
}

.aems-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.aems-stat-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-accent-muted);
    border-radius: var(--radius-sm);
    color: var(--clr-accent);
}

/* ---- SECTION CARDS (General Purpose) ---- */
.aems-stat-val {
    font-size: var(--text-2xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-text);
}
.aems-stat-label {
    font-size: var(--text-xs);
    color: var(--clr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.aems-section-card {
    background: var(--clr-surface);
    border: 1px solid var(--clr-card-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
    transition: border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out);
}

.aems-section-card:hover {
    box-shadow: var(--shadow-lg);
}

/* ---- 2b. AUTH CARD — rich visual depth for login/signup/verify/reset ---- */
.aems-auth-bg {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    position: relative;
    overflow: hidden;
}
.aems-auth-bg::before {
    content: '';
    position: absolute;
    top: -40%;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 600px;
    background: radial-gradient(ellipse at center, var(--clr-accent-glow) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}
.aems-auth-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg-grid);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}
.aems-auth-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 460px;
    background: linear-gradient(180deg, var(--clr-surface-raised) 0%, var(--clr-surface) 100%);
    border: 1px solid var(--clr-card-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-xl), 0 0 100px var(--clr-accent-glow-lg);
}
.aems-auth-card-bar {
    height: 4px;
    background: linear-gradient(90deg, var(--clr-accent-tertiary), var(--clr-accent));
}
.aems-auth-card-body {
    padding: var(--space-10) var(--space-8);
}
.aems-auth-brand {
    text-align: center;
    margin-bottom: var(--space-8);
}
.aems-auth-brand h1 {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-accent);
    margin: 0 0 var(--space-2) 0;
    line-height: 1;
}
.aems-auth-brand p {
    font-size: var(--text-sm);
    color: var(--clr-text-muted);
    margin: 0;
}
.aems-auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-6) 0;
}
.aems-auth-divider-line {
    flex: 1;
    height: 1px;
    background: var(--clr-card-border);
}
.aems-auth-divider span {
    font-size: var(--text-xs);
    color: var(--clr-text-muted);
    white-space: nowrap;
}
.aems-auth-social {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    align-items: center;
    margin-bottom: var(--space-3);
}
.aems-auth-social-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.aems-auth-social-btn:hover {
    border-color: var(--clr-accent);
    background: var(--clr-accent-muted);
    transform: translateY(-1px);
}
.aems-auth-footer {
    text-align: center;
    margin-top: var(--space-8);
    font-size: var(--text-sm);
    color: var(--clr-text-muted);
}
.aems-auth-footer a {
    color: var(--clr-accent);
    font-weight: var(--weight-semibold);
}
.aems-auth-error {
    display: none;
    padding: var(--space-3);
    background: var(--clr-error-muted);
    border: 1px solid var(--clr-danger-soft);
    border-radius: var(--radius-md);
    color: var(--clr-error);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
}
.aems-auth-success {
    display: none;
    padding: var(--space-6);
    background: var(--clr-success-muted);
    border: 1px solid var(--clr-success-soft);
    border-radius: var(--radius-lg);
    text-align: center;
    margin-bottom: var(--space-4);
}
.aems-auth-icon-circle {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aems-auth-icon-circle.success { background: var(--clr-success-muted); }
.aems-auth-icon-circle.error { background: var(--clr-error-muted); }
.aems-auth-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--clr-accent-muted);
    border-top-color: var(--clr-accent);
    border-radius: 50%;
    animation: aems-spin 0.8s linear infinite;
    margin: var(--space-4) auto;
}
@keyframes aems-spin { to { transform: rotate(360deg); } }

/* ---- 2c. QUICK ACTIONS — dashboard rich action buttons ---- */
.quick-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--clr-card-border);
    background: var(--clr-surface);
    color: var(--clr-text);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-align: left;
    text-decoration: none;
    transition: border-color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
    box-shadow: var(--shadow-xs);
    line-height: 1.35;
}
.quick-action-btn:hover {
    border-color: var(--clr-accent);
    background: var(--clr-accent-muted);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.quick-action-btn:active {
    transform: translateY(0);
    box-shadow: none;
}
.quick-action-btn .qa-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-accent-muted);
    color: var(--clr-accent);
}
.quick-action-btn .qa-text {
    flex: 1;
    min-width: 0;
}
.quick-action-btn.primary {
    background: linear-gradient(135deg, var(--clr-accent-muted-strong), var(--clr-accent-muted));
    border-color: var(--clr-accent);
    color: var(--clr-accent);
    font-weight: var(--weight-semibold);
}
.quick-action-btn.primary .qa-icon {
    background: var(--clr-accent);
    color: var(--clr-on-accent);
}
.quick-action-btn.primary:hover {
    background: linear-gradient(135deg, var(--clr-accent-muted), var(--clr-accent-muted-strong));
    box-shadow: var(--shadow-sm), 0 0 24px var(--clr-accent-glow);
}
.quick-action-btn.span-2 {
    grid-column: 1 / -1;
}

/* ---- 3. TOPBAR ---- */
.aems-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    background: var(--clr-bg);
    border-bottom: 1px solid var(--clr-border);
}

/* Sidebar toggle button — visible on app pages (desktop + mobile) */
.aems-app-layout .aems-sidebar-toggle {
    display: flex !important;
}

.aems-topbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-weight: var(--weight-bold);
    font-size: var(--text-lg);
    color: var(--clr-text);
    text-decoration: none;
}

.aems-topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-left: auto;
    flex-shrink: 0;
    overflow: visible;
}

.aems-toggle-group {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    flex-shrink: 0;
    padding: var(--space-1) var(--space-2);
    background: var(--clr-surface-raised);
    border-radius: var(--radius-md);
    border: 1px solid var(--clr-border);
    box-shadow: var(--shadow-sm);
}

/* ---- 4. SIDEBAR ---- */
.aems-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--clr-surface-glass);
    backdrop-filter: blur(var(--glass-blur)) saturate(1.1);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.1);
    border-right: 1px solid var(--clr-border);
    display: flex;
    flex-direction: column;
    contain: layout style;
    z-index: var(--z-sidebar);
    pointer-events: auto;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding-bottom: 24px;
    transition: width 0.3s ease;
}

.aems-sidebar-brand {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-6);
    border-bottom: 1px solid var(--clr-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.aems-nav-group {
    flex-shrink: 0;
    padding: var(--space-1) 0;
}

.aems-sidebar-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--clr-border);
}

.aems-sidebar-logo {
    font-weight: var(--weight-bold);
    font-size: var(--text-xl);
    color: var(--clr-text);
}

.aems-sidebar-ver {
    font-size: var(--text-xs);
    color: var(--clr-text-muted);
}

.aems-nav-group-label {
    padding: 4px var(--space-5);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--clr-text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.aems-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 5px var(--space-5);
    margin: 1px var(--space-3);
    color: var(--clr-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    border-radius: var(--radius-md);
    transition: color var(--duration-75) var(--ease-out), background-color var(--duration-75) var(--ease-out);
    text-decoration: none;
    white-space: nowrap;
    will-change: color, background-color;
    pointer-events: auto;
    touch-action: manipulation;
}

.aems-nav-item:hover {
    color: var(--clr-text);
    background: var(--clr-accent-muted);
}

.aems-nav-item.active {
    background: var(--clr-accent);
    color: var(--clr-accent-contrast);
    font-weight: var(--weight-semibold);
}

.aems-nav-item.active .aems-icon {
    color: var(--clr-accent-contrast);
}

/* ---- Collapsible Nav Sections (v5.1) ---- */
.aems-nav-toggle-all {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(100% - 24px);
    margin: 4px 12px 8px;
    padding: 6px;
    background: transparent;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    color: var(--clr-text-muted);
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background-color var(--duration-75) var(--ease-out);
}
.aems-nav-toggle-all:hover {
    color: var(--clr-text);
    background: var(--clr-surface-hover);
}

.aems-nav-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px var(--space-5);
    cursor: pointer;
    user-select: none;
    transition: background-color var(--duration-75) var(--ease-out);
}
.aems-nav-group-header:hover {
    background: var(--clr-surface-hover);
}
.aems-nav-group-header:focus {
    outline: 2px solid var(--clr-accent);
    outline-offset: -2px;
    border-radius: var(--radius-sm);
}

.aems-nav-caret {
    display: inline-block;
    font-size: 12px;
    color: var(--clr-text-muted);
    transition: transform var(--duration-200) var(--ease-out);
    flex-shrink: 0;
}
.aems-nav-caret.collapsed {
    transform: rotate(-90deg);
}

.aems-nav-group-label {
    padding: 0;
    flex: 1;
}

.aems-nav-group-body {
    overflow: hidden;
    max-height: 1000px;
    transition: max-height var(--duration-300) var(--ease-out);
}
.aems-nav-group-body.collapsed {
    max-height: 0;
    overflow: hidden;
}

/* ---- Nav Label (for icon-only mode hiding) ---- */
.aems-nav-label {
    transition: opacity var(--duration-200) var(--ease-out);
}

/* Nav item icons — consistent size in both expanded and collapsed modes */
.aems-nav-item .aems-icon {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0;
    fill: none;
}
.aems-nav-group-icon {
    fill: none;
}

/* ---- Icon-Only Sidebar Mode ---- */
.aems-sidebar.icon-only {
    width: 56px;
}
/* When sidebar collapses, shrink the margin variable so app-main follows */
.aems-app-layout:has(.aems-sidebar.icon-only) .aems-app-main {
    margin-left: 56px !important;
}
.aems-sidebar.icon-only .aems-nav-label,
.aems-sidebar.icon-only .aems-nav-group-label,
.aems-sidebar.icon-only .aems-sidebar-ver {
    display: none !important;
}
/* Hide CSS tooltips on sidebar nav items when sidebar is expanded (labels visible) */
.aems-sidebar:not(.icon-only) .aems-nav-item.aems-tooltip::after,
.aems-sidebar:not(.icon-only) .aems-nav-group-header.aems-tooltip::after {
    display: none !important;
}

.aems-sidebar.icon-only .aems-nav-item {
    justify-content: center;
    padding: 10px 8px;
    margin: 1px 8px;
}
.aems-sidebar.icon-only .aems-nav-item .aems-icon {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0;
}
.aems-sidebar.icon-only .aems-nav-group-icon {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0;
    opacity: 1;
}
.aems-sidebar .aems-nav-group-icon {
    display: none;
}
.aems-sidebar.icon-only .aems-nav-group-icon {
    display: block;
}
.aems-sidebar.icon-only .aems-nav-caret {
    display: none;
}
.aems-sidebar.icon-only .aems-nav-toggle-all {
    width: 40px;
    margin: 4px 8px;
}
.aems-sidebar.icon-only .aems-nav-group-header {
    justify-content: center;
    padding: 8px;
    cursor: pointer;
}
.aems-sidebar.icon-only .aems-sidebar-brand {
    justify-content: center;
    padding: var(--space-2) 0;
}
.aems-sidebar.icon-only .aems-sidebar-logo {
    display: none;
}
.aems-sidebar.icon-only .aems-sidebar-brand::after {
    content: 'A';
    display: block;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-accent);
    background: var(--clr-accent-muted);
    border-radius: var(--radius-sm);
}
.aems-sidebar.icon-only .aems-sidebar-footer > div {
    justify-content: center;
}
.aems-sidebar.icon-only .aems-sidebar-footer > div > div:last-child {
    display: none !important;
}

.aems-app-main.sidebar-icon-only {
    margin-left: 56px !important;
}

/* Fallback: when sidebar has icon-only class, also target sibling app-main */
.aems-sidebar.icon-only ~ .aems-app-main,
.aems-app-layout:has(.aems-sidebar.icon-only) .aems-app-main {
    margin-left: 56px !important;
}
/* Icon-only tooltips */
.aems-sidebar.icon-only .aems-nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 52px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--clr-surface-raised);
    color: var(--clr-text);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    z-index: var(--z-tooltip);
    pointer-events: none;
}

/* ---- Scroll Indicators ---- */
.aems-sidebar-scroll-up,
.aems-sidebar-scroll-down {
    position: sticky;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 6px;
    background: var(--clr-surface-raised);
    border-top: 1px solid var(--clr-border);
    color: var(--clr-text-muted);
    font-size: 12px;
    cursor: pointer;
    z-index: 10;
    transition: color var(--duration-75) var(--ease-out), background-color var(--duration-75) var(--ease-out);
}
.aems-sidebar-scroll-up {
    top: 0;
    border-bottom: 1px solid var(--clr-border);
    border-top: none;
}
.aems-sidebar-scroll-down {
    bottom: 0;
}
.aems-sidebar-scroll-up:hover,
.aems-sidebar-scroll-down:hover {
    color: var(--clr-text);
    background: var(--clr-surface-hover);
}

/* ---- Topbar Title and Left Container ---- */
.aems-topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}
.aems-topbar-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--clr-text);
    margin: 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Public nav bar (under topbar) */
.aems-public-nav {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    margin: 0 auto; /* center between brand and actions */
}

.aems-public-nav a {
    color: var(--clr-text-secondary);
    text-decoration: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out);
}

.aems-public-nav a:hover {
    color: var(--clr-text);
    background: var(--clr-accent-muted);
}

.aems-public-content {
    padding: var(--space-8) var(--space-6);
    max-width: var(--content-max);
    margin: 0 auto;
}

/* ---- 5. LANGUAGE SWITCH ---- */
.aems-lang-switch {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.aems-lang-pill {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--clr-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
}

.aems-lang-pill:hover {
    color: var(--clr-text);
    background: var(--clr-surface-hover);
}

.aems-lang-pill.active {
    background: var(--clr-accent);
    color: var(--clr-accent-contrast);
}

.aems-lang-divider {
    color: var(--clr-border-hover);
    font-size: var(--text-xs);
    user-select: none;
}

/* ---- 6. THEME TOGGLE ---- */
.theme-toggle-btn,
.lang-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
}

.lang-toggle-btn {
    width: auto;
    min-width: 32px;
    padding: 0 8px;
}

.lang-toggle-text {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
}

.theme-toggle-btn:hover,
.lang-toggle-btn:hover {
    background: var(--clr-accent-muted);
    color: var(--clr-accent);
    border-color: var(--clr-accent);
}

.theme-toggle-btn .aems-icon,
.lang-toggle-btn .aems-icon {
    width: 20px;
    height: 20px;
}

.lang-toggle-btn .aems-icon {
    width: 16px;
    height: 16px;
}

/* ---- 7. BUTTONS ---- */

/* Tooltip toggle button — same visual style as theme/lang toggle */
.tooltip-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out);
}
.tooltip-toggle-btn:hover {
    background: var(--clr-accent-muted);
    color: var(--clr-accent);
    border-color: var(--clr-accent);
}
.tooltip-toggle-btn .aems-icon {
    width: 20px;
    height: 20px;
}
.btn, .ch-icon-btn, .aems-nav-item, .aems-lang-pill, .ch-tab, .ch-subnav-item {
    will-change: color, background-color, border-color;
}
.aems-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: color var(--duration-100) var(--ease-out), background var(--duration-100) var(--ease-out), border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out), transform var(--duration-100) var(--ease-out);
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1;
}

.aems-btn-primary {
    background: var(--clr-accent);
    color: var(--clr-accent-contrast);
    box-shadow: 0 1px 4px rgba(20,184,137,0.12);
}

.aems-btn-primary:hover {
    background: var(--clr-accent-hover);
    box-shadow: 0 2px 8px rgba(20,184,137,0.09), 0 0 7px var(--clr-accent-glow);
    transform: translateY(-1px);
}

.aems-btn-primary:active {
    background: var(--clr-accent-active);
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(20,184,137,0.10);
}

.aems-btn-secondary {
    background: var(--clr-surface-raised);
    color: var(--clr-text);
    border-color: var(--clr-border);
}

.aems-btn-secondary:hover {
    background: var(--clr-accent-muted);
    border-color: var(--clr-accent);
    color: var(--clr-accent-active);
}

.aems-btn-ghost {
    background: transparent;
    color: var(--clr-text-secondary);
    border-color: var(--clr-border);
}

.aems-btn-ghost:hover {
    background: var(--clr-accent-muted);
    color: var(--clr-accent-active);
    border-color: var(--clr-accent);
}

.aems-btn-danger {
    background: var(--clr-danger);
    color: var(--clr-on-accent);
    box-shadow: 0 2px 8px rgba(var(--rgb-danger),0.25);
}

.aems-btn-danger:hover {
    background: var(--clr-danger);
    filter: brightness(0.9);
    box-shadow: 0 4px 16px rgba(var(--rgb-danger),0.35);
}

.aems-btn-sm { padding: 6px 12px; font-size: var(--text-xs); border-radius: var(--radius-md); }
.aems-btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); border-radius: var(--radius-xl); }

.aems-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ---- 8. CARDS ---- */
.aems-card {
    background: var(--clr-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--clr-card-border);
    box-shadow: var(--shadow-card);
    transition: color var(--duration-100) var(--ease-out), background var(--duration-100) var(--ease-out), border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out), transform var(--duration-100) var(--ease-out);
    overflow: hidden;
}

.aems-card-hover:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card-hover);
}

.aems-card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--clr-divider);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.aems-card-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--clr-text);
    margin: 0;
}

.aems-card-body {
    padding: var(--space-5) var(--space-6);
}

.aems-card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--clr-divider);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-4);
}

/* Metric Card variant */
.aems-metric-card {
    padding: var(--space-6);
    text-align: left;
}

.aems-metric-value {
    font-size: var(--text-2xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-text);
    line-height: 1.2;
    margin-bottom: var(--space-1);
}

.aems-metric-label {
    font-size: var(--text-sm);
    color: var(--clr-text-secondary);
    font-weight: var(--weight-medium);
}

.aems-metric-change {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    margin-top: var(--space-2);
}

.aems-metric-change.positive { color: var(--clr-success); }
.aems-metric-change.negative { color: var(--clr-danger); }

/* ---- 9. FORMS ---- */
.aems-form-group {
    margin-bottom: var(--space-5);
}

.aems-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--clr-text);
    margin-bottom: var(--space-2);
}

.aems-input,
.aems-select,
.aems-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    color: var(--clr-text);
    background: var(--clr-surface-input);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%239C92AC' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
    outline: none;
}

.aems-input::placeholder,
.aems-textarea::placeholder {
    color: var(--clr-text-muted);
}

.aems-input:hover,
.aems-select:hover,
.aems-textarea:hover {
    border-color: var(--clr-border-hover);
}

.aems-input:focus,
.aems-select:focus,
.aems-textarea:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px var(--clr-accent-muted);
}

.aems-input:disabled,
.aems-select:disabled,
.aems-textarea:disabled {
    background: var(--clr-surface-raised);
    color: var(--clr-text-muted);
    cursor: not-allowed;
}

.aems-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23657786' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

.aems-textarea {
    min-height: 100px;
    resize: vertical;
}

.aems-form-hint {
    font-size: var(--text-xs);
    color: var(--clr-text-muted);
    margin-top: var(--space-1);
}

.aems-form-error {
    font-size: var(--text-xs);
    color: var(--clr-danger);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

/* ---- 10. TABLES ---- */
.aems-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--clr-card-border);
}

.aems-table {
    width: 100%;
    font-size: var(--text-sm);
    color: var(--clr-text);
    background: var(--clr-surface);
}

.aems-table thead th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-weight: var(--weight-semibold);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--clr-text-muted);
    background: var(--clr-surface-raised);
    border-bottom: 1px solid var(--clr-divider);
    white-space: nowrap;
}

.aems-table tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--clr-divider);
    vertical-align: middle;
}

.aems-table tbody tr:last-child td { border-bottom: none; }

.aems-table tbody tr:hover {
    background: var(--clr-surface-hover);
}

.aems-table .aems-table-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: flex-end;
}

/* ---- 11. MODALS ---- */
.aems-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--clr-overlay);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8) var(--space-6);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-250) var(--ease-out), visibility var(--duration-250);
}

.aems-modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.aems-modal {
    background: var(--clr-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--clr-card-border);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transform: translateY(20px) scale(0.98);
    transition: transform var(--duration-250) var(--ease-out);
}

.aems-modal-backdrop.active .aems-modal {
    transform: translateY(0) scale(1);
}

.aems-modal-close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--clr-text-muted);
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
    z-index: 2;
}

.aems-modal-close:hover {
    background: var(--clr-surface-hover);
    color: var(--clr-text);
}

.aems-modal-header {
    padding: var(--space-5) var(--space-6) 0;
    margin-bottom: var(--space-5);
}

.aems-modal-title {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--clr-text);
    margin: 0;
    padding-right: var(--space-8);
}

.aems-modal-body {
    padding: 0 var(--space-6);
}

.aems-modal-footer {
    padding: var(--space-5) var(--space-6);
    border-top: 1px solid var(--clr-divider);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-4);
    margin-top: var(--space-4);
}

/* ---- 12. DROPDOWNS ---- */
.aems-dropdown {
    position: absolute;
    background: var(--clr-surface-raised);
    border-radius: var(--radius-md);
    border: 1px solid var(--clr-border);
    box-shadow: var(--shadow-dropdown);
    min-width: 200px;
    z-index: var(--z-dropdown);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
}

.aems-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.aems-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--clr-text);
    cursor: pointer;
    transition: background var(--duration-100) var(--ease-out);
    text-decoration: none;
}

.aems-dropdown-item:hover {
    background: var(--clr-surface-hover);
}

[data-theme="light"] .aems-dropdown-item:hover {
    background: var(--clr-surface-hover);
}

.aems-dropdown-item .icon-left {
    color: var(--clr-text-secondary);
    flex-shrink: 0;
}

.aems-dropdown-item .check-right {
    margin-left: auto;
    color: var(--clr-accent);
    flex-shrink: 0;
}

.aems-dropdown-divider {
    height: 1px;
    background: var(--clr-divider);
    margin: var(--space-1) 0;
}

/* ---- 13. TOASTS ---- */
.aems-toast-container {
    position: fixed;
    top: calc(var(--topbar-h) + var(--space-4));
    right: var(--space-6);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    pointer-events: none;
}

.aems-toast {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    background: var(--clr-surface-raised);
    border-radius: var(--radius-md);
    border: 1px solid var(--clr-border);
    box-shadow: var(--shadow-md);
    font-size: var(--text-sm);
    color: var(--clr-text);
    max-width: 400px;
    pointer-events: auto;
    transform: translateX(100%);
    opacity: 0;
    transition: color var(--duration-150) var(--ease-out), background var(--duration-150) var(--ease-out), border-color var(--duration-150) var(--ease-out), box-shadow var(--duration-150) var(--ease-out), transform var(--duration-150) var(--ease-out);
}

.aems-toast.show {
    transform: translateX(0);
    opacity: 1;
}

.aems-toast-success { border-left: 3px solid var(--clr-success); }
.aems-toast-error   { border-left: 3px solid var(--clr-danger); }
.aems-toast-warning { border-left: 3px solid var(--clr-warning); }
.aems-toast-info    { border-left: 3px solid var(--clr-info); }

/* ---- 14. EMPTY STATE ---- */
.aems-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--clr-text-muted);
}

.aems-empty-state-icon {
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-4);
    color: var(--clr-text-muted);
    opacity: 0.5;
}

.aems-empty-state-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--clr-text);
    margin-bottom: var(--space-2);
}

.aems-empty-state-text {
    font-size: var(--text-sm);
    color: var(--clr-text-secondary);
    max-width: 400px;
    margin-bottom: var(--space-6);
}

/* ---- 15. SKELETON LOADING ---- */
.aems-skeleton {
    background: linear-gradient(90deg, var(--clr-surface-raised) 25%, var(--clr-surface-hover) 50%, var(--clr-surface-raised) 75%);
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: aems-skeleton-shimmer 1.5s infinite;
}

@keyframes aems-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---- 16. HERO SECTION (public pages) ---- */
.aems-hero {
    padding: var(--space-16) var(--space-6);
    text-align: center;
    max-width: var(--content-max);
    margin: 0 auto;
}

.aems-hero-title {
    font-size: var(--text-4xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-text);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    margin-bottom: var(--space-5);
}

.aems-hero-title span {
    background: linear-gradient(135deg, var(--clr-accent), var(--clr-accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.aems-hero-subtitle {
    font-size: var(--text-lg);
    color: var(--clr-text-secondary);
    line-height: var(--leading-relaxed);
    max-width: 640px;
    margin: 0 auto var(--space-6);
}

.aems-hero-cta {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-8);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    border-radius: var(--radius-full);
    background: var(--clr-accent);
    color: var(--clr-accent-contrast);
    text-decoration: none;
    transition: color var(--duration-100) var(--ease-out), background var(--duration-100) var(--ease-out), border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out), transform var(--duration-100) var(--ease-out);
    box-shadow: 0 2px 8px rgba(20,184,137,0.15);
}

.aems-hero-cta:hover {
    background: var(--clr-accent-hover);
    box-shadow: 0 4px 12px rgba(20,184,137,0.10), 0 0 10px var(--clr-accent-glow);
    transform: translateY(-2px);
}

/* ---- 17. FEATURE GRID (bento) ---- */
.aems-feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-5);
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--space-6);
}

.aems-feature-card {
    background: var(--clr-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-6);
    border: 1px solid var(--clr-card-border);
    box-shadow: var(--shadow-card);
    transition: color var(--duration-100) var(--ease-out), background var(--duration-100) var(--ease-out), border-color var(--duration-100) var(--ease-out), box-shadow var(--duration-100) var(--ease-out), transform var(--duration-100) var(--ease-out);
}

.aems-feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card-hover);
}

.aems-feature-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--clr-accent-muted);
    color: var(--clr-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.aems-feature-card h3 {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--clr-text);
    margin: 0 0 var(--space-2) 0;
}

.aems-feature-card p {
    font-size: var(--text-sm);
    color: var(--clr-text-secondary);
    line-height: var(--leading-relaxed);
    margin: 0;
}

/* ---- 18. PAGE HEADER ---- */
.aems-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
    gap: var(--space-4);
}

.aems-page-header h1 {
    font-size: var(--text-2xl);
    font-weight: var(--weight-extrabold);
    color: var(--clr-text);
    margin: 0;
}

.aems-page-header p {
    color: var(--clr-text-secondary);
    font-size: var(--text-sm);
    margin: var(--space-1) 0 0;
}

/* ---- 19. BADGES ---- */
.aems-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    border-radius: var(--radius-full);
    line-height: 1;
}

.aems-badge-success { background: var(--clr-accent-muted); color: var(--clr-accent); }
.aems-badge-warning { background: rgba(var(--rgb-warning),0.12); color: var(--clr-warning-text, var(--clr-warning)); }
.aems-badge-danger  { background: rgba(var(--rgb-danger),0.12); color: var(--clr-danger); }
.aems-badge-info    { background: rgba(var(--rgb-info),0.12); color: var(--clr-info); }
.aems-badge-muted   { background: var(--clr-surface-raised); color: var(--clr-text-muted); }

/* ---- 20. TABS ---- */
.aems-tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--clr-divider);
    margin-bottom: var(--space-5);
}

.aems-tab {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--clr-text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), border-color var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
}

.aems-tab:hover {
    color: var(--clr-text);
}

.aems-tab.active {
    color: var(--clr-accent);
    border-bottom-color: var(--clr-accent);
    font-weight: var(--weight-semibold);
}

/* ---- 21. ICONS ---- */
.aems-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    fill: none;
}

.aems-icon-sm { width: 16px; height: 16px; }
.aems-icon-lg { width: 24px; height: 24px; }
.aems-icon-xl { width: 32px; height: 32px; }

/* ---- 22. STATUS INDICATORS ---- */
.aems-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.aems-status-dot.online  { background: var(--clr-success); box-shadow: 0 0 6px var(--clr-success); }
.aems-status-dot.away    { background: var(--clr-warning); }
.aems-status-dot.offline { background: var(--clr-text-muted); }
.aems-status-dot.busy    { background: var(--clr-danger); }

/* ---- 23. TOOLTIP ---- */
/* Universal tooltip system for all interactive elements with data-tooltip */

.aems-tooltip {
    position: relative;
}

/* Tooltip toggle: when body has .aems-tooltips-off, suppress ALL CSS tooltips
   EXCEPT on the collapsed sidebar (icon-only) where tooltips are always needed.
   The toggle button itself is inside overflow:hidden so it uses the floating
   tooltip handler (which has its own exception) -- no CSS ::after needed. */
body.aems-tooltips-off .aems-tooltip::after {
    display: none !important;
}
/* Collapsed sidebar tooltips are ALWAYS on regardless of toggle */
body.aems-tooltips-off .aems-sidebar.icon-only .aems-nav-item[data-tooltip]::after,
body.aems-tooltips-off .aems-sidebar.icon-only .aems-nav-group-header[data-tooltip]::after {
    display: block !important;
}

.aems-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-2) var(--space-3);
    background: var(--clr-surface-raised);
    color: var(--clr-text);
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-tooltip);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-75) var(--ease-out), visibility var(--duration-75) var(--ease-out);
    pointer-events: none;
    z-index: var(--z-tooltip);
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aems-tooltip:hover::after,
.aems-tooltip:focus-visible::after {
    opacity: 1;
    visibility: visible;
}

/* Suppress CSS ::after tooltip when floating tooltip handles it (inside overflow:hidden) */
.aems-tooltip.tip-floating::after {
    display: none !important;
}

/* Tooltip position: top (explicit — used when near bottom of viewport) */
.aems-tooltip.tip-top::after {
    bottom: calc(100% + 6px);
    top: auto;
}

/* Tooltip position: bottom (for elements near top of viewport) */
.aems-tooltip.tip-bottom::after {
    bottom: auto;
    top: calc(100% + 6px);
}

/* Tooltip position: left (for elements near right edge) */
.aems-tooltip.tip-left::after {
    bottom: auto;
    top: 50%;
    left: auto;
    right: calc(100% + 6px);
    transform: translateY(-50%);
}

/* Tooltip position: right (for elements near left edge) */
.aems-tooltip.tip-right::after {
    bottom: auto;
    top: 50%;
    left: calc(100% + 6px);
    transform: translateY(-50%);
}

/* Tooltip for icon-only buttons in topbar (no padding, tighter) */
.aems-tooltip.tip-compact::after,
button.aems-tooltip:not(.has-text)::after {
    padding: 3px 8px;
    font-size: 12px;
}

/* Ensure tooltips on text buttons have proper max-width for longer text */
.aems-tooltip:not(.tip-compact)::after {
    max-width: 280px;
    white-space: normal;
    line-height: 1.3;
}

/* Tooltip inside modals needs higher z-index than modal backdrop */
.modal-overlay .aems-tooltip::after,
.modal-overlay.show .aems-tooltip::after {
    z-index: var(--z-confirm, 1200);
}

/* Tooltip inside Casey chat panel */
.casey-chat-panel .aems-tooltip::after {
    z-index: calc(var(--z-chat, 950) + 100);
}

/* Tooltip inside dropdown menus */
.dropdown-menu .aems-tooltip::after,
.ch-dropdown .aems-tooltip::after {
    z-index: var(--z-dropdown, 700);
}

/* ---- 24. RESPONSIVE ---- */

/* Tablet: sidebar collapses to icon-only (56px) */
@media (max-width: 1024px) {
    .aems-sidebar {
        width: 56px;
    }
    .aems-sidebar .aems-nav-label,
    .aems-sidebar .aems-nav-group-label,
    .aems-sidebar .aems-sidebar-ver {
        display: none;
    }
    .aems-sidebar .aems-nav-group-icon {
        display: block;
    }
    /* S207 (D1): at tablet widths the sidebar is visually icon-only but WITHOUT the
       .icon-only class — the base nav-item margin (1px 12px) + padding leaves only
       ~16px of content width, squeezing the 20px icons to 15x20 (skewed) and
       clipping items off-canvas (x=-44). Mirror the .icon-only geometry here so
       icons keep their exact 20x20 size/shape in the auto-collapsed state. */
    .aems-sidebar .aems-nav-item {
        justify-content: center;
        padding: 10px 8px;
        margin: 1px 8px;
    }
    .aems-sidebar .aems-nav-item .aems-icon {
        width: 20px !important;
        height: 20px !important;
        flex-shrink: 0;
        max-width: none;
    }
    .aems-sidebar .aems-nav-group-body {
        overflow: visible;
    }
    .aems-sidebar .aems-sidebar-brand .aems-brand-text {
        display: none;
    }
    /* S207 (D1): the user-card initial must stay a perfect circle when the
       sidebar auto-collapses (media query path has no .icon-only class).
       Without this the 56px width squeezes the flex row: circle -> oval. */
    .aems-sidebar .aems-sidebar-footer > div {
        justify-content: center;
        gap: 0;
        padding: 8px 0;
    }
    .aems-sidebar .aems-sidebar-footer > div > div:first-child {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }
    .aems-sidebar .aems-sidebar-footer > div > div:last-child {
        display: none !important;
    }
    .aems-app-main {
        margin-left: 56px;
    }
}

@media (max-width: 768px) {
    .aems-sidebar {
        transform: translateX(-100%);
        transition: transform var(--duration-300) var(--ease-out);
    }

    .aems-sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
        z-index: var(--z-modal);
    }

    .aems-sidebar-toggle {
        display: flex !important;
    }

    .aems-sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: var(--clr-overlay);
        z-index: var(--z-modal);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--duration-200) var(--ease-out);
    }

    .aems-sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .aems-app-main {
        margin-left: 0;
    }

    .aems-content {
        padding: var(--space-4);
    }

    .aems-topbar-actions {
        gap: var(--space-1);
        flex-shrink: 1;
        overflow: hidden;
    }

    .aems-topbar-brand {
        font-size: var(--text-sm);
        flex-shrink: 0;
    }

    .aems-feature-grid {
        grid-template-columns: 1fr;
        padding: 0 var(--space-4);
    }

    .aems-hero {
        padding: var(--space-10) var(--space-4);
    }

    .aems-hero-title {
        font-size: var(--text-2xl);
    }

    .aems-page-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .aems-toggle-group {
        padding: 2px var(--space-1);
    }

    .aems-lang-pill {
        padding: 3px 8px;
    }

    .aems-modal {
        max-width: 100%;
        border-radius: 0;
        max-height: 100vh;
    }

    .aems-hero-cta {
        width: 100%;
        justify-content: center;
    }

    /* Hide public nav links on very small screens to prevent overflow */
    .aems-public-nav {
        display: none;
    }

    /* Reduce topbar actions on tiny screens */
    .aems-topbar-actions {
        gap: 2px;
    }

    .aems-topbar-actions .aems-lang-switch {
        font-size: 0.78rem;
    }
}

@media (max-width: 400px) {
    /* Ultra-small screens: hide language switcher and secondary button */
    .aems-topbar-actions .aems-lang-switch {
        display: none;
    }

    .landing-nav-actions .btn-cta-secondary {
        display: none;
    }

    .landing-nav-actions {
        gap: 6px;
    }

    .landing-nav-actions button {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
}

/* ---- CRM Page Layout ---- */
.crm-page {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ---- Back to Top ---- */
.back-to-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--clr-accent);
    color: var(--clr-accent-contrast, #FEFEFE);
    border: none;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-drawer);  /* Below toast(500), above sidebar(350) */
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: var(--shadow-md);
}
.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.back-to-top:hover {
    background: var(--clr-accent-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ---- C-019: Visual Design Polish — Gradients, Textures, Animations ---- */

/* Page header gradient accent */
.page-header h1 {
    background: linear-gradient(135deg, var(--clr-text) 0%, var(--clr-text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Ambient page background — subtle radial glow */
.aems-shell-loaded .aems-main {
    background-image: radial-gradient(ellipse at top, rgba(var(--rgb-accent), 0.03) 0%, transparent 50%);
    background-attachment: fixed;
}

/* Card hover lift — fortune-500 tactile depth */
.aems-stat-card, .billing-card, .vault-card, .dep-card, .sub-card, .ref-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.aems-stat-card:hover, .billing-card:hover, .vault-card:hover, .dep-card:hover, .sub-card:hover, .ref-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card-hover);
    border-color: var(--clr-accent-muted);
}

/* Button press feedback */
.aems-btn:active, .btn:active {
    transform: scale(0.97);
    transition: transform 0.08s ease;
}

/* Gradient accent border on focus — inputs */
.form-input:focus, .form-input-sm:focus, select.form-input:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px rgba(var(--rgb-accent), 0.12);
}
.form-input:focus-visible, .form-input-sm:focus-visible, select.form-input:focus-visible {
    outline: 2px solid var(--clr-accent);
    outline-offset: 1px;
}

/* Tab indicator slide animation */
.ch-tab {
    position: relative;
    transition: color 0.15s ease;
}
.ch-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--clr-accent), var(--clr-accent-hover));
    border-radius: 1px;
    animation: aems-slide-up 0.2s ease-out;
}

/* Spinner enhancement — gradient ring */
.spinner {
    border: 3px solid var(--clr-border);
    border-top-color: var(--clr-accent);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    animation: aems-spin 0.7s linear infinite;
}
@keyframes aems-spin {
    to { transform: rotate(360deg); }
}

/* Toast show/hide transition uses .show class (translateX) — do not add conflicting animations */

/* Modal overlay — fixed positioning + backdrop dimming */
.modal-overlay,
.wizard-overlay,
.conn-modal-overlay,
.sec-modal-overlay,
.billing-modal-backdrop,
.li-modal-overlay,
.usage-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--clr-overlay);
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    box-sizing: border-box;
}
.modal-overlay.show,
.wizard-overlay.show,
.conn-modal-overlay.show,
.sec-modal-overlay.show,
.billing-modal-backdrop.active,
.li-modal-overlay.show,
.usage-modal.show {
    display: flex;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.modal-overlay .modal,
.wizard-overlay .wizard,
.conn-modal-overlay .conn-modal,
.sec-modal-overlay .sec-modal,
.modal-overlay .modal-card,
.modal-overlay .mr-rule-modal,
.billing-modal-backdrop .billing-modal,
.bs-confirm-overlay .bs-confirm-modal,
.bs-confirm-overlay .bs-deact-modal,
.li-modal-overlay .li-modal {
    background: linear-gradient(180deg, var(--clr-surface-raised) 0%, var(--clr-surface) 100%);
    border: 1px solid var(--clr-card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 60px var(--clr-accent-glow);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0;
}

/* Premium modal header with accent gradient and icon circle */
.modal-overlay .modal .modal-header,
.conn-modal-overlay .conn-modal .conn-modal-header,
.sec-modal-overlay .sec-modal .sec-modal-header,
.modal-overlay .modal-card .modal-card-header {
    padding: var(--space-5) var(--space-6) var(--space-4);
    margin-bottom: 0;
    border-bottom: 1px solid var(--clr-card-border);
    background: linear-gradient(135deg, var(--clr-accent-muted) 0%, transparent 60%);
    display: flex;
    align-items: center;
}
/* Wizard header has stacked content (title, subtitle, progress dots) — must be column, not row */
.wizard-overlay .wizard .wiz-header {
    padding: var(--space-5) var(--space-6) var(--space-4);
    margin-bottom: 0;
    border-bottom: 1px solid var(--clr-card-border);
    background: linear-gradient(135deg, var(--clr-accent-muted) 0%, transparent 60%);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.modal-overlay .modal .modal-header h2,
.modal-overlay .modal .modal-header h3,
.wizard-overlay .wizard .wiz-header h2,
.wizard-overlay .wizard .wiz-header h3,
.conn-modal-overlay .conn-modal .conn-modal-header h3,
.sec-modal-overlay .sec-modal .sec-modal-header h3,
.modal-overlay .modal-card .modal-card-header h3,
.billing-modal-backdrop .billing-modal h3,
.bs-confirm-overlay .bs-confirm-modal h3,
.bs-confirm-overlay .bs-deact-modal h3,
.li-modal-overlay .li-modal h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    margin: 0;
}
.modal-overlay .modal .modal-header h2 .modal-icon,
.modal-overlay .modal .modal-header h3 .modal-icon,
.modal-overlay .modal .modal-header h2 .dash-modal-icon,
.modal-overlay .modal .modal-header h3 .dash-modal-icon,
.wizard-overlay .wizard .wiz-header .modal-icon,
.conn-modal-overlay .conn-modal .conn-modal-header h3 .modal-icon,
.sec-modal-overlay .sec-modal .sec-modal-header h3 .modal-icon,
.modal-overlay .modal-card .modal-card-header h3 .modal-icon,
.billing-modal-backdrop .billing-modal h3 .modal-icon,
.bs-confirm-overlay .bs-confirm-modal h3 .modal-icon,
.bs-confirm-overlay .bs-deact-modal h3 .modal-icon,
.li-modal-overlay .li-modal h3 .modal-icon {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    background: var(--clr-accent); color: var(--clr-on-accent);
    flex-shrink: 0;
}
.modal-overlay .modal .modal-body,
.wizard-overlay .wizard .wiz-body,
.sec-modal-overlay .sec-modal .sec-modal-body,
.conn-modal-overlay .conn-modal .conn-modal-body,
.modal-overlay .modal-card .modal-card-body {
    padding: var(--space-5) var(--space-6);
}
.modal-overlay .modal .modal-footer,
.sec-modal-overlay .sec-modal .sec-modal-footer,
.conn-modal-overlay .conn-modal .conn-modal-actions,
.wizard-overlay .wizard .wiz-footer,
.modal-overlay .modal-card .modal-card-footer {
    padding: var(--space-4) var(--space-6) var(--space-5);
    margin-top: 0;
    border-top: 1px solid var(--clr-card-border);
    background: var(--clr-surface);
}

/* ============================================================
   SHARED MODAL BODY CONTENT — form fields, inputs, labels
   All modals pull the same form styling from here.
   Set it once here, every modal gets it.
   ============================================================ */

/* Form group spacing inside any modal */
.modal-overlay .modal .modal-body .form-group,
.modal-overlay .modal-card .modal-card-body .form-group,
.conn-modal-overlay .conn-modal .conn-field,
.sec-modal-overlay .sec-modal .sec-modal-body .form-group,
.wizard-overlay .wizard .wiz-body .form-group {
    margin-bottom: 16px;
}

/* Labels inside modals */
.modal-overlay .modal .modal-body label,
.modal-overlay .modal .modal-body .form-label,
.modal-overlay .modal-card .modal-card-body label,
.conn-modal-overlay .conn-modal .conn-field label,
.sec-modal-overlay .sec-modal .sec-modal-body label,
.wizard-overlay .wizard .wiz-body label,
.billing-modal-backdrop .billing-modal label,
.li-modal-overlay .li-modal label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 6px;
    color: var(--clr-text-muted);
    font-weight: var(--weight-medium);
}

/* Inputs inside modals — unified padding, border, radius, focus */
.modal-overlay .modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.modal-overlay .modal select,
.modal-overlay .modal textarea,
.modal-overlay .modal-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.modal-overlay .modal-card select,
.modal-overlay .modal-card textarea,
.conn-modal-overlay .conn-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.conn-modal-overlay .conn-modal select,
.conn-modal-overlay .conn-modal textarea,
.sec-modal-overlay .sec-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.sec-modal-overlay .sec-modal select,
.sec-modal-overlay .sec-modal textarea,
.wizard-overlay .wizard input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.wizard-overlay .wizard select,
.wizard-overlay .wizard textarea,
.billing-modal-backdrop .billing-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.billing-modal-backdrop .billing-modal select,
.li-modal-overlay .li-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--clr-border);
    /* Inputs read as FILLED fields, never as transparent holes: --clr-bg is
       the PAGE background — inside a modal card it renders as a see-through
       window (dark: #0A0E14 hole in #182028 card; light: indistinguishable
       from the card). --clr-surface-input is what every non-modal input uses
       (compat.css .form-input) — dark #101820 / light #FFFFFF. One source,
       every modal inherits (S106). */
    background: var(--clr-surface-input);
    color: var(--clr-text);
    font-size: 0.9rem;
    box-sizing: border-box;
    transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.modal-overlay .modal input:focus,
.modal-overlay .modal select:focus,
.modal-overlay .modal textarea:focus,
.modal-overlay .modal-card input:focus,
.modal-overlay .modal-card select:focus,
.modal-overlay .modal-card textarea:focus,
.conn-modal-overlay .conn-modal input:focus,
.conn-modal-overlay .conn-modal select:focus,
.conn-modal-overlay .conn-modal textarea:focus,
.sec-modal-overlay .sec-modal input:focus,
.sec-modal-overlay .sec-modal select:focus,
.sec-modal-overlay .sec-modal textarea:focus,
.wizard-overlay .wizard input:focus,
.wizard-overlay .wizard select:focus,
.wizard-overlay .wizard textarea:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px var(--clr-accent-muted);
    outline: none;
}

/* Footer button spacing — consistent gap across all modal variants */
.modal-overlay .modal .modal-footer,
.sec-modal-overlay .sec-modal .sec-modal-footer,
.wizard-overlay .wizard .wiz-footer,
.conn-modal-overlay .conn-modal .conn-modal-actions,
.billing-modal-backdrop .billing-modal .billing-modal-actions,
.bs-confirm-overlay .bs-confirm-modal .bs-confirm-actions,
.bs-confirm-overlay .bs-deact-modal .bs-deact-actions,
.li-modal-overlay .li-modal .li-modal-actions,
.modal-overlay .modal-card .modal-card-footer,
.modal-overlay .mr-rule-modal .mr-modal-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
}
.modal-overlay .modal .modal-footer .btn-ghost,
.sec-modal-overlay .sec-modal .sec-modal-footer .btn-ghost,
.wizard-overlay .wizard .wiz-footer .btn-ghost,
.conn-modal-overlay .conn-modal .conn-modal-actions .btn-ghost,
.conn-modal-overlay .conn-modal .conn-modal-actions .conn-btn:not(.conn-btn-primary),
.modal-overlay .modal-card .modal-card-footer .btn-ghost {
    background: none;
    border: none;
    color: var(--clr-text-muted);
    font-size: var(--text-sm);
    cursor: pointer;
}
.modal-overlay .modal .modal-footer .btn-ghost:hover,
.sec-modal-overlay .sec-modal .sec-modal-footer .btn-ghost:hover,
.wizard-overlay .wizard .wiz-footer .btn-ghost:hover,
.conn-modal-overlay .conn-modal .conn-modal-actions .btn-ghost:hover,
.modal-overlay .modal-card .modal-card-footer .btn-ghost:hover {
    background: var(--clr-surface-hover);
    color: var(--clr-text);
}
.modal {
    animation: aems-fade-in 0.15s ease-out;
}
.modal-content {
    animation: aems-scale-in 0.18s ease-out;
}

/* Textured fill — subtle dot pattern for card container backgrounds only */
.aems-section-card,
.aems-stat-card,
.aems-office-card,
.billing-card,
.vault-card,
.dep-card,
.sub-card,
.ref-card,
.ch-section,
.ch-summary-card,
.conn-section,
.conn-card,
.hire-card,
.section-card,
.dash-modal,
.modal-card,
.modal-overlay .modal,
.wizard-overlay .wizard,
.conn-modal-overlay .conn-modal,
.sec-modal-overlay .sec-modal,
.bs-confirm-overlay .bs-confirm-modal,
.bs-confirm-overlay .bs-deact-modal,
.billing-modal-backdrop .billing-modal,
.li-modal-overlay .li-modal,
.modal-overlay .mr-rule-modal,
.ch-spending-card,
.ch-notif-item,
.ch-app-card,

.emp-card,
.ae-card,
.stat-card,
.bs-card,
.ch-emp-card,
.rpt-builder-card {
    background-image: radial-gradient(circle, var(--clr-border) 1.5px, transparent 1.5px) !important;
    background-size: 24px 24px !important;
    background-position: 0 0 !important;
    background-origin: padding-box !important;
}

/* Link hover — underline grow animation */
.aems-link {
    position: relative;
    text-decoration: none;
}
.aems-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--clr-accent);
    transition: width 0.2s ease;
}
.aems-link:hover::after {
    width: 100%;
}

/* ---- A-008: Superadmin View-As-Client Toggle ---- */
body[data-view-as="client"] [data-superadmin-only] {
    display: none !important;
}
body[data-view-as="client"] .aems-sidebar-group[data-role="superadmin"] {
    display: none !important;
}
#view-as-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: var(--z-toast);
    background: var(--clr-accent);
    color: var(--clr-accent-contrast);
    text-align: center;
    padding: 6px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    animation: aems-slide-down 0.2s ease-out;
}
#superadmin-view-toggle {
    transition: color var(--duration-75) var(--ease-out), background var(--duration-75) var(--ease-out), box-shadow var(--duration-75) var(--ease-out);
}
#superadmin-view-toggle:hover {
    background: var(--clr-accent) !important;
    color: var(--clr-accent-contrast) !important;
}

/* ── Breadcrumbs (FIX-038) ── */
.aems-breadcrumb {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    padding: 0;
    margin: 0 0 var(--space-4) 0;
    font-size: var(--text-sm);
}
.aems-breadcrumb li {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}
.aems-breadcrumb li:not(:last-child)::after {
    content: '/';
    color: var(--clr-text-faint);
    margin-left: var(--space-1);
}
.aems-breadcrumb a {
    color: var(--clr-text-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}
.aems-breadcrumb a:hover {
    color: var(--clr-accent);
}
.aems-breadcrumb [aria-current="page"] {
    color: var(--clr-text);
    font-weight: var(--weight-semibold);
}

/* ── Empty States (FIX-033) ── */
.aems-empty-state {
    text-align: center;
    padding: 48px 24px;
}
.aems-empty-state .aems-empty-icon {
    opacity: 0.4;
    margin-bottom: 16px;
}
.aems-empty-state .aems-empty-message {
    color: var(--clr-text-muted);
    font-size: var(--text-sm);
    margin: 0 0 8px;
}

/* ── Password Toggle (FIX-040) ── */
.aems-pw-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--clr-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.aems-pw-toggle:hover {
    color: var(--clr-text);
}
.aems-pw-field-wrapper {
    position: relative;
}
.aems-pw-field-wrapper .form-input {
    padding-right: 36px;
}

/* ── Caps Lock Warning (FIX-042) ── */
.aems-capslock-warning {
    display: none;
    font-size: var(--text-xs);
    color: var(--clr-warning);
    margin-top: var(--space-1);
    align-items: center;
    gap: 4px;
}
.aems-capslock-warning.show {
    display: flex;
}

/* ── 2FA Field (FIX-041) ── */
.aems-totp-field {
    display: none;
}
.aems-totp-field.show {
    display: block;
}
.aems-totp-field input {
    letter-spacing: 0.5em;
    text-align: center;
    font-size: 1.25rem;
    font-weight: var(--weight-bold);
}

/* ── Accessible Tabs (FIX-039) ── */
[role="tablist"] {
    display: flex;
    gap: var(--space-2);
}
[role="tab"] {
    cursor: pointer;
}
[role="tab"][aria-selected="true"] {
    font-weight: var(--weight-semibold);
}

/* ── Touch device hover guards (FIX-060) ── */
/* On touch devices, hover states get stuck after tap. Reset them. */
@media (hover: none) {
    .aems-stat-card:hover,
    .aems-section-card:hover,
    .aems-nav-item:hover,
    .aems-public-nav a:hover,
    .aems-lang-pill:hover,
    .theme-toggle-btn:hover,
    .aems-btn:hover,
    .btn:hover,
    .btn-primary:hover,
    a:hover {
        /* Reset to non-hover state on touch devices */
        transform: none;
        background: inherit;
        color: inherit;
        border-color: inherit;
        box-shadow: inherit;
        opacity: inherit;
    }
    /* Use :active for tap feedback instead */
    .aems-stat-card:active,
    .aems-section-card:active,
    .aems-nav-item:active,
    .aems-btn:active,
    .btn:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
}

/* ── Focus indicators (FIX-072) ── */
*:focus-visible {
    outline: 2px solid var(--clr-accent);
    outline-offset: 2px;
}
/* Icon-only buttons need a more visible ring */
button:not([class*="btn"]):focus-visible,
[role="tab"]:focus-visible,
.aems-icon-btn:focus-visible {
    outline: 3px solid var(--clr-accent);
    outline-offset: 1px;
}

/* ── Reduced motion (FIX-073) ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Responsive table card view (FIX-079) ── */
@media (max-width: 600px) {
    .aems-table-wrap table,
    .aems-data-table table {
        display: block;
    }
    .aems-table-wrap thead,
    .aems-data-table thead {
        display: none;
    }
    .aems-table-wrap tbody,
    .aems-data-table tbody {
        display: block;
    }
    .aems-table-wrap tr,
    .aems-data-table tr {
        display: block;
        padding: 12px;
        border: 1px solid var(--clr-border);
        border-radius: var(--radius-md);
        margin-bottom: 8px;
    }
    .aems-table-wrap td,
    .aems-data-table td {
        display: flex;
        justify-content: space-between;
        padding: 4px 0;
        border: none;
        text-align: right;
    }
    .aems-table-wrap td::before,
    .aems-data-table td::before {
        content: attr(data-label);
        font-weight: var(--weight-semibold);
        color: var(--clr-text-muted);
        text-align: left;
        padding-right: 12px;
    }
}

/* ---- Visual depth: gradient borders + mesh background utilities ---- */
.aems-gradient-border {
    position: relative;
    border: 1px solid transparent;
    background-clip: padding-box;
}
.aems-gradient-border::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, var(--clr-accent-tertiary), transparent 50%, var(--clr-accent, var(--clr-accent-tertiary)) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.4;
    transition: opacity var(--duration-200) var(--ease-out);
}
.aems-gradient-border:hover::before { opacity: 0.8; }

.aems-mesh-bg {
    background-image:
        radial-gradient(at 20% 20%, var(--clr-accent-glow, rgba(20,184,137,0.06)) 0px, transparent 50%),
        radial-gradient(at 80% 80%, var(--clr-accent-glow, rgba(20,184,137,0.04)) 0px, transparent 50%);
}

/* ═══════════════════════════════════════════════════════════════════════════
   S201: SHARED TAB VISUAL STYLE — extracted from reports.html .rpt-tabs
   Apply .aems-tabs to any in-page tab bar to get the unified compact style.
   Active tab: accent color + 2px accent underline merged into border + surface bg.
   Compact height (<80px). Each page keeps its own tab-switching JS logic.
   ═══════════════════════════════════════════════════════════════════════════ */
.aems-tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--clr-border); margin-bottom: var(--space-6); flex-wrap: wrap; }
.aems-tab { display: inline-flex; flex-direction: column; gap: 1px; padding: 7px 10px 8px; font-size: var(--text-sm); color: var(--clr-text-muted); cursor: pointer; border: 1px solid transparent; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color var(--duration-100), border-color var(--duration-100), background-color var(--duration-100); border-radius: var(--radius-md) var(--radius-md) 0 0; background: transparent; text-decoration: none; white-space: nowrap; align-items: flex-start; }
.aems-tab:hover { color: var(--clr-text); background: var(--clr-surface-hover); }
.aems-tab.active { color: var(--clr-accent); border-bottom-color: var(--clr-accent); background: var(--clr-surface); font-weight: var(--weight-semibold); }
.aems-tab-label { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.aems-tab-desc { font-size: 0.78rem; color: var(--clr-text-faint); font-weight: 400; letter-spacing: 0; text-transform: none; }
.aems-tab.active .aems-tab-desc { color: var(--clr-text-muted); }
.aems-tab:focus-visible { outline: 2px solid var(--clr-accent); outline-offset: -2px; }
@media (max-width: 768px) { .aems-tabs { flex-wrap: wrap; } }
