/* Core Styling for SCI-Congress Dashboard */

:root {
    /* DEFAULT PREMIUM PATRIOTIC LIGHT THEME */
    --bg-color: #fafaf9; /* Warm stone/ivory white */
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-border: rgba(15, 23, 42, 0.08);
    --primary-color: #1e3a8a; /* Dignified Navy Blue */
    --primary-light: #3b82f6; /* Sleek Blue */
    --secondary-color: #2563eb; /* Royal Blue */
    --accent-color: #be123c; /* Crimson / Wine Red */
    --text-main: #0f172a; /* Slate 900 */
    --text-muted: #475569; /* Slate 600 */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --shadow: 0 8px 32px 0 rgba(15, 23, 42, 0.06);
    --sidebar-bg: rgba(250, 250, 249, 0.85);
    --item-bg: rgba(30, 58, 138, 0.03);
    --glass-overlay: rgba(250, 250, 249, 0.85);
    --color-white-text: #0f172a;
}

.dark-theme {
    /* PREMIUM SLEEK PATRIOTIC DARK THEME */
    --bg-color: #0b0f19; /* Deep navy-black */
    --card-bg: rgba(17, 25, 40, 0.65);
    --card-border: rgba(255, 255, 255, 0.08);
    --primary-color: #3b82f6; /* Sleek Blue */
    --primary-light: #60a5fa; /* Light Blue */
    --secondary-color: #2563eb; /* Royal Blue */
    --accent-color: #f43f5e; /* Light Crimson */
    --text-main: #f8fafc; /* Slate 50 */
    --text-muted: #94a3b8; /* Slate 400 */
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --sidebar-bg: rgba(11, 15, 25, 0.85);
    --item-bg: rgba(255, 255, 255, 0.02);
    --glass-overlay: rgba(11, 15, 25, 0.75);
    --color-white-text: #ffffff;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
}

#app-container {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: 100vh;
    width: 100vw;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Sidebar Interface */
#sidebar {
    height: 100vh;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    display: flex;
    flex-direction: column;
    z-index: 10;
    background: var(--sidebar-bg);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.app-header {
    padding: 24px;
    border-bottom: 1px solid var(--card-border);
}

.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.theme-switch-wrapper {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 2px;
}

.theme-switch-track {
    position: relative;
    width: 60px;
    height: 30px;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 6px;
    transition: all 0.3s ease;
}

.switch-icon {
    font-size: 13px;
    z-index: 1;
    pointer-events: none;
}

.theme-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Slide thumb in dark mode */
.dark-theme .theme-switch-thumb {
    transform: translateX(30px);
    background: var(--primary-light);
}

.theme-switch-track:hover {
    border-color: var(--primary-light);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-area .icon {
    font-size: 28px;
}

.logo-area h1 {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 26px;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--color-white-text) 30%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: background-color 0.3s ease;
}

.tagline {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-heading);
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.intro-section {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

.scrollable::-webkit-scrollbar {
    width: 6px;
}

.scrollable::-webkit-scrollbar-track {
    background: transparent;
}

.scrollable::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 3px;
}

.summary-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 24px;
}
/* Tabs */
.stat-tabs {
    display: flex;
    justify-content: space-between;
    gap: 4px;
    border-bottom: 1px solid var(--card-border);
    margin-top: 28px; /* Increased from 16px for a clear visual gap from the Explore card */
    margin-bottom: 20px;
    padding-bottom: 8px;
}

.tab-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    padding: 6px 10px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-align: center;
    flex: 1;
    box-sizing: border-box;
}

.tab-btn.active {
    color: var(--primary-color);
    background: rgba(30, 58, 138, 0.08);
    border: 1px solid rgba(30, 58, 138, 0.2);
}

.dark-theme .tab-btn.active {
    color: #ffffff;
    background: rgba(96, 165, 250, 0.15);
    border: 1px solid rgba(96, 165, 250, 0.3);
}

.tab-btn:hover:not(.active) {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.02);
}

.dark-theme .tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.02);
}

.tab-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.tab-content.hidden {
    display: none;
}

.info-card {
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 16px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.info-card h3 {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary-light);
}

.info-card p {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.metric-box {
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.metric-value {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--color-white-text);
    transition: color 0.3s ease;
}

.metric-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.control-card {
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.merged-navigation-card {
    margin-bottom: 28px; /* Increased from 24px to add padding above the tabs */
}

.control-label {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    color: var(--primary-light);
    letter-spacing: -0.01em;
}

.select-wrapper {
    position: relative;
    width: 100%;
}

select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 13px;
    appearance: none;
    cursor: pointer;
    outline: none;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

select:focus {
    border-color: var(--primary-color);
}

.select-wrapper::after {
    content: "▼";
    font-size: 9px;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-muted);
}

/* Method Step styling */
.method-scroller {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.method-step {
    border-left: 2px solid var(--primary-color);
    padding-left: 16px;
    margin-bottom: 4px;
}

.step-num {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 800;
    color: var(--primary-light);
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.method-step h4 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.method-step p {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

.formula {
    display: block;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    padding: 6px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 10.5px;
    margin-top: 6px;
    color: var(--text-main);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.app-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--card-border);
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* Interactive Map Area */
#map-area {
    position: relative;
    height: 100vh;
    width: 100%;
}

#swipe-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.map-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

#map-actual {
    border: 4px solid #2563eb; /* Royal Blue */
}

/* MapLibre comparison overrides */
#map-optimized {
    clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%);
    border: 4px solid #be123c; /* Crimson Red */
}

#swipe-slider {
    position: absolute;
    top: 0;
    bottom: 314px; /* Stops exactly at the top edge of carousel panel (24px gap + 290px height) */
    left: 50%;
    width: 40px; /* Much larger active area for grabbing! */
    margin-left: -20px; /* Center it on the dividing line */
    background: transparent;
    z-index: 5;
    cursor: ew-resize;
}

#swipe-slider::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 18px; /* Centers the 4px line: (40 - 4)/2 = 18 */
    width: 4px;
    background: var(--primary-color);
    transition: background-color 0.2s ease;
    z-index: 1; /* Below handle and label */
}

#swipe-slider:hover::after {
    background: var(--primary-light);
}

.swipe-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-color);
    border: 3px solid var(--bg-color);
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); /* Softened shadow, no glowing halo */
    user-select: none;
    pointer-events: none;
    transition: transform 0.2s ease;
    z-index: 2; /* Above line, below label */
}

#swipe-slider:hover .swipe-handle {
    transform: translate(-50%, -50%) scale(1.1);
}

.swipe-arrow {
    font-size: 12px;
    font-weight: bold;
}

.swipe-label {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    padding: 6px 14px;
    border-radius: 20px;
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--shadow);
    color: var(--text-main);
    letter-spacing: 0.5px;
    pointer-events: none;
    opacity: 0.85;
    z-index: 3; /* On top of everything */
}

.swipe-arrow.left::after { content: "◀"; }
.swipe-arrow.right::after { content: "▶"; }

/* Map Controls Overlay */
#map-overlay-controls {
    position: absolute;
    top: 24px;
    left: 24px;
    padding: 12px 20px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 20px;
    border-radius: 8px;
    background: var(--glass-overlay);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.map-mode-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.indicator-dot.actual {
    background-color: var(--secondary-color);
}

.indicator-dot.optimal {
    background-color: var(--accent-color);
}

.mode-text {
    font-weight: 500;
}

.mode-text.font-bold {
    color: var(--color-white-text);
    font-weight: 600;
    transition: color 0.3s ease;
}

.divider {
    color: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
}

.secondary-btn {
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 6px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary-light);
}

/* State SVG Carousel Overlay */
#carousel-panel {
    position: absolute;
    bottom: 24px;
    left: 24px;
    right: 24px;
    height: 290px;
    z-index: 6;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
    background: var(--glass-overlay);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.carousel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.carousel-header h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.2px;
}

.carousel-nav {
    display: flex;
    gap: 8px;
}

.nav-arrow {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.nav-arrow:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

#carousel-track-container {
    width: 100%;
    flex: 1;
    overflow: hidden;
}

#carousel-track {
    display: flex;
    gap: 20px;
    height: 100%;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: max-content;
}

/* 3D Flip Cards */
.carousel-card {
    width: 380px;
    height: 190px;
    perspective: 1000px; /* Crucial for 3D depth */
    cursor: pointer;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.carousel-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden; /* Crucial: hide back face during rotation */
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    padding: 12px;
    display: flex;
    gap: 16px;
    align-items: center;
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card-back {
    transform: rotateY(180deg); /* Render back side upside down */
}

/* Card Visual styling */
.card-map-wrapper {
    width: 140px;
    height: 140px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 4px;
    border: 1px solid var(--card-border);
}

.card-map-wrapper svg {
    width: 100%;
    height: 100%;
}

.card-info-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.card-info-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.state-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 18px;
}

.plan-type-badge {
    font-size: 9px;
    font-family: var(--font-heading);
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.plan-type-badge.actual {
    background: rgba(37, 99, 235, 0.15);
    color: var(--secondary-color);
    border: 1px solid rgba(37, 99, 235, 0.3);
}

.plan-type-badge.optimal {
    background: rgba(190, 18, 60, 0.15);
    color: var(--accent-color);
    border: 1px solid rgba(190, 18, 60, 0.3);
}

.card-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
}

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

.detail-value {
    color: var(--color-white-text);
    font-weight: 600;
    transition: color 0.3s ease;
}

.detail-value.highlight {
    color: var(--accent-color);
}

.card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.action-hint {
    font-size: 9px;
    color: var(--text-muted);
    font-style: italic;
}

.btn-small {
    background: var(--primary-color);
    border: none;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 10px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.btn-small:hover {
    background: var(--primary-light);
}

/* SVG districts paths */
.svg-district-path {
    fill: none;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-width: 1.5;
    transition: all 0.3s ease;
}

/* Map popup stylings */
.mapboxgl-popup, .maplibregl-popup {
    pointer-events: none;
}

.mapboxgl-popup-content, .maplibregl-popup-content {
    background: var(--bg-color) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: var(--shadow) !important;
    border-radius: 8px !important;
    padding: 14px !important;
    font-family: var(--font-body) !important;
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip, .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--card-border) !important; }
.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip, .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--card-border) !important; }
.mapboxgl-popup-anchor-left .mapboxgl-popup-tip, .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--card-border) !important; }
.mapboxgl-popup-anchor-right .mapboxgl-popup-tip, .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--card-border) !important; }

.popup-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 6px;
}

.popup-stat {
    font-size: 12px;
    margin-bottom: 4px;
}

.popup-stat-label {
    color: var(--text-muted);
}

.popup-stat-val {
    font-weight: 600;
}

/* Premium Index Chart Styles */
.index-chart-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    width: 100%;
}

.index-chart-title {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
}

.index-chart-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.index-chart-label {
    font-size: 10px;
    color: var(--text-muted);
    width: 65px;
    font-weight: 500;
    white-space: nowrap;
}

.index-chart-track {
    flex: 1;
    height: 14px;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.index-chart-bar {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    border-radius: 3px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.index-chart-bar.baseline {
    background: var(--secondary-color);
}

.index-chart-bar.optimized {
    background: var(--accent-color);
}

/* Premium Stacked Bar Chart Styles */
.stacked-bar-horizontal {
    display: flex;
    height: 18px;
    width: 100%;
    border-radius: 6px;
    overflow: hidden;
    background-color: var(--item-bg);
    border: 1px solid var(--card-border);
    margin: 8px 0;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stacked-bar-vertical {
    display: flex;
    flex-direction: column-reverse; /* Stack from bottom to top: within-zcta at bottom, out-of-state at top */
    height: 200px;
    width: 45px;
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--item-bg);
    border: 1px solid var(--card-border);
    margin: 10px auto;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bar-segment {
    height: 100%;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.stacked-bar-vertical .bar-segment {
    width: 100%;
    height: 0; /* will be set via inline style height: X% */
}

.bar-segment:hover {
    filter: brightness(1.2);
    transform: scale(1.02);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
    z-index: 2;
}

/* Harmonized Theme-tailored Segment Colors */
.segment-out-of-state {
    background-color: #64748b !important; /* Slate 500 */
}
.segment-marginal {
    background-color: #10b981 !important; /* Emerald 500 (emerald green) */
}
.segment-marginal-lost {
    background-color: #f59e0b !important; /* Amber 500 (amber orange) */
}
.segment-shared-cuts {
    background-color: #ef4444 !important; /* Red 500 (crimson red) */
}
.segment-preserved {
    background-color: #3b82f6 !important; /* Blue 500 (royal blue) */
}
.segment-within-zcta {
    background-color: #8b5cf6 !important; /* Violet 500 (violet purple) */
}

/* Legend and Details */
.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    padding: 12px;
    background: var(--item-bg);
    border-radius: 8px;
    border: 1px solid var(--card-border);
    flex: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-main);
}

.legend-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
    flex-shrink: 0;
}

.legend-color.out-of-state { background-color: #64748b; }
.legend-color.marginal { background-color: #10b981; }
.legend-color.marginal-lost { background-color: #f59e0b; }
.legend-color.shared-cuts { background-color: #ef4444; }
.legend-color.preserved { background-color: #3b82f6; }
.legend-color.within-zcta { background-color: #8b5cf6; }

.legend-value {
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--color-white-text);
}

/* Carousel compact legend */
.card-chart-legend {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px 12px;
    margin-top: 8px;
    font-size: 10px;
    color: var(--text-muted);
    border-top: 1px solid var(--card-border);
    padding-top: 8px;
}

/* On wider screens or cards, allow 2 columns */
@media (min-width: 320px) {
    .card-chart-legend {
        grid-template-columns: 1fr 1fr;
    }
}

.card-legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.card-legend-left {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-legend-item .legend-color {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

.card-legend-value {
    font-weight: 600;
    color: var(--color-white-text);
    margin-left: 4px;
}

/* National chart card card styling */
.national-chart-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 16px;
    margin-top: 16px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.national-chart-card h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--color-white-text);
    margin-bottom: 4px;
    text-align: center;
}

.national-chart-card .card-desc {
    font-size: 10.5px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 12px;
    line-height: 1.4;
}

.national-chart-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Glossary Section Styles */
.glossary-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.glossary-item {
    border-left: 2px solid var(--primary-color);
    padding-left: 14px;
}

.glossary-item h5 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.glossary-item p {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

.credits-card {
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 16px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.credits-card h4 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-light);
}

.credits-card p {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

.resource-link, .linkedin-link {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.resource-link:hover, .linkedin-link:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.credits-line {
    margin-top: 4px;
    font-size: 10.5px;
    font-weight: 500;
}

.antigravity-credit {
    margin-top: 6px;
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 400;
}

/* Search Box & Download Card Styles */
.search-card {
    gap: 8px;
}

.search-input-wrapper {
    display: flex;
    gap: 8px;
    width: 100%;
}

.search-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 13px;
    outline: none;
    transition: all 0.3s ease;
}

.search-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.search-btn {
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 6px;
    border: none;
    background: var(--primary-color);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.search-btn:hover {
    background-color: var(--primary-light);
}

.download-btn {
    background: var(--primary-color);
    color: #fff;
    border-radius: 6px;
    transition: background-color 0.3s ease;
}

.download-btn:hover {
    background-color: var(--primary-light);
    color: #fff;
}

.search-status-text {
    font-size: 12px;
    line-height: 1.5;
    padding: 10px;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.search-status-text.hidden {
    display: none;
}

.search-title {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--color-white-text);
    margin-bottom: 4px;
}

.search-highlight {
    font-weight: 600;
    color: var(--accent-color);
}

.search-highlight.actual-highlight {
    color: var(--secondary-color);
}

/* View Transitions Customization for premium crossfades (Google I/O 2026 Keynote 10) */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.28s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Deviation Selector Styling */
.deviation-selector {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.dev-btn {
    flex: 1;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.dev-btn:hover {
    background: var(--card-border);
    color: var(--color-white-text);
}

.dev-btn.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: #ffffff;
}

.quick-stats-card {
    margin-top: 12px;
    background: var(--item-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 14px;
}

.stats-paragraph {
    font-size: 13px;
    margin: 0;
    line-height: 1.5;
    color: var(--text-main);
}

/* Responsive Styles for Mobile and Tablet Devices (max-width: 768px) */
@media (max-width: 768px) {
    #app-container {
        grid-template-columns: 1fr;
        grid-template-rows: 45vh 55vh;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }

    #sidebar {
        height: 55vh;
        border-right: none;
        border-top: 1px solid var(--card-border);
    }

    #map-area {
        height: 45vh;
        width: 100%;
        position: relative;
    }

    #carousel-panel {
        display: none; /* Hide carousel panel on mobile to avoid covering the map */
    }

    #swipe-slider {
        bottom: 0; /* Extend swipe handle to the bottom edge of the mobile map area */
    }

    .app-header {
        padding: 16px 20px;
    }

    .intro-section {
        padding: 16px 20px;
    }

    /* Adjust scrollable height for method steps inside the sidebar */
    .method-scroller {
        max-height: 40vh;
    }
}
