:root {
    /* Primary Colors - aligned with banner */
    --primary-blue: #1a365d;
    --primary-dark: #0f2744;
    --primary-light: #2d4a6f;
    --primary-hover: #243c5a;
    --accent-cyan: #319795;
    --accent-purple: #8B5CF6;

    /* Semantic Colors */
    --success-green: #22c55e;
    --success-light: #D1FAE5;
    --success-dark: #16a34a;
    --warning-orange: #F59E0B;
    --warning-light: #FEF3C7;
    --warning-dark: #D97706;
    --error-red: #EF4444;
    --error-light: #FEE2E2;
    --error-dark: #DC2626;
    --info-blue: #319795;
    --info-light: #ccfbf1;

    /* Text Colors */
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --text-tertiary: #94a3b8;
    --text-muted: #94a3b8;
    --text-inverse: #f1f5f9;

    /* Background Colors */
    --bg-white: #FFFFFF;
    --bg-light: #F9FAFB;
    --bg-gray: #F3F4F6;
    --bg-hover: #F0F4F8;
    --bg-active: #e6fffa;

    /* Border Colors */
    --border-light: #E5E7EB;
    --border-medium: #D1D5DB;
    --border-focus: var(--accent-cyan);

    /* Shadow System */
    --shadow-xs: 0 1px 2px 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 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 20px rgba(49, 151, 149, 0.3);
    --shadow-focus: 0 0 0 3px rgba(49, 151, 149, 0.25);
    --shadow-card-hover: 0 8px 24px -4px rgba(49, 151, 149, 0.15), 0 4px 8px -2px rgba(0, 0, 0, 0.08);

    /* Border Radius */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-spring: 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Glass Effect */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-blur: blur(12px);
}

/* Core Keyframe Animations - defined early for availability */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Reduced motion for accessibility */
@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;
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Better text rendering */
body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus visible for keyboard navigation */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

/* Skip to content link for accessibility (WCAG 2.1 AA) */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-cyan);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    text-decoration: none;
    z-index: 10000;
    transition: top var(--transition-fast);
}

.skip-to-content:focus {
    top: 16px;
    outline: 3px solid var(--success-green);
    outline-offset: 2px;
}

/* Utility class for initially hidden elements */
.hidden {
    display: none !important;
}

/* Landing page specific styles */
.landing-header {
    padding: 0;
    background: transparent;
    position: relative;
}

.landing-banner {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    object-position: center;
    display: block;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(26, 54, 93, 0.2);
    margin-bottom: 8px;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-dark) 50%, #002855 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding: 0 0 0 var(--side-nav-width);
    margin: 0;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
}

/* Subtle background pattern overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(255, 255, 255, 0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 1694px;
    margin: 0;
    background: var(--bg-white);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    min-height: 100vh;
    padding: 0 20px;
}

@keyframes containerFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.container:hover {
    box-shadow: var(--shadow-2xl);
}

header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 36px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    border-radius: 12px;
    margin: 36px;
}

header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.env-indicator {
    position: absolute;
    top: 16px;
    right: 20px;
    padding: 6px 12px;
    background: rgba(245, 158, 11, 0.95);
    color: white;
    border-radius: 6px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
    animation: fadeIn 0.3s ease-in;
}

.env-indicator.local {
    background: rgba(139, 92, 246, 0.95);
}

.version-badge {
    position: fixed;
    bottom: 16px;
    right: 20px;
    padding: 6px 10px;
    background: rgba(31, 41, 55, 0.85);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    font-size: 0.65em;
    font-weight: 500;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0.6;
    transition: opacity 0.2s ease, background 0.2s ease;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    cursor: default;
}

.version-badge:hover {
    opacity: 1;
    background: rgba(31, 41, 55, 0.95);
}

.version-badge .version-number {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

.version-badge .version-commit {
    color: rgba(100, 200, 255, 0.8);
    margin-left: 4px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    font-size: 2.75em;
    margin-bottom: 12px;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.subtitle {
    opacity: 0.95;
    font-size: 1.15em;
    font-weight: 400;
    letter-spacing: -0.01em;
}

.content {
    padding: 36px 48px 48px;
    background: var(--bg-white);
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.toolbar-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ============================================
   Side Navigation
   ============================================ */
:root {
    --side-nav-width: 220px;
}

.side-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--side-nav-width);
    height: 100vh;
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid rgba(229, 231, 235, 0.8);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 4px 0 24px -8px rgba(0, 0, 0, 0.08);
}

.nav-top {
    display: flex;
    align-items: center;
    padding: 16px 12px;
    border-bottom: 1px solid var(--border-light);
    min-height: 60px;
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(49, 151, 149, 0.04) 0%, transparent 100%);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    transition: all var(--transition-fast);
}

.nav-brand:hover {
    color: var(--accent-cyan);
    transform: translateX(2px);
}

.nav-brand-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    transition: transform var(--transition-bounce);
}

.nav-brand:hover .nav-brand-icon {
    transform: rotate(-5deg) scale(1.1);
}

.nav-links {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 6px;
    padding-top: 50px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.nav-link::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(49, 151, 149, 0.1) 0%, rgba(34, 197, 94, 0.05) 100%);
    opacity: 0;
    transition: opacity var(--transition-fast);
    border-radius: inherit;
    pointer-events: none;
}

.nav-link:hover {
    color: var(--accent-cyan);
    transform: translateX(3px);
}

.nav-link:hover::after {
    opacity: 1;
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(49, 151, 149, 0.15) 0%, rgba(34, 197, 94, 0.08) 100%);
    color: var(--accent-cyan);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(49, 151, 149, 0.15);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: linear-gradient(180deg, var(--accent-cyan), var(--success-green));
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(49, 151, 149, 0.4);
}

.nav-link-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    transition: transform var(--transition-fast);
}

.nav-link:hover .nav-link-icon {
    transform: scale(1.1);
}

.nav-link-label {}

/* Navigation section labels */
.nav-section-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    padding: 10px 12px 4px;
    margin-top: 2px;
}

.nav-section-label:first-child {
    margin-top: 0;
}

/* Indented nav links (sub-items) */
.nav-link-indent {
    padding-left: 28px;
    font-size: 0.8125rem;
}

.nav-link-indent .nav-link-icon {
    font-size: 1rem;
    width: 20px;
}

.nav-bottom {
    padding: 12px;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    margin-top: auto;
}

.nav-user {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-user.hidden {
    display: none;
}

.nav-user-name {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
}

.nav-logout-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    width: 100%;
}

.nav-logout-btn:hover {
    background: var(--error-light);
    border-color: var(--error-red);
    color: var(--error-red);
}

.logout-icon {
    font-size: 1.1rem;
}

/* Responsive: Mobile - slide out nav */
@media (max-width: 768px) {
    .side-nav {
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
        width: 220px;
    }

    .side-nav.open {
        transform: translateX(0);
    }

    body {
        padding-left: 0 !important;
    }

    .nav-links {
        padding: 6px 4px;
        padding-top: 40px;
        gap: 1px;
    }

    .nav-link {
        padding: 10px 12px;
        gap: 8px;
        font-size: 0.9rem;
    }

    .nav-section-label {
        padding: 12px 12px 4px;
    }

    .mobile-nav-toggle {
        display: flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 99;
        background: var(--bg-white);
        border: 1px solid var(--border-light);
        border-radius: var(--radius-sm);
        padding: 8px 12px;
        font-size: 1.25rem;
        cursor: pointer;
        box-shadow: var(--shadow-sm);
    }

    .side-nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }

    .side-nav-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {

    .mobile-nav-toggle,
    .side-nav-overlay {
        display: none !important;
    }
}

/* Tablet: Narrower sidebar */
@media (min-width: 769px) and (max-width: 1024px) {
    .side-nav {
        width: 200px;
    }

    body {
        padding-left: 200px;
    }

    .nav-link {
        padding: 7px 10px;
        font-size: 0.8125rem;
        gap: 8px;
    }

    .nav-link-icon {
        font-size: 1.1rem;
        width: 20px;
    }

    .nav-section-label {
        font-size: 0.625rem;
        padding: 8px 10px 3px;
    }
}

/* Legacy .main-nav for backwards compatibility during transition */
.main-nav {
    display: none;
}

.btn-icon {
    font-size: 1.1em;
    line-height: 1;
}

.refresh-btn.secondary {
    background: var(--bg-white);
    color: var(--text-primary);
    border: 2px solid var(--border-medium);
    box-shadow: var(--shadow-xs);
}

.refresh-btn.secondary:hover {
    background: var(--bg-light);
    border-color: var(--primary-blue);
    color: var(--primary-blue);
    box-shadow: var(--shadow-sm);
}

.refresh-btn.secondary:active {
    background: var(--bg-gray);
    box-shadow: var(--shadow-inner);
}

.loading {
    text-align: center;
    padding: 60px 40px;
    color: #333;
}

.loading .spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.loading .message {
    font-size: 1.125em;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.loading .submessage {
    font-size: 0.9375em;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 400px;
    margin: 0 auto;
}

.error {
    background: linear-gradient(135deg, var(--error-light) 0%, #FEF2F2 100%);
    border: 2px solid var(--error-red);
    border-left-width: 6px;
    color: #991B1B;
    padding: 20px 24px;
    border-radius: var(--radius-md);
    margin: 24px 0;
    box-shadow: var(--shadow-sm);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
}

.error::before {
    content: '⚠️';
    font-size: 1.5em;
}

.tree {
    margin: 20px 0;
}

.tree-node {
    margin: 10px 0;
    padding: 16px 20px;
    border-left: 4px solid var(--primary-blue);
    background: var(--bg-white);
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border-light);
    border-left-width: 4px;
    position: relative;
}

.tree-node::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
    box-shadow: var(--shadow-glow);
}

.tree-node:hover {
    background: var(--bg-light);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-blue);
}

.tree-node:hover::after {
    opacity: 0.3;
}

.tree-node.category {
    background: linear-gradient(135deg, rgba(0, 120, 212, 0.08) 0%, rgba(0, 69, 120, 0.08) 100%);
    border-left: 5px solid var(--primary-blue);
    font-weight: 600;
    font-size: 1.25em;
    box-shadow: var(--shadow-md);
}

.tree-node.category:hover {
    background: linear-gradient(135deg, rgba(0, 120, 212, 0.12) 0%, rgba(0, 69, 120, 0.12) 100%);
}

.tree-node.directory {
    border-left-color: var(--warning-orange);
}

.tree-node.directory:hover {
    border-color: var(--warning-orange);
    box-shadow: var(--shadow-md), 0 0 0 1px var(--warning-orange);
}

.tree-node.survey {
    border-left-color: var(--success-green);
}

.tree-node.survey:hover {
    border-color: var(--success-green);
    box-shadow: var(--shadow-md), 0 0 0 1px var(--success-green);
}

.tree-node.library {
    border-left-color: var(--accent-cyan);
}

.tree-node.library:hover {
    border-color: var(--accent-cyan);
    box-shadow: var(--shadow-md), 0 0 0 1px var(--accent-cyan);
}

.tree-node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.tree-node-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.tree-node-icon {
    font-size: 1.5em;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
    transition: transform var(--transition-fast);
}

.tree-node:hover .tree-node-icon {
    transform: scale(1.1);
}

.tree-node-badge {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.875em;
    font-weight: 600;
    letter-spacing: 0.025em;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.tree-node-badge:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.tree-node-metadata {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 2px solid var(--border-light);
    font-size: 0.9375em;
    color: var(--text-secondary);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.metadata-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.metadata-item:hover {
    background: var(--bg-gray);
    transform: translateX(2px);
}

.metadata-label {
    font-weight: 600;
    color: var(--text-primary);
}

.tree-children {
    margin-left: 36px;
    margin-top: 12px;
    padding-left: 12px;
    border-left: 2px solid var(--border-light);
    transition: border-color var(--transition-base);
}

.tree-children:hover {
    border-left-color: var(--primary-blue);
}

.expand-toggle {
    background: var(--bg-light);
    border: 2px solid var(--border-light);
    font-size: 1.2em;
    cursor: pointer;
    padding: 6px 8px;
    color: var(--primary-blue);
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
}

.expand-toggle:hover {
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
    box-shadow: var(--shadow-sm);
}

.expand-toggle.expanded {
    transform: rotate(90deg);
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
}



.refresh-btn {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 0.875em;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin: 0;
    height: 40px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.refresh-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    filter: brightness(1.05);
}

.refresh-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}

.refresh-btn:focus-visible {
    outline: 3px solid rgba(0, 120, 212, 0.5);
    outline-offset: 2px;
}

.logout-btn {
    background: var(--bg-white);
    color: var(--text-secondary);
    border: 2px solid var(--border-medium);
    padding: 14px 24px;
    font-size: 0.9375em;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    margin: 0;
    height: 48px;
    box-shadow: var(--shadow-xs);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.logout-btn:hover {
    background: var(--bg-light);
    border-color: var(--text-secondary);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.logout-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-inner);
    background: var(--bg-gray);
}

.logout-btn:focus-visible {
    outline: 3px solid rgba(107, 114, 128, 0.3);
    outline-offset: 2px;
}

/* @keyframes spin - defined at top of file */

.spinning {
    display: inline-block;
    animation: spin 1s linear infinite;
}

/* Professional Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    animation: fadeIn var(--transition-base);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.loading-content {
    background: var(--bg-white);
    padding: 48px 72px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    text-align: center;
    max-width: 440px;
    animation: slideUp var(--transition-slow);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loading-spinner {
    width: 64px;
    height: 64px;
    margin: 0 auto 24px;
}

.loading-spinner svg {
    width: 100%;
    height: 100%;
}

.loading-message {
    font-size: 1.25em;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.loading-submessage {
    font-size: 0.9375em;
    color: var(--text-secondary);
    line-height: 1.5;
}

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '';
    }

    40% {
        content: '.';
    }

    60% {
        content: '..';
    }

    80%,
    100% {
        content: '...';
    }
}

/* Keyboard Navigation Focus Styles */
button:focus,
.expand-toggle:focus {
    outline: 3px solid var(--primary-blue);
    outline-offset: 3px;
    box-shadow: 0 0 0 4px rgba(0, 120, 212, 0.2);
}

.distribution-row:focus {
    outline: 3px solid var(--primary-blue) !important;
    outline-offset: -3px;
    box-shadow: 0 0 0 4px rgba(0, 120, 212, 0.25);
}

select:focus {
    outline: 3px solid var(--primary-blue);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 120, 212, 0.2);
}

/* Cross-Month Attribution Indicator */
.cross-month-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border: 1px solid #ffb74d;
    color: #e65100;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 6px;
    vertical-align: middle;
    box-shadow: 0 1px 2px rgba(255, 152, 0, 0.2);
    cursor: help;
}

.cross-month-badge:hover {
    background: linear-gradient(135deg, #ffe0b2 0%, #ffcc80 100%);
    box-shadow: 0 2px 4px rgba(255, 152, 0, 0.3);
}

.cross-month-icon {
    font-size: 11px;
}

/* Collapsible Reminder Rows */
.reminder-row {
    transition: all 0.2s ease;
}

.reminder-row.collapsed {
    display: none;
}

.reminder-row td:first-child {
    padding-left: 40px !important;
    position: relative;
}

.reminder-row td:first-child::before {
    content: '↳';
    position: absolute;
    left: 20px;
    color: #f57c00;
    font-size: 14px;
}

.parent-invite-row {
    position: relative;
}

.reminder-toggle {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 8px;
    border: 1px solid #f57c00;
    border-radius: 3px;
    background: #fff3e0;
    font-size: 10px;
    font-weight: bold;
    color: #f57c00;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
}

.reminder-toggle:hover {
    background: #ffe0b2;
    border-color: #ff9800;
    transform: scale(1.1);
}

.reminder-toggle.collapsed::after {
    content: '▼';
}

.reminder-toggle.expanded::after {
    content: '▲';
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 8px;
    }

    h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 1em;
    }

    .stats-panel {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-value {
        font-size: 2.5em;
    }

    .tree-node-metadata {
        grid-template-columns: 1fr;
    }

    .distribution-table-container {
        overflow-x: auto;
    }

    .distribution-table {
        font-size: 11px !important;
        min-width: 800px;
    }

    .distribution-table th,
    .distribution-table td {
        padding: 6px 4px !important;
    }

    .filter-container {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .filter-container label,
    .filter-container select,
    .filter-container button {
        width: 100% !important;
        margin: 0 !important;
    }

    .filter-container button {
        margin-top: 10px !important;
    }

    .error-toast {
        max-width: calc(100vw - 40px) !important;
        right: 10px !important;
        left: 10px !important;
    }

    .tree-children {
        margin-left: 15px;
    }

    .refresh-btn {
        width: 100%;
        margin-bottom: 10px !important;
    }
}

/* Tablet breakpoint */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 100%;
    }



    .distribution-table {
        font-size: 12px;
    }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {

    button,
    .expand-toggle,
    .distribution-row {
        min-height: 44px;
        /* iOS recommended minimum touch target */
    }

    .expand-toggle {
        padding: 8px;
        font-size: 1.4em;
    }
}

/* ============================================
   NOTIFICATIONS & SHARED COMPONENTS
   ============================================ */

.header-content {
    position: relative;
    z-index: 1;
}

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

.nav-links {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10;
}

.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    min-height: 44px;
    min-width: 44px;
    box-sizing: border-box;
    position: relative;
}

.back-link * {
    pointer-events: none;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.back-link:active {
    transform: translateY(0);
}

.main-content {
    padding: 36px;
}

.loading-state,
.error-state,
.empty-state {
    text-align: center;
    padding: 60px 24px;
}

.loading-state {
    color: var(--text-secondary);
}

.error-state {
    color: var(--error-red);
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state {
    color: var(--text-muted);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

/* Loading Animation */
.loading-animation {
    margin-bottom: 16px;
}

.loading-animation svg {
    display: block;
    margin: 0 auto;
}

/* Animated SVG Spinner - animation is handled by SVG SMIL */
.spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    width: 48px;
    height: 48px;
}

.spinner svg {
    width: 100%;
    height: 100%;
}

/* Small inline spinner variant */
.spinner-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.spinner-small svg {
    width: 100%;
    height: 100%;
}

/* Skeleton Loading Animation */
.skeleton {
    background: linear-gradient(90deg,
            var(--bg-light) 25%,
            var(--bg-gray) 50%,
            var(--bg-light) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-card {
    padding: 24px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.section-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.global-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-light);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
}

.global-toggle label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.survey-card {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.survey-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary-blue) 0%, var(--accent-cyan) 100%);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    transform: scaleY(0);
    transform-origin: center;
    transition: transform var(--transition-base);
}

.survey-card:hover {
    box-shadow: var(--shadow-card-hover);
    border-color: var(--primary-light);
    transform: translateY(-3px);
}

.survey-card:hover::before {
    transform: scaleY(1);
}

.survey-card:active {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Notification Settings Card (shown when survey is selected) */
.notification-settings-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 28px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-md);
    position: relative;
}

.notification-settings-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-blue) 0%, var(--accent-cyan) 50%, var(--accent-purple) 100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.settings-survey-info h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.settings-survey-info .survey-id {
    font-size: 13px;
    color: var(--text-muted);
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Notification status indicator in survey grid */
.notification-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--success-light);
    color: var(--success-green);
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-full);
    margin-bottom: 4px;
}

.survey-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.survey-info h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.survey-id {
    font-size: 13px;
    color: var(--text-muted);
    font-family: 'Consolas', 'Monaco', monospace;
}

.notification-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-toggle label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Toggle Switch Styles */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    cursor: pointer;
}

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

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-medium);
    border-radius: 28px;
    transition: all var(--transition-base);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background: white;
    border-radius: 50%;
    transition: all var(--transition-base);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--success-green);
}

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

.toggle-switch input:disabled+.toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.notification-rules {
    display: none;
    padding-top: 20px;
}

.notification-rules.active {
    display: block;
}

.rule-group {
    margin-bottom: 20px;
}

.rule-group:last-child {
    margin-bottom: 0;
}

.rule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.rule-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.rule-icon {
    font-size: 18px;
}

.threshold-input {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-light);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.threshold-input label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 120px;
}

.threshold-input input[type="number"] {
    width: 80px;
    padding: 6px 12px;
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: white;
    transition: all var(--transition-base);
}

.threshold-input input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1);
}

.threshold-input input[type="number"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--bg-gray);
}

.milestone-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.milestone-badge {
    padding: 6px 12px;
    background: var(--primary-light);
    color: white;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
}

.rule-description {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-top: 8px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

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

.btn-secondary:hover {
    background: var(--bg-light);
    border-color: var(--text-secondary);
}

.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    z-index: 9999;
    animation: toastSlideIn 0.4s cubic-bezier(0.21, 1.02, 0.73, 1);
    max-width: 400px;
    min-width: 320px;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.toast.closing {
    animation: toastSlideOut 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(120%) scale(0.9);
        opacity: 0;
    }

    60% {
        transform: translateX(-3%) scale(1.01);
    }

    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0) scale(1);
        opacity: 1;
    }

    to {
        transform: translateX(120%) scale(0.9);
        opacity: 0;
    }
}

.toast-icon {
    font-size: 24px;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast.success {
    border-left: 4px solid var(--success-green);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.05) 0%, rgba(255, 255, 255, 0.98) 20%);
}

.toast.error {
    border-left: 4px solid var(--error-red);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.05) 0%, rgba(255, 255, 255, 0.98) 20%);
}

.toast.warning {
    border-left: 4px solid var(--warning-orange);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.05) 0%, rgba(255, 255, 255, 0.98) 20%);
}

.toast.info {
    border-left: 4px solid var(--primary-blue);
    background: linear-gradient(135deg, rgba(0, 120, 212, 0.05) 0%, rgba(255, 255, 255, 0.98) 20%);
}

/* Toast Container - Queue-based stacking */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

#toast-container .toast {
    position: relative;
    top: auto;
    right: auto;
    pointer-events: auto;
}

.toast-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease, background 0.15s ease;
}

.toast-close:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
}

.toast-close:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* Welcome Panel - Homepage landing */
.welcome-panel {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    padding: 40px;
    margin-top: 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.welcome-panel h2 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 1.5rem;
    font-weight: 600;
}

.welcome-panel p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.welcome-panel-cards {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.welcome-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 32px;
    background: var(--bg-gray);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all var(--transition-fast);
    min-width: 180px;
}

.welcome-card:hover {
    background: var(--border-light);
    transform: translateY(-2px);
}

.welcome-card-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.welcome-card-title {
    font-weight: 600;
    color: var(--text-primary);
}

.welcome-card-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}
