/* ============================================
   CSS Cascade Layer Order
   Establishes explicit cascade priority:
   base < components < animations < pages
   ============================================ */
@layer base, components, animations, pages;

/* ============================================
   CAD Modeling Challenge — Core Styles
   ============================================ */

/* --- CSS Custom Properties (Dark Theme Default) --- */
/* Custom properties are unlayered so they're available to all layers */
:root,
[data-theme="dark"] {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2234;
    --bg-card-hover: #1f2b42;

    --surface-1: #1e293b;
    --surface-2: #2a3548;
    --surface-3: #374357;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #7b8ba3; /* WCAG AA 5.57:1 on --bg-primary */

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.25);

    --color-success: #22c55e;
    --color-success-glow: rgba(34, 197, 94, 0.25);
    --color-warning: #f59e0b;
    --color-warning-glow: rgba(245, 158, 11, 0.25);
    --color-danger: #ef4444;
    --color-danger-glow: rgba(239, 68, 68, 0.25);

    --border-color: #2a3548;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    /* Alias used in components.css */
    --radius-sm: 8px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* Spacing Scale (4px grid) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* Typography Scale */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;

    /* Border Radius Scale */
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Shadow System */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);

    /* Color Opacity Scale — Accent (Blue) */
    --accent-bg-subtle: rgba(59, 130, 246, 0.06);
    --accent-bg: rgba(59, 130, 246, 0.08);
    --accent-bg-medium: rgba(59, 130, 246, 0.1);
    --accent-bg-strong: rgba(59, 130, 246, 0.12);
    --accent-border: rgba(59, 130, 246, 0.15);
    --accent-border-medium: rgba(59, 130, 246, 0.2);
    --accent-border-strong: rgba(59, 130, 246, 0.3);

    /* Color Opacity Scale — Success (Green) */
    --success-bg: rgba(34, 197, 94, 0.1);
    --success-border: rgba(34, 197, 94, 0.2);

    /* Color Opacity Scale — Warning (Amber) */
    --warning-bg: rgba(245, 158, 11, 0.12);
    --warning-border: rgba(245, 158, 11, 0.25);

    /* Color Opacity Scale — Danger (Red) */
    --danger-bg: rgba(239, 68, 68, 0.08);

    /* Overlay Colors */
    --overlay-dark: rgba(0, 0, 0, 0.6);
    --overlay-darker: rgba(0, 0, 0, 0.7);
    --overlay-light: rgba(255, 255, 255, 0.1);
    --overlay-light-border: rgba(255, 255, 255, 0.15);
    --overlay-light-text: rgba(255, 255, 255, 0.6);

    /* Achievement tier colors */
    --tier-common: #9ca3af;
    --tier-uncommon: #22c55e;
    --tier-rare: #3b82f6;
    --tier-epic: #a855f7;
    --tier-legendary: #f59e0b;

    /* Z-Index Scale */
    --z-base: 0;
    --z-raised: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 1000;
    --z-modal: 9000;
    --z-modal-content: 9001;
    --z-toast: 9500;
    --z-toast-content: 9501;
    --z-toast-dismiss: 9600;
    --z-devpanel: 9900;
    --z-notification: 9999;
    --z-top: 10000;
}

/* ============================================
   Responsive Breakpoint Scale
   CSS custom properties cannot be used in @media queries.
   Use these standardized values consistently:

   --bp-mobile-sm:   480px   (small mobile)
   --bp-mobile-lg:   640px   (large mobile / small tablet)
   --bp-tablet:      768px   (tablet portrait)
   --bp-desktop-sm: 1024px   (tablet landscape / small desktop)
   ============================================ */

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;

    --surface-1: #f1f5f9;
    --surface-2: #e2e8f0;
    --surface-3: #cbd5e1;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b; /* WCAG AA 4.55:1 on --bg-primary */

    --border-color: #e2e8f0;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05), 0 0 1px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 16px rgba(59, 130, 246, 0.15);

    /* Slightly subtler accent glow in light theme */
    --accent-glow: rgba(59, 130, 246, 0.15);

    /* Light theme color overrides */
    --accent-bg-subtle: rgba(59, 130, 246, 0.04);
    --accent-bg: rgba(59, 130, 246, 0.06);
    --accent-bg-medium: rgba(59, 130, 246, 0.08);
    --accent-bg-strong: rgba(59, 130, 246, 0.1);
    --accent-border: rgba(59, 130, 246, 0.12);
    --accent-border-medium: rgba(59, 130, 246, 0.15);
    --accent-border-strong: rgba(59, 130, 246, 0.25);
    --success-bg: rgba(34, 197, 94, 0.08);
    --success-border: rgba(34, 197, 94, 0.15);
    --warning-bg: rgba(245, 158, 11, 0.1);
    --warning-border: rgba(245, 158, 11, 0.2);
    --danger-bg: rgba(239, 68, 68, 0.06);
    --overlay-dark: rgba(0, 0, 0, 0.4);
    --overlay-darker: rgba(0, 0, 0, 0.5);
    --overlay-light: rgba(0, 0, 0, 0.04);
    --overlay-light-border: rgba(0, 0, 0, 0.08);
    --overlay-light-text: rgba(0, 0, 0, 0.5);
}

@layer base {

/* Light theme: add subtle border on cards for definition */
[data-theme="light"] .widget-block,
[data-theme="light"] .card-inner {
    border-color: var(--border-color);
}

/* Light theme: enhanced depth for stat items */
[data-theme="light"] .stat-item {
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* Light theme: enhance header surface */
[data-theme="light"] .app-header {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Light theme: toast refinements */
[data-theme="light"] .toast {
    box-shadow: var(--shadow-md);
    border-color: var(--border-color);
}

/* Light theme: modal backdrop — slightly less dark */
[data-theme="light"] .modal-backdrop,
[data-theme="light"] .delete-modal-backdrop {
    background: rgba(0, 0, 0, 0.4);
}

/* Light theme: modal dialog surface */
[data-theme="light"] .modal-dialog,
[data-theme="light"] .delete-modal-dialog {
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* Light theme: hero glow — more subtle */
[data-theme="light"] .hero-section::after {
    opacity: 0.25;
}

/* ============================================
   Breadcrumb Navigation
   ============================================ */

.breadcrumb {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-3) var(--space-6);
}

.breadcrumb-inner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
}

.breadcrumb-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
    font-weight: 500;
}

.breadcrumb-link:hover {
    color: var(--accent);
}

.breadcrumb-link svg {
    opacity: 0.7;
}

.breadcrumb-sep {
    color: var(--text-muted);
    opacity: 0.4;
    display: flex;
    align-items: center;
}

.breadcrumb-current {
    color: var(--text-secondary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

/* Light theme: breadcrumb surface */
[data-theme="light"] .breadcrumb {
    border-bottom: 1px solid var(--border-color);
}

/* Light theme: focus mode overlay */
[data-theme="light"] .focus-overlay {
    background: rgba(255, 255, 255, 0.95);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* --- Top Loading Bar (NProgress-style) --- */
#loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: var(--z-top);
    pointer-events: none;
    background: var(--accent);
    transform: translate3d(-100%, 0, 0);
    transition: none;
    opacity: 0;
}

#loading-bar.loading-bar-active {
    opacity: 1;
}

#loading-bar.loading-bar-done {
    opacity: 0;
    transition: opacity 300ms ease 100ms;
}

.loading-bar-peg {
    position: absolute;
    right: 0;
    top: 0;
    width: 100px;
    height: 100%;
    box-shadow: 0 0 10px var(--accent), 0 0 5px var(--accent);
    opacity: 0.8;
    border-radius: 0 0 0 100%;
}

@media (prefers-reduced-motion: reduce) {
    #loading-bar,
    #loading-bar.loading-bar-done {
        transition: none;
    }
    .loading-bar-peg {
        box-shadow: none;
    }
}

/* --- Offline Indicator --- */
.offline-indicator {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: var(--z-notification);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-warning);
    color: #0f172a;
    font-size: var(--text-sm);
    font-weight: 600;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: opacity 300ms ease, transform 300ms ease;
    pointer-events: none;
}

.offline-indicator-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.offline-indicator svg {
    flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
    .offline-indicator {
        transition: opacity 0s;
        transform: translateX(-50%);
    }
}

/* Custom text selection */
::selection {
    background: rgba(59, 130, 246, 0.25);
    color: var(--text-primary);
}

/* Custom scrollbar (webkit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 4px;
    border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) var(--bg-primary);
}

/* --- Utility Classes --- */
.hidden {
    display: none !important;
}

/* Skip to content link for keyboard/screen-reader accessibility */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    z-index: var(--z-overlay);
    padding: var(--space-2) var(--space-4);
    background: var(--accent);
    color: white;
    font-size: var(--text-sm);
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-2);
}

/* Focus visible styles for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Buttons get a glow ring on focus for better visibility */
.btn:focus-visible,
.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* Form inputs get accent border + ring */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: var(--z-dropdown);
    backdrop-filter: blur(12px);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.1rem;
    flex: 1;
}

.brand-icon {
    display: inline-flex;
    align-items: center;
    width: 24px;
    height: 24px;
}

.brand-icon svg {
    width: 100%;
    height: 100%;
}

.brand-text {
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
}

.user-greeting {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.user-greeting-link {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-decoration: none;
    transition: color var(--transition-fast);
}

.user-greeting-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* --- Avatar Dropdown --- */
.avatar-dropdown-container {
    position: relative;
}

.avatar-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.avatar-trigger:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.avatar-circle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-sans);
    letter-spacing: 0.02em;
    user-select: none;
    line-height: 1;
    box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.15);
}

.avatar-circle-lg {
    width: 40px;
    height: 40px;
    font-size: 15px;
}

.avatar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-sticky);
    padding: var(--space-2);
    animation: dropdown-enter 0.15s ease-out;
}

.avatar-dropdown.open {
    display: block;
}

@keyframes dropdown-enter {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.avatar-dropdown-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    margin-bottom: var(--space-1);
}

.avatar-dropdown-user {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.avatar-dropdown-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar-dropdown-email {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.avatar-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.avatar-dropdown-item:hover {
    background: var(--surface-1);
    color: var(--text-primary);
}

.avatar-dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.avatar-dropdown-item:hover svg {
    opacity: 1;
}

.avatar-dropdown-danger {
    color: var(--color-danger);
}

.avatar-dropdown-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--color-danger);
}

.avatar-dropdown-danger svg {
    color: var(--color-danger);
}

.avatar-dropdown-bridge {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.bridge-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.bridge-status-dot.connected {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success-glow);
}

.bridge-status-dot.partial {
    background: var(--color-warning);
    box-shadow: 0 0 6px var(--color-warning-glow);
}

.bridge-status-dot.disconnected {
    background: var(--color-danger);
}

.bridge-status-label {
    font-weight: 500;
}

/* --- Navigation --- */
.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.nav-link {
    padding: 6px var(--space-4);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--surface-1);
}

.nav-link.nav-active {
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
    font-weight: 600;
}

/* --- Mobile Navigation --- */
.hamburger-btn {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
    flex-shrink: 0;
}

.hamburger-btn:hover {
    background: var(--surface-1);
    color: var(--text-primary);
}

.hamburger-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mobile-nav-panel {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-4) var(--space-6);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    gap: var(--space-3);
    animation: mobile-nav-slide-down 250ms ease;
}

.mobile-nav-panel.mobile-nav-open {
    display: flex;
}

.mobile-nav-panel .nav-link {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    border-radius: var(--radius-sm);
}

.mobile-nav-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-1) 0;
}

.mobile-nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1) 0;
}

.mobile-nav-actions .user-greeting {
    font-size: var(--text-sm);
}

@keyframes mobile-nav-slide-down {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .hamburger-btn {
        display: flex;
    }

    .header-nav,
    .header-actions {
        display: none;
    }

    .app-header {
        padding: 0 var(--space-4);
    }

    /* Keep status indicator visible on mobile header */
    #status-indicator {
        margin-left: auto;
        margin-right: var(--space-2);
    }
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-sans);
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 0 0 var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: var(--shadow-glow);
}

.btn-accent {
    background: var(--color-success);
    color: white;
}

.btn-accent:hover:not(:disabled) {
    box-shadow: 0 0 20px var(--color-success-glow);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-1);
    color: var(--text-primary);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* --- Global Button Loading Spinner ---
   Apply .btn-loading to any button to show a spinner overlay.
   Works with .btn, .btn-primary, .btn-ghost, .btn-accent, etc.
   Text becomes transparent; spinner is centered via ::after pseudo-element. */
.btn-loading,
.btn.loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}

.btn-loading::after,
.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}

/* Ghost/outline button spinner uses darker colors */
.btn-ghost.btn-loading::after,
.btn-ghost.loading::after {
    border-color: rgba(0, 0, 0, 0.15);
    border-top-color: var(--text-secondary);
}

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

/* Button icon helper (consistent SVG inside buttons) */
.btn-icon {
    flex-shrink: 0;
    vertical-align: middle;
}

/* --- Dashboard Layout --- */
.dashboard-layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.dashboard-layout > section {
    margin-bottom: var(--space-12);
}

.dashboard-layout > section:last-child {
    margin-bottom: 0;
}

.hero-section {
    text-align: center;
    padding: var(--space-16) 0 var(--space-12);
    position: relative;
    overflow: hidden;
}

/* Decorative background pattern for hero */
.hero-section::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 1px 1px, var(--surface-2) 1px, transparent 0);
    background-size: 40px 40px;
    opacity: 0.4;
    pointer-events: none;
    mask-image: radial-gradient(ellipse 60% 80% at 50% 40%, black 20%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse 60% 80% at 50% 40%, black 20%, transparent 70%);
}

/* Ambient glow behind the hero title */
.hero-section::after {
    content: '';
    position: absolute;
    top: 30%;
    left: 50%;
    width: 400px;
    height: 200px;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse, var(--accent-glow) 0%, transparent 70%);
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: var(--radius-full);
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--accent);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: var(--space-4);
    position: relative;
    z-index: var(--z-raised);
}

.hero-title {
    font-size: var(--text-4xl);
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    z-index: var(--z-raised);
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: var(--text-lg);
    margin-top: var(--space-3);
    position: relative;
    z-index: var(--z-raised);
}

.hero-actions {
    margin-top: var(--space-6);
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    position: relative;
    z-index: var(--z-raised);
}

/* --- Stats Bar --- */
.stats-bar {
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    padding: var(--space-5) 0;
    margin-bottom: var(--space-8);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-8);
    background: var(--bg-card);
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xs);
    transition: all var(--transition-normal);
}

.stat-item:hover {
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.stat-value {
    font-size: var(--text-xl);
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mini-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.mini-dot.connected { background: var(--color-success); box-shadow: 0 0 8px var(--color-success-glow); }
.mini-dot.disconnected { background: var(--color-danger); }

/* --- Challenge Grid --- */
.challenge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    /* Performance: contain layout paint for cards */
    contain: layout style;
}

.grid-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* --- Footer --- */
.app-footer {
    text-align: left;
    padding: var(--space-12) var(--space-6) var(--space-6);
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-top: var(--space-12);
    position: relative;
    background: var(--bg-secondary);
}

/* Gradient top edge instead of a hard border */
.app-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--border-color) 20%, var(--accent) 50%, var(--border-color) 80%, transparent 100%);
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: var(--space-8);
    max-width: 1100px;
    margin: 0 auto var(--space-8);
}

.footer-brand-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.footer-brand-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: var(--text-base);
}

.footer-brand-link:hover {
    color: var(--accent);
}

.footer-brand-icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
}

.footer-brand-desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 300px;
}

.footer-domain {
    margin-top: var(--space-2);
}

.footer-domain-link {
    font-size: var(--text-sm);
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.footer-domain-link:hover {
    text-decoration: underline;
}

.footer-links-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.footer-col-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.footer-link-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.footer-link-list a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--text-sm);
    transition: color var(--transition-fast);
}

.footer-link-list a:hover {
    color: var(--accent);
}

.footer-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1100px;
    margin: 0 auto;
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.footer-copyright {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.footer-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-link:hover {
    color: var(--accent);
}

.footer-heart {
    color: var(--color-danger);
    display: inline-block;
    animation: none;
}

.footer-version {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    opacity: 0.6;
}

@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-6);
    }

    .footer-brand-col {
        grid-column: span 2;
    }
}

@media (max-width: 480px) {
    .footer-grid {
        grid-template-columns: 1fr;
    }

    .footer-brand-col {
        grid-column: auto;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }
}

/* --- Shared Form Elements --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:hover:not(:focus) {
    border-color: var(--surface-3);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--surface-2);
}

.form-input:invalid:not(:placeholder-shown) {
    border-color: var(--color-danger);
}

.form-textarea {
    resize: vertical;
    min-height: 64px;
    max-height: 160px;
    line-height: 1.5;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.form-feedback {
    font-size: 0.85rem;
    transition: opacity var(--transition-fast);
}

.feedback-success { color: var(--color-success); }
.feedback-error   { color: var(--color-danger); }

} /* end @layer base */
