/* ===== CSS Variables ===== */
:root {
    /* Color Palette - Dark theme (default) */
    --color-bg: #0d1117;
    --color-bg-elevated: #161b22;
    --color-bg-card: #1c2128;
    --color-border: #30363d;
    --color-border-muted: #21262d;
    
    --color-text-primary: #e6edf3;
    --color-text-secondary: #8b949e;
    --color-text-muted: #6e7681;
    
    --color-accent: #58a6ff;
    --color-accent-emphasis: #388bfd;
    --color-accent-muted: #1f6feb33;
    
    --color-success: #3fb950;
    --color-warning: #d29922;
    --color-danger: #f85149;
    
    /* Chart colors */
    --chart-1: #58a6ff;
    --chart-2: #3fb950;
    --chart-3: #d29922;
    --chart-4: #f85149;
    --chart-5: #a371f7;
    --chart-6: #db61a2;
    --chart-7: #79c0ff;
    --chart-8: #7ee787;
    
    /* Typography */
    --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', 'Consolas', monospace;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    
    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Light Theme */
[data-theme="light"] {
    --color-bg: #ffffff;
    --color-bg-elevated: #f6f8fa;
    --color-bg-card: #f0f3f6;
    --color-border: #d0d7de;
    --color-border-muted: #d8dee4;
    
    --color-text-primary: #1f2328;
    --color-text-secondary: #656d76;
    --color-text-muted: #8c959f;
    
    --color-accent: #0969da;
    --color-accent-emphasis: #0550ae;
    --color-accent-muted: #0969da22;
    
    --color-success: #1a7f37;
    --color-warning: #9a6700;
    --color-danger: #cf222e;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ===== Skip to Content (Accessibility) ===== */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    z-index: 10000;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-accent);
    color: var(--color-bg);
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Screen-reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== 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;
}

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

/* ===== App Layout ===== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.mobile-only {
    display: none;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--color-accent), #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--color-accent);
    color: var(--color-bg);
}

.btn-primary:hover {
    background: var(--color-accent-emphasis);
}

.btn-secondary {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

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

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

.btn-ghost:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-card);
}

.btn-success {
    color: var(--color-success) !important;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-logo {
    margin-bottom: var(--space-lg);
}

.loading-bar {
    animation: loadingPulse 1.5s ease-in-out infinite;
}

.loading-bar-1 { animation-delay: 0s; }
.loading-bar-2 { animation-delay: 0.2s; }
.loading-bar-3 { animation-delay: 0.4s; }

@keyframes loadingPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.loading-text {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-md);
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: var(--color-bg-card);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress-bar {
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, var(--color-accent), #a371f7);
    border-radius: 2px;
    animation: loadingSlide 1.5s ease-in-out infinite;
}

@keyframes loadingSlide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--color-text-primary);
    font-size: 0.875rem;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease;
}

.toast.toast-success {
    border-color: var(--color-success);
}

.toast.toast-success .toast-icon {
    color: var(--color-success);
}

.toast.toast-error {
    border-color: var(--color-danger);
}

.toast.toast-error .toast-icon {
    color: var(--color-danger);
}

.toast.hiding {
    animation: toastSlideOut 0.3s ease forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ===== Scroll to Top Button ===== */
.scroll-to-top {
    position: fixed;
    bottom: var(--space-lg);
    left: var(--space-lg);
    width: 44px;
    height: 44px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.scroll-to-top:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-bg);
    transform: translateY(0) scale(1.1);
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@media (max-width: 480px) {
    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
        bottom: var(--space-md);
    }
    
    .toast {
        width: 100%;
    }
    
    .scroll-to-top {
        bottom: var(--space-md);
        left: var(--space-md);
    }
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr;
    flex: 1;
    overflow: hidden;
}

.main-content.no-filter-panel {
    grid-template-columns: 1fr;
}

.filter-panel.hidden-for-tab {
    display: none;
}

#mobile-menu-toggle.hidden-for-tab {
    display: none !important;
}

/* ===== Filter Panel ===== */
.filter-panel {
    background: var(--color-bg-elevated);
    border-right: 1px solid var(--color-border);
    padding: var(--space-lg);
    overflow-y: auto;
    height: calc(100vh - 72px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-group {
    margin-bottom: var(--space-md);
}

.filter-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xs);
}

.filter-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b949e' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-sm) center;
    padding-right: var(--space-xl);
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-muted);
}

.filter-stats {
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--color-border);
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.filter-stats span {
    color: var(--color-accent);
    font-weight: 600;
}

/* ===== Content Area ===== */
.content-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    padding: var(--space-sm) var(--space-lg);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.tab:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-card);
}

.tab.active {
    color: var(--color-accent);
    background: var(--color-accent-muted);
}

.tab-content {
    display: none;
    flex: 1;
    overflow: auto;
}

.tab-content.active {
    display: block;
}

/* ===== Chart Filter Pills ===== */
.chart-filter-pills {
    display: none;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.chart-filter-pills.visible {
    display: flex;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    background: var(--color-accent-muted);
    border: 1px solid var(--color-accent);
    border-radius: 9999px;
    color: var(--color-accent);
    cursor: pointer;
    transition: all 0.15s ease;
    animation: pillPop 0.3s ease;
}

@keyframes pillPop {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.filter-pill:hover {
    background: var(--color-accent);
    color: var(--color-bg);
}

.filter-pill:hover .pill-remove {
    opacity: 1;
}

.pill-label {
    font-weight: 500;
}

.pill-value {
    color: var(--color-text-primary);
}

.filter-pill:hover .pill-value {
    color: var(--color-bg);
}

.pill-remove {
    opacity: 0.7;
    transition: opacity 0.15s ease;
}

.filter-pill-clear {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text-secondary);
}

.filter-pill-clear:hover {
    background: var(--color-bg-card);
    border-color: var(--color-text-muted);
    color: var(--color-text-primary);
}

/* ===== Charts Tab ===== */
#charts-tab {
    padding: var(--space-lg);
}

.charts-controls {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-lg);
    margin-bottom: var(--space-md);
}

.charts-metric-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toggle-label {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.metric-btn {
    padding: var(--space-xs) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

.metric-btn:first-of-type {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    border-right: none;
}

.metric-btn:last-of-type {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.metric-btn:hover {
    background: var(--color-border-muted);
}

.metric-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-bg);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-lg);
}

.chart-card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

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

.chart-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0;
    color: var(--color-text-primary);
}

.chart-card > h3 {
    margin-bottom: var(--space-md);
}

.chart-export-btn,
.chart-embed-btn {
    padding: var(--space-xs);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.chart-card:hover .chart-export-btn,
.chart-card:hover .chart-embed-btn {
    opacity: 1;
}

.chart {
    min-height: 250px;
}

/* Chart bar styles */
.chart-bar-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.chart-bar-row {
    display: grid;
    grid-template-columns: 180px 1fr 50px;
    align-items: center;
    gap: var(--space-md);
}

/* Clickable bar styles */
.chart-bar-clickable {
    cursor: pointer;
    padding: var(--space-xs);
    margin: calc(-1 * var(--space-xs));
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
}

.chart-bar-clickable:hover {
    background: var(--color-bg-card);
}

.chart-bar-clickable:hover .chart-bar-label {
    color: var(--color-text-primary);
}

.chart-bar-clickable:hover .chart-bar-fill {
    filter: brightness(1.1);
}

.chart-bar-clickable.active {
    background: var(--color-accent-muted);
}

.chart-bar-clickable.active .chart-bar-label {
    color: var(--color-accent);
    font-weight: 500;
}

.chart-bar-label {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-bar-track {
    height: 24px;
    background: var(--color-bg-card);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chart-bar-fill {
    height: 100%;
    border-radius: var(--radius-sm);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.chart-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    100% { left: 100%; }
}

.chart-bar-value {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    text-align: right;
}

/* ===== SQL Tab ===== */
#sql-tab {
    display: none;
    flex-direction: column;
    height: calc(100vh - 130px);
}

#sql-tab.active {
    display: flex;
}

.sql-container {
    display: grid;
    grid-template-rows: auto 1fr;
    flex: 1;
    overflow: hidden;
}

.sql-editor-wrapper {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--color-border);
}

.sql-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

#sql-editor {
    width: 100%;
    min-height: 150px;
    padding: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    background: var(--color-bg);
    border: none;
    color: var(--color-text-primary);
    resize: vertical;
}

#sql-editor:focus {
    outline: none;
}

/* CodeMirror overrides */
.CodeMirror {
    height: 180px !important;
    font-family: var(--font-mono) !important;
    font-size: 0.875rem !important;
    background: var(--color-bg) !important;
}

.cm-s-dracula.CodeMirror {
    background: var(--color-bg) !important;
}

.sql-results-wrapper {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sql-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.sql-results-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.sql-results-actions .btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

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

.query-time {
    font-family: var(--font-mono);
    color: var(--color-success);
}

.sql-results {
    flex: 1;
    overflow: auto;
    padding: var(--space-md);
}

.placeholder-text {
    color: var(--color-text-muted);
    font-style: italic;
}

/* ===== Empty States ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
    min-height: 200px;
}

.empty-state-icon {
    color: var(--color-text-muted);
    opacity: 0.5;
    margin-bottom: var(--space-md);
}

.empty-state p {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xs);
}

.empty-state-hint {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.error-text {
    color: var(--color-danger);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    white-space: pre-wrap;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.results-table th,
.results-table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.results-table th {
    background: var(--color-bg-elevated);
    font-weight: 600;
    color: var(--color-text-secondary);
    position: sticky;
    top: 0;
}

.results-table tr:hover td {
    background: var(--color-bg-card);
}

.results-table td {
    font-family: var(--font-mono);
    color: var(--color-text-primary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* SQL Help */
.sql-help {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
}

.sql-help details {
    margin-bottom: var(--space-sm);
}

.sql-help summary {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-xs) 0;
}

.sql-help summary:hover {
    color: var(--color-text-primary);
}

.columns-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-sm) 0;
}

.columns-list code {
    padding: 2px var(--space-sm);
    background: var(--color-bg-card);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-accent);
}

.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-sm) 0;
}

.example-query {
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.example-query:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* ===== Crosstab Tab ===== */
#crosstab-tab {
    display: none;
    flex-direction: column;
    height: calc(100vh - 130px);
}

#crosstab-tab.active {
    display: flex;
}

.crosstab-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.crosstab-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
}

.crosstab-control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.crosstab-control-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.crosstab-control-group .filter-select {
    min-width: 180px;
}

.crosstab-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    margin-left: var(--space-sm);
}

.crosstab-toggle input {
    accent-color: var(--color-accent);
}

.crosstab-table-wrapper {
    flex: 1;
    overflow: auto;
    padding: var(--space-lg);
}

.crosstab-results {
    min-height: 200px;
}

/* Crosstab Table */
.crosstab-table {
    border-collapse: collapse;
    font-size: 0.8125rem;
    width: auto;
    min-width: 100%;
}

.crosstab-table th,
.crosstab-table td {
    padding: var(--space-sm) var(--space-md);
    text-align: center;
    border: 1px solid var(--color-border);
    white-space: nowrap;
}

.crosstab-corner {
    background: var(--color-bg-elevated);
    text-align: left !important;
    font-weight: 500;
    color: var(--color-text-secondary);
    position: sticky;
    left: 0;
    z-index: 2;
}

.crosstab-col-header {
    background: var(--color-bg-elevated);
    font-weight: 500;
    color: var(--color-text-secondary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crosstab-sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.crosstab-sortable:hover {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
}

.crosstab-sortable.sort-active {
    color: var(--color-accent);
    background: var(--color-accent-muted);
}

.crosstab-row-header {
    background: var(--color-bg-elevated);
    text-align: left !important;
    font-weight: 500;
    color: var(--color-text-secondary);
    position: sticky;
    left: 0;
    z-index: 1;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Wrapped text mode */
.crosstab-table.wrap-text th,
.crosstab-table.wrap-text td {
    white-space: normal;
    word-wrap: break-word;
}

.crosstab-table.wrap-text .crosstab-col-header {
    max-width: none;
    min-width: 100px;
    writing-mode: horizontal-tb;
}

.crosstab-table.wrap-text .crosstab-row-header {
    max-width: none;
    min-width: 150px;
}

.crosstab-cell {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    transition: transform 0.1s ease;
}

.crosstab-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 2px var(--color-accent);
    z-index: 1;
    position: relative;
}

.crosstab-total-header,
.crosstab-row-total,
.crosstab-col-total,
.crosstab-grand-total {
    background: var(--color-bg-card);
    font-weight: 600;
    color: var(--color-text-primary);
}

.crosstab-totals-row th,
.crosstab-totals-row td {
    border-top: 2px solid var(--color-border);
}

.crosstab-grand-total {
    background: var(--color-accent-muted);
    color: var(--color-accent);
}

/* ===== Responses Tab ===== */
#responses-tab {
    display: none;
    flex-direction: column;
    height: calc(100vh - 130px);
}

#responses-tab.active {
    display: flex;
}

.responses-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.responses-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
}

.responses-info {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.responses-info strong {
    color: var(--color-text-primary);
}

.responses-controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.responses-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.responses-toggle input {
    accent-color: var(--color-accent);
}

.responses-table-wrapper {
    flex: 1;
    overflow: auto;
    padding: var(--space-md) var(--space-lg);
}

.responses-results {
    min-height: 200px;
}

.responses-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
}

#responses-page-info {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

/* Responses Table */
.responses-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.responses-table th,
.responses-table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.responses-table th {
    background: var(--color-bg-elevated);
    font-weight: 600;
    color: var(--color-text-secondary);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}

.responses-table tr:hover td {
    background: var(--color-bg-card);
}

.response-row-num {
    width: 50px;
    text-align: center !important;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.responses-table td {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.responses-table td.text-column {
    max-width: 300px;
    white-space: normal;
}

.text-cell {
    position: relative;
}

.text-preview {
    display: block;
    line-height: 1.5;
    color: var(--color-text-primary);
}

.text-cell.expandable .text-preview {
    color: var(--color-text-secondary);
}

.text-cell.expanded .text-preview {
    color: var(--color-text-primary);
}

.expand-btn {
    display: inline-block;
    margin-top: var(--space-xs);
    padding: 2px var(--space-sm);
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--color-accent);
    background: transparent;
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.expand-btn:hover {
    background: var(--color-accent);
    color: var(--color-bg);
}

.empty-text {
    color: var(--color-text-muted);
    font-style: italic;
}

.responses-table th.text-column {
    min-width: 200px;
}

/* ===== About Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-lg);
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.modal-close {
    padding: var(--space-xs);
}

.modal-content {
    padding: var(--space-lg);
    overflow-y: auto;
}

.about-section {
    margin-bottom: var(--space-xl);
}

.about-section:last-child {
    margin-bottom: 0;
}

.about-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
}

.about-section p {
    color: var(--color-text-secondary);
    line-height: 1.7;
}

.methodology-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.methodology-item {
    background: var(--color-bg-card);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.methodology-label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.methodology-value {
    display: block;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text-primary);
}

.about-notes {
    list-style: none;
    padding: 0;
}

.about-notes li {
    position: relative;
    padding-left: var(--space-lg);
    margin-bottom: var(--space-sm);
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.about-notes li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.5em;
    width: 6px;
    height: 6px;
    background: var(--color-warning);
    border-radius: 50%;
}

.about-links {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

@media (max-width: 480px) {
    .methodology-grid {
        grid-template-columns: 1fr;
    }
    
    .modal {
        max-height: 90vh;
    }
}

/* ===== Footer ===== */
.footer {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
    text-align: center;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .mobile-only {
        display: flex;
    }

    .header {
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-sm);
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-actions {
        display: none;
    }

    .filter-panel {
        display: none;
        position: fixed;
        top: 72px;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        height: calc(100vh - 72px);
        background: var(--color-bg-elevated);
        border-right: none;
        overflow-y: auto;
        animation: slideIn 0.2s ease;
    }

    .filter-panel.hidden-for-tab {
        display: none !important;
    }

    @keyframes slideIn {
        from { transform: translateX(-100%); }
        to { transform: translateX(0); }
    }

    .filter-panel.open {
        display: block;
    }

    .filter-backdrop {
        position: fixed;
        inset: 0;
        top: 72px;
        background: rgba(0, 0, 0, 0.5);
        z-index: 199;
    }

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

    .chart-bar-row {
        grid-template-columns: 120px 1fr 40px;
    }

    .header h1 {
        font-size: 1.125rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .tabs {
        padding: var(--space-sm) var(--space-md);
        border-top: 1px solid var(--color-border-muted);
    }
    
    /* Tables scroll horizontally on mobile */
    .crosstab-table-wrapper,
    .responses-table-wrapper,
    .sql-results {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .results-table,
    .crosstab-table,
    .responses-table {
        min-width: 600px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: var(--space-sm) var(--space-sm);
        flex-wrap: wrap;
        gap: var(--space-xs);
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-content h1 {
        font-size: 0.9375rem;
    }

    .header-content .subtitle {
        font-size: 0.6875rem;
    }

    .tabs {
        padding: var(--space-xs) var(--space-sm);
        gap: 2px;
    }

    .tab {
        padding: 6px var(--space-sm);
        font-size: 0.75rem;
    }
    
    #charts-tab {
        padding: var(--space-md);
    }
    
    .chart-card {
        padding: var(--space-md);
    }
    
    .chart-bar-row {
        grid-template-columns: 100px 1fr 35px;
        gap: var(--space-sm);
    }
    
    .chart-bar-label {
        font-size: 0.75rem;
    }
    
    .chart-bar-value {
        font-size: 0.75rem;
    }
    
    /* Report mobile styles */
    .report-layout {
        padding: var(--space-md);
    }
    
    .report-content {
        padding: var(--space-md);
    }
    
    .report-header h1 {
        font-size: 1.5rem;
    }
    
    .report-section h2 {
        font-size: 1.25rem;
    }
    
    .report-section h3 {
        font-size: 1rem;
    }
    
    .report-section p {
        font-size: 0.9375rem;
        line-height: 1.7;
    }
    
    .key-findings {
        grid-template-columns: 1fr;
    }
    
    .finding-stat {
        font-size: 2rem;
    }
    
    .report-table {
        font-size: 0.75rem;
    }
    
    .report-table th,
    .report-table td {
        padding: var(--space-xs) var(--space-sm);
    }
    
    .author-intro h2 {
        font-size: 1.25rem;
    }
    
    .interactive-callout {
        flex-direction: column;
        padding: var(--space-md);
    }
    
    .callout-features {
        grid-template-columns: 1fr;
    }
    
    /* SQL tab mobile */
    .sql-container {
        grid-template-rows: auto auto 1fr;
    }
    
    .CodeMirror {
        height: 120px !important;
    }
    
    .sql-help {
        padding: var(--space-sm) var(--space-md);
    }
    
    /* Crosstab controls */
    .crosstab-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .crosstab-control-group {
        width: 100%;
    }
    
    .crosstab-control-group .filter-select {
        width: 100%;
        min-width: unset;
    }
    
    /* Responses tab */
    .responses-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .responses-controls {
        width: 100%;
        flex-direction: column;
        gap: var(--space-sm);
    }
    
    .responses-toggle {
        width: 100%;
    }
    
    #export-filtered-csv {
        width: 100%;
        justify-content: center;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        opacity: 0; 
        transform: translateY(10px);
    }
    to { 
        opacity: 1; 
        transform: translateY(0);
    }
}

.chart-card {
    animation: slideUp 0.3s ease;
}

.chart-card:nth-child(2) { animation-delay: 0.05s; }
.chart-card:nth-child(3) { animation-delay: 0.1s; }
.chart-card:nth-child(4) { animation-delay: 0.15s; }
.chart-card:nth-child(5) { animation-delay: 0.2s; }
.chart-card:nth-child(6) { animation-delay: 0.25s; }

/* Smooth transitions */
.tab-content {
    animation: fadeIn 0.2s ease;
}

/* Stagger animation helper */
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
.stagger-5 { animation-delay: 0.25s; }

/* Report section entrance animations */
.report-section {
    animation: slideUp 0.4s ease both;
}

.report-section:nth-child(1) { animation-delay: 0.1s; }
.report-section:nth-child(2) { animation-delay: 0.15s; }
.report-section:nth-child(3) { animation-delay: 0.2s; }
.report-section:nth-child(4) { animation-delay: 0.25s; }
.report-section:nth-child(5) { animation-delay: 0.3s; }

/* Button press effect */
.btn {
    transition: all 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
}

/* Filter select animation */
.filter-select {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Tab hover lift */
.tab {
    transition: all 0.2s ease;
}

.tab:hover {
    transform: translateY(-1px);
}

/* Crosstab cell hover */
.crosstab-cell {
    transition: all 0.15s ease;
}

/* Focus states for accessibility */
.btn:focus-visible,
.tab:focus-visible,
.filter-select:focus-visible,
.toc-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Better touch feedback */
@media (hover: none) {
    .btn:active {
        transform: scale(0.97);
    }
    
    .chart-bar-clickable:active {
        background: var(--color-bg-card);
    }
}

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

/* ===== Report Tab ===== */
#report-tab {
    display: none;
    height: calc(100vh - 130px);
    overflow-y: auto;
}

#report-tab.active {
    display: block;
}

.report-layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: var(--space-lg);
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-lg);
}

/* Table of Contents */
.report-toc {
    position: sticky;
    top: var(--space-lg);
    height: fit-content;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.toc-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
    padding-left: var(--space-sm);
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-list li {
    margin-bottom: var(--space-xs);
}

.toc-link {
    display: block;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    transition: all 0.15s ease;
}

.toc-link:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-card);
}

.toc-link.active {
    color: var(--color-accent);
    border-left-color: var(--color-accent);
    background: var(--color-accent-muted);
}

.report-container {
    max-width: 900px;
    margin: 0 auto;
}

@media (max-width: 900px) {
    .report-layout {
        grid-template-columns: 1fr;
        padding: var(--space-lg) var(--space-md);
    }
    
    .report-toc {
        display: none;
    }
}

/* Interactive Features Callout */
.interactive-callout {
    display: flex;
    gap: var(--space-lg);
    background: linear-gradient(135deg, var(--color-accent-muted), rgba(163, 113, 247, 0.15));
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-2xl);
    position: relative;
    overflow: hidden;
}

.interactive-callout::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--color-accent), #a371f7);
}

.callout-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: var(--color-accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-bg);
}

.callout-content h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-sm);
}

.callout-content > p {
    color: var(--color-text-secondary);
    font-size: 0.9375rem;
    margin-bottom: var(--space-md);
}

.callout-features {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-md) 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.callout-features li {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    padding-left: var(--space-md);
    position: relative;
}

.callout-features li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--color-accent);
}

.callout-features li strong {
    color: var(--color-text-primary);
}

.callout-hint {
    font-size: 0.8125rem !important;
    color: var(--color-text-muted) !important;
    margin-bottom: 0 !important;
}

@media (max-width: 768px) {
    .interactive-callout {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .callout-features {
        grid-template-columns: 1fr;
    }
}

.report-content {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl);
}

/* Author Introduction */
.author-intro {
    padding-bottom: var(--space-2xl);
    margin-bottom: var(--space-2xl);
    border-bottom: 1px solid var(--color-border);
}

.author-intro h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-lg);
    line-height: 1.3;
}

.author-intro p {
    color: var(--color-text-secondary);
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: var(--space-md);
}

.author-intro p:last-child {
    margin-bottom: 0;
}

.author-cta {
    font-weight: 600;
    color: var(--color-text-primary) !important;
    font-style: italic;
}

.author-signoff {
    margin-top: var(--space-lg) !important;
    margin-bottom: var(--space-xs) !important;
    color: var(--color-text-muted) !important;
}

.author-name {
    font-weight: 600;
    font-size: 1.125rem !important;
    color: var(--color-accent) !important;
    margin-bottom: 0 !important;
}

/* Report Header */
.report-header {
    text-align: center;
    padding-bottom: var(--space-2xl);
    margin-bottom: var(--space-2xl);
    border-bottom: 1px solid var(--color-border);
}

.report-series {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: var(--space-sm);
}

.report-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-accent), #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-xs);
    letter-spacing: -0.02em;
}

.report-subtitle {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-lg);
}

.report-description {
    font-size: 1rem;
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-md);
}

.report-date {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Report Sections */
.report-section {
    margin-bottom: var(--space-2xl);
}

.report-section:last-of-type {
    margin-bottom: 0;
}

.report-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-accent);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-accent-muted);
}

.report-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-top: var(--space-xl);
    margin-bottom: var(--space-md);
}

.report-section h3:first-child {
    margin-top: 0;
}

.report-section p {
    color: var(--color-text-secondary);
    line-height: 1.8;
    margin-bottom: var(--space-md);
}

.report-section p:last-child {
    margin-bottom: 0;
}

.report-section em {
    color: var(--color-text-primary);
    font-style: italic;
}

/* Key Findings Cards */
.key-findings {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
    margin: var(--space-xl) 0;
}

.finding {
    background: linear-gradient(135deg, var(--color-bg-card), var(--color-bg-elevated));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl) var(--space-lg);
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.finding::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-accent), #a371f7);
}

.finding:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.finding-stat {
    display: block;
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-accent), #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    margin-bottom: var(--space-sm);
}

.finding-text {
    display: block;
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

/* Report Tables */
.report-table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-xl) 0;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.report-table th,
.report-table td {
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.report-table th {
    background: var(--color-bg-card);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.report-table td {
    color: var(--color-text-primary);
}

.report-table td:nth-child(2),
.report-table td:nth-child(3),
.report-table td:nth-child(4) {
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 500;
}

.report-table th:nth-child(2),
.report-table th:nth-child(3),
.report-table th:nth-child(4) {
    text-align: center;
}

.report-table tbody tr {
    transition: background 0.15s ease;
}

.report-table tbody tr:hover td {
    background: var(--color-bg-card);
}

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

/* Report Takeaways List */
.report-takeaways {
    list-style: none;
    padding: 0;
    counter-reset: takeaway;
}

.report-takeaways li {
    position: relative;
    padding-left: var(--space-2xl);
    margin-bottom: var(--space-lg);
    color: var(--color-text-secondary);
    line-height: 1.7;
    counter-increment: takeaway;
}

.report-takeaways li::before {
    content: counter(takeaway);
    position: absolute;
    left: 0;
    top: 0;
    width: 28px;
    height: 28px;
    background: var(--color-accent-muted);
    color: var(--color-accent);
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.report-takeaways li strong {
    color: var(--color-text-primary);
}

/* Report Footer */
.report-footer {
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--color-border);
    text-align: center;
}

.report-footer h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-md);
}

.report-footer p {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: var(--space-sm);
}

.report-footer a {
    color: var(--color-accent);
    text-decoration: none;
}

.report-footer a:hover {
    text-decoration: underline;
}

/* Report Responsive */
@media (max-width: 768px) {
    .report-container {
        padding: var(--space-lg) var(--space-md);
    }
    
    .report-content {
        padding: var(--space-lg);
    }
    
    .report-header h1 {
        font-size: 1.75rem;
    }
    
    .report-subtitle {
        font-size: 1rem;
    }
    
    .key-findings {
        grid-template-columns: 1fr;
    }
    
    .finding-stat {
        font-size: 2rem;
    }
    
    .report-table {
        font-size: 0.8125rem;
    }
    
    .report-table th,
    .report-table td {
        padding: var(--space-xs) var(--space-sm);
    }
}

/* ===== Chart Tooltips ===== */
.chart-tooltip {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.8125rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.chart-tooltip.visible {
    opacity: 1;
}

.chart-tooltip-label {
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.chart-tooltip-value {
    color: var(--color-text-secondary);
}

.chart-tooltip-value strong {
    color: var(--color-accent);
    font-family: var(--font-mono);
}

/* ===== Responses Search ===== */
.responses-search {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

.responses-search .filter-select {
    width: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b949e' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-sm) center;
    padding-right: var(--space-xl);
}

/* ===== Keyboard Shortcuts Modal ===== */
.shortcuts-modal {
    max-width: 500px;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
}

.shortcut-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.shortcut-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 2px var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    box-shadow: 0 1px 0 var(--color-border);
}

@media (max-width: 480px) {
    .shortcuts-grid {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }
}

/* ===== Footer Enhancements ===== */
.footer-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
    flex-wrap: wrap;
}

.version-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.footer-separator {
    color: var(--color-border);
}

.feedback-link {
    color: var(--color-accent);
    text-decoration: none;
    font-size: 0.8125rem;
}

.feedback-link:hover {
    text-decoration: underline;
}

.footer-shortcuts-btn {
    font-size: 0.75rem !important;
    padding: 2px var(--space-sm) !important;
    gap: var(--space-xs) !important;
}

.footer a {
    color: var(--color-accent);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ===== Improved Mobile Filter Transitions ===== */
@media (max-width: 900px) {
    .filter-panel {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(-100%);
    }

    .filter-panel.open {
        display: block;
        transform: translateX(0);
    }

    .filter-backdrop {
        opacity: 0;
        animation: fadeIn 0.3s ease forwards;
    }
}

/* ===== Improved Contrast (Accessibility) ===== */
/* Ensure muted text meets WCAG AA 4.5:1 on both themes */
[data-theme="light"] {
    --color-text-muted: #656d76; /* bumped from #8c959f for better contrast */
}

/* ===== Print Styles for Report Tab ===== */
@media print {
    /* Hide non-essential UI */
    .header,
    .filter-panel,
    .tabs,
    .chart-filter-pills,
    .scroll-to-top,
    .toast-container,
    .footer,
    .report-toc,
    .interactive-callout,
    .skip-to-content,
    #aria-announcer,
    #loading-overlay {
        display: none !important;
    }

    /* Reset layout for print */
    body {
        background: white !important;
        color: #1f2328 !important;
        font-size: 11pt;
    }

    .app-container {
        display: block;
    }

    .main-content {
        display: block !important;
        overflow: visible !important;
    }

    .content-area {
        overflow: visible !important;
    }

    /* Show only the report tab */
    .tab-content {
        display: none !important;
    }

    #report-tab {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }

    .report-layout {
        display: block !important;
        padding: 0 !important;
        max-width: none !important;
    }

    .report-container {
        max-width: none !important;
    }

    .report-content {
        background: white !important;
        border: none !important;
        padding: 0 !important;
        box-shadow: none !important;
    }

    /* Report text */
    .report-section h2 {
        color: #1f2328 !important;
        border-bottom-color: #d0d7de !important;
        page-break-after: avoid;
    }

    .report-section h3 {
        color: #1f2328 !important;
        page-break-after: avoid;
    }

    .report-section p {
        color: #1f2328 !important;
        orphans: 3;
        widows: 3;
    }

    /* Report header */
    .report-header h1 {
        background: none !important;
        -webkit-text-fill-color: #1f2328 !important;
        color: #1f2328 !important;
    }

    .report-series,
    .report-subtitle,
    .report-description,
    .report-date {
        color: #656d76 !important;
    }

    /* Tables */
    .report-table {
        page-break-inside: avoid;
        border-color: #d0d7de !important;
    }

    .report-table th {
        background: #f6f8fa !important;
        color: #1f2328 !important;
    }

    .report-table td {
        color: #1f2328 !important;
        border-color: #d0d7de !important;
    }

    /* Key findings cards */
    .key-findings {
        page-break-inside: avoid;
    }

    .finding {
        border-color: #d0d7de !important;
        background: #f6f8fa !important;
    }

    .finding-stat {
        background: none !important;
        -webkit-text-fill-color: #0969da !important;
        color: #0969da !important;
    }

    .finding-text {
        color: #1f2328 !important;
    }

    /* Author intro */
    .author-intro h2 {
        color: #1f2328 !important;
    }

    .author-intro p {
        color: #1f2328 !important;
    }

    .author-name {
        -webkit-text-fill-color: #0969da !important;
        color: #0969da !important;
    }

    /* Takeaways */
    .report-takeaways li {
        color: #1f2328 !important;
    }

    .report-takeaways li::before {
        background: #0969da !important;
        color: white !important;
    }

    /* Footer */
    .report-footer {
        border-color: #d0d7de !important;
    }

    .report-footer h3,
    .report-footer p {
        color: #1f2328 !important;
    }

    .report-footer a {
        color: #0969da !important;
    }

    /* Links in print */
    a[href] {
        color: #0969da !important;
        text-decoration: underline;
    }

    /* Page margins */
    @page {
        margin: 2cm;
    }
}

/* ===== Embed Chart Modal ===== */
.embed-modal-dialog {
    max-width: 700px;
}

.embed-options {
    margin-bottom: var(--space-lg);
}

.embed-option-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.embed-option-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.embed-option-group .filter-select {
    width: 100%;
    min-width: unset;
}

.embed-filter-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.embed-filter-toggle input {
    accent-color: var(--color-accent);
}

.embed-preview-section {
    margin-bottom: var(--space-lg);
}

.embed-preview-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

.embed-preview {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
}

.embed-preview iframe {
    display: block;
    border: none;
    width: 100%;
    height: 300px;
}

.embed-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.embed-code-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.embed-copy-btn {
    font-size: 0.75rem !important;
    padding: var(--space-xs) var(--space-sm) !important;
}

.embed-code-block {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    overflow-x: auto;
    margin: 0;
}

.embed-code-block code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-accent);
    white-space: pre-wrap;
    word-break: break-all;
}

@media (max-width: 600px) {
    .embed-option-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .embed-modal-dialog {
        max-height: 90vh;
    }
}

/* ===== Responses Search Mobile ===== */
@media (max-width: 480px) {
    .responses-search {
        max-width: none;
        width: 100%;
        order: -1;
    }
}

/* ===== Chart Loading Skeletons ===== */
.chart-skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.chart-skeleton-row {
    display: grid;
    grid-template-columns: 180px 1fr 50px;
    align-items: center;
    gap: var(--space-md);
}

.chart-skeleton-label,
.chart-skeleton-bar,
.chart-skeleton-value {
    background: var(--color-bg-card);
    border-radius: var(--radius-sm);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.chart-skeleton-label {
    height: 14px;
    width: 70%;
}

.chart-skeleton-bar {
    height: 24px;
}

.chart-skeleton-value {
    height: 14px;
    width: 30px;
    margin-left: auto;
}

@keyframes skeletonPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

.chart-skeleton-row:nth-child(1) .chart-skeleton-bar { width: 90%; }
.chart-skeleton-row:nth-child(2) .chart-skeleton-bar { width: 70%; }
.chart-skeleton-row:nth-child(3) .chart-skeleton-bar { width: 55%; }
.chart-skeleton-row:nth-child(4) .chart-skeleton-bar { width: 40%; }
.chart-skeleton-row:nth-child(5) .chart-skeleton-bar { width: 25%; }

.chart-skeleton-row:nth-child(2) { animation-delay: 0.1s; }
.chart-skeleton-row:nth-child(3) { animation-delay: 0.2s; }
.chart-skeleton-row:nth-child(4) { animation-delay: 0.3s; }
.chart-skeleton-row:nth-child(5) { animation-delay: 0.4s; }

@media (max-width: 900px) {
    .chart-skeleton-row {
        grid-template-columns: 120px 1fr 40px;
    }
}

/* ===== SQL Query History ===== */
.sql-history-wrapper {
    position: relative;
}

.sql-history-btn {
    font-size: 0.75rem !important;
    padding: var(--space-xs) var(--space-sm) !important;
}

.sql-history-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 50;
    min-width: 320px;
    max-width: 500px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    margin-top: var(--space-xs);
}

.sql-history-dropdown.open {
    display: block;
}

.sql-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sql-history-clear {
    font-size: 0.6875rem !important;
    padding: 2px var(--space-sm) !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

.sql-history-item {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--color-border-muted);
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sql-history-item:hover {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
}

.sql-history-item:last-child {
    border-bottom: none;
}

.sql-history-time {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.625rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.sql-history-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-style: italic;
}

/* ===== Drill-down Link ===== */
.chart-drilldown {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-accent);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
    font-family: var(--font-sans);
}

.chart-drilldown:hover {
    background: var(--color-accent-muted);
}

/* ===== Comparison Mode ===== */
.compare-controls {
    display: none;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    animation: fadeIn 0.2s ease;
}

.compare-controls.visible {
    display: flex;
    flex-wrap: wrap;
}

.compare-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.compare-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.compare-label-a {
    color: var(--chart-1);
}

.compare-label-b {
    color: var(--chart-4);
}

.compare-group .filter-select {
    min-width: 160px;
    width: auto;
}

.compare-bar-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.compare-bar-track {
    height: 12px;
    background: var(--color-bg-card);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.compare-bar-fill-a {
    height: 100%;
    border-radius: 2px;
    background: var(--chart-1);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.compare-bar-fill-b {
    height: 100%;
    border-radius: 2px;
    background: var(--chart-4);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.compare-values {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    min-width: 50px;
}

.compare-val-a { color: var(--chart-1); }
.compare-val-b { color: var(--chart-4); }

.compare-btn {
    white-space: nowrap;
}

.compare-btn.active {
    background: var(--color-accent-muted);
    color: var(--color-accent);
    border-color: var(--color-accent);
}

@media (max-width: 480px) {
    .compare-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .compare-group .filter-select {
        min-width: unset;
        width: 100%;
    }
}

