/* =========================
   Root Variables
   ========================= */
:root {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --text-primary: #1a2332;
    --text-secondary: #4a5568;
    --accent: #1e3a8a;
    --accent-light: #3b82f6;
    --border: #d1d5db;
    --shadow: rgba(0, 0, 0, 0.06);
    --shadow-lg: rgba(0, 0, 0, 0.10);
    --primary-light: #eff6ff;
    --secondary-light: #dbeafe;
    --accent-green: #059669;
    --gov-blue: #1e40af;
    --gov-red: #dc2626;
}

/* =========================
   Global Reset
   ========================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-weight: 400;
    letter-spacing: -0.011em;
    min-height: 100vh;
    padding: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.container-fluid {
    padding-right: 30px;
    padding-left: 30px;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow-x: hidden;
    overflow-y: visible;
    box-shadow: 0 1px 3px var(--shadow), 0 0 0 1px var(--border);
    border: 1px solid var(--border);
}

/* =========================
   Header
   ========================= */
header {
    text-align: center;
    padding: 20px 30px 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-bottom: 1px solid var(--border);
    position: relative;
}

.header-badge {
    display: inline-block;
    padding: 6px 14px;
    background: var(--text-primary);
    color: var(--bg-secondary);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-radius: 20px;
    margin-bottom: 20px;
}

h1 {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
    max-width: 700px;
    margin: 0 auto;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

/* =========================
   Section Headers
   ========================= */
.visualization-section {
    padding: 60px 0;
    min-height: 600px;
    border-bottom: 1px solid var(--border);
}

.viz-block {
    border-bottom: 3px dotted rgba(74, 85, 104, 0.3);
    padding-bottom: 18px;
    margin-bottom: 30px;
}

.vis4-surface {
    position: relative;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.06);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.vis4-layout {
    display: flex;
    gap: 16px;
    min-height: 620px;
    height: 100%;
    align-items: stretch;
    width: 100%;
}

.vis4-main {
    flex: 3 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

#vis4-container {
    width: 100%;
    height: 100%;
    min-height: 600px;
}

.vis4-graph-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

.vis4-side-rail {
    flex: 1 1 0;
    min-width: 220px;
    background: #ffffff;
    border-left: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
    position: relative;
    padding: 12px;
    display: flex;
    overflow-y: auto;
}
.vis4-side-rail::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 1px;
    background: linear-gradient(to bottom, rgba(17,24,39,0.08), rgba(17,24,39,0.02));
}

.vis4-side-rail-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.vis4-side-rail #vis4-rentinfo {
    width: 100%;
    padding: 0 !important;
    margin: 0;
}
.vis4-side-rail #vis4-rentinfo .rent-info-wrapper {
    width: 100%;
    max-width: 240px;
    margin: 0 auto;
}

.vis4v2-shell {
    position: relative;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.06);
    overflow: auto;
    min-height: 760px;
}

#vis4v2-container {
    width: 100%;
    min-height: 760px;
    overflow: auto;
}

#vis4v2-container svg {
    display: block;
}

#visualization-area-3 .visualization-section {
    padding-top: 20px;
    padding-bottom: 48px;
    margin-top: 0;
}
#visualization-area-3 .vis4v2-shell {
    margin-top: 12px;
}

.info-row .info-row-bg {
    stroke: transparent;
    stroke-width: 1px;
    transition: stroke 180ms ease, stroke-width 180ms ease;
}

.info-row .info-divider {
    stroke: #e5e7eb;
    transition: stroke 180ms ease, stroke-width 180ms ease;
}
.info-row:hover .info-row-bg {
    stroke: rgb(96, 165, 250);
    stroke-width: 1px;
}
.info-row:hover .info-divider {
    stroke: rgb(96, 165, 250);
    stroke-width: 1px;
}
.info-row.is-selected .info-row-bg {
    stroke: rgb(96, 165, 250);
    stroke-width: 1px;
}
.info-row.is-selected .info-divider {
    stroke: rgb(96, 165, 250);
    stroke-width: 1px;
}

.section-header {
    text-align: center;
    margin-bottom: 40px;
}

.section-title {
    font-size: 2em;
    color: var(--text-primary);
    margin-bottom: 15px;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.section-description {
    font-size: 1.1em;
    color: var(--text-secondary);
    max-width: 800px;
    margin: 0 auto 20px;
    line-height: 1.6;
}

/* =========================
   Controls Section (Vis1)
   ========================= */
.controls-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    border-bottom: 1px solid var(--border);
}

.income-control,
.timeline-control {
    padding: 15px;
    border-right: 1px solid var(--border);
}

/* Narrative text sections between visualizations */
.narrative-text {
    /* Limit width and center the narrative block for better readability */
    max-width: 960px;
    margin: 20px auto;
    text-align: center;
    padding: 40px 24px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.narrative-text h3 {
    font-size: 1.8em;
    color: #2d3748;
    font-weight: 600;
    margin: 0;
    line-height: 1.4;
}

/* Narrative "before" visualization - introduces upcoming content */
.narrative-before {
    margin-top: 60px;
    margin-bottom: 30px;
    background: rgba(72, 187, 120, 0.08);
}

/* Narrative "after" visualization - takeaway/insight from previous */
.narrative-after {
    margin-top: 30px;
    margin-bottom: 60px;
    background: rgba(74, 144, 226, 0.08);
}

/* Placeholder styles for other visualizations */
.vis-placeholder {
    background: rgba(255, 255, 255, 0.6);
    border: 2px dashed rgba(74, 85, 104, 0.3);
    border-radius: 10px;
    padding: 60px 20px;
    text-align: center;
    color: #4a5568;
}

.vis-placeholder h3 {
    font-size: 1.5em;
    margin-bottom: 15px;
    color: #2d3748;
}

/* Building Visualization Styles (from original) */
.legend {
    padding: 15px;
    border-right: none;
}

.income-control label,
.timeline-control label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

#income-display,
#quarter-display {
    display: block;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

input[type="range"] {
    width: 100%;
    height: 5px;
    border-radius: 2.5px;
    background: var(--border);
    outline: none;
    cursor: pointer;
    margin: 10px 0 8px;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: 3px solid var(--bg-secondary);
    box-shadow: 0 2px 8px var(--shadow-lg);
    transition: transform 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover { 
    transform: scale(1.2); 
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: 3px solid var(--bg-secondary);
    box-shadow: 0 2px 8px var(--shadow-lg);
    transition: transform 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover { 
    transform: scale(1.2); 
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 5px;
    border-radius: 2.5px;
    background: var(--border);
    border: none;
}

.income-labels,
.timeline-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0 8px;
    margin-top: 8px;
    letter-spacing: -0.01em;
}

.playback-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.control-btn {
    flex: 1;
    padding: 8px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1.5px solid var(--text-primary);
    border-radius: 3px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    letter-spacing: -0.01em;
}

.control-btn:hover { background: var(--text-primary); color: var(--bg-secondary); transform: translateY(-1px); }
.control-btn:active { transform: translateY(0); }
.control-btn.playing { background: var(--text-primary); color: var(--bg-secondary); }

/* =========================
   Legend
   ========================= */
.legend h3 {
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.legend-color {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.legend-note {
    margin-top: 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* =========================
   Map (Vis1)
   ========================= */
.map-container {
    position: relative;
    background: #f9fafb;
    padding: 8px;
    height: 562px;
    max-height: 562px;
    min-height: 562px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 2px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
}

#canada-map { 
    width: 100%; 
    height: 546px; 
    max-height: 546px; 
    min-height: 546px;
}

.province { stroke: #ffffff; stroke-width: 3.1; cursor: pointer; transition: fill 0.2s ease; }
.province:hover { filter: brightness(0.95); }

.cma-marker { stroke: var(--text-primary); cursor: pointer; transition: all 0.2s ease; }
.cma-marker:hover { filter: brightness(1.1); }

.cma-line { stroke: var(--text-primary); stroke-width: 2; stroke-dasharray: 3,3; fill: none; opacity: 0.3; }

.cma-label, .province-label { font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif; text-shadow: 0 0 4px white, 0 0 8px white; pointer-events: none; }
.province-label { font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif; font-size: 14px; font-weight: 700; text-anchor: middle; }
.cma-label { font-size: 11px; }

/* =========================
   Tooltip
   ========================= */
.tooltip {
    position: absolute;
    background: rgba(26,26,26,0.96);
    color: white;
    padding: 20px;
    border-radius: 16px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 0.875rem;
    max-width: 300px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    z-index: 1000;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.1);
}
.tooltip.visible { opacity: 1; }
.tooltip h4 { margin-bottom: 12px; font-size: 1.1rem; font-weight: 600; }
.tooltip p { margin: 8px 0; line-height: 1.6; }

/* =========================
   Info Cards (Vis1)
   ========================= */
.info-section {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 0;
    border-bottom: 1px solid var(--border);
}
.info-card {
    background: var(--bg-secondary);
    padding: 25px 30px;
    border-right: 1px solid var(--border);
    transition: background 0.2s ease;
}
.info-card h3 {
    color: var(--text-secondary);
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    margin-bottom: 18px;
}
.info-card .big-number {
    color: var(--text-primary);
    font-size: 1.6rem;
    font-weight: 700;
}
.info-card .province-name {
    color: var(--text-primary);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.info-card .payment-amount,
.info-card .affordability-text {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 4px;
}
.info-card:last-child { border-right: none; }
.info-card:hover { background: #f8f9fa; }

/* data table (visualization summary) styling */
.data-table-section {
    max-width: 1100px;
    margin: 28px auto 20px;
    padding: 28px 40px;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(248,250,252,0.88) 100%);
    border-radius: 14px;
    border: 1px solid rgba(15,23,42,0.06);
    box-shadow: 0 8px 28px rgba(15,23,42,0.06), 0 1.5px 4px rgba(15,23,42,0.04);
    text-align: center;
}
.data-table-section p {
    line-height: 1.75;
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin: 0;
}
.data-table-section p + p {
    margin-top: 20px;
}

/* Emphasis utilities inside summary sections */
.data-table-section strong,
.data-table-section .highlight {
    color: var(--text-primary);
    font-weight: 700;
}
.data-table-section .stat {
    display: inline;
    background: transparent;
    color: inherit;
    font-weight: 700;
    padding: 0;
    border-radius: 0;
    margin: 0 2px;
}
.surge-text {
    font-size: 12rem;
    font-weight: 700;
    text-align: center;
    text-transform: lowercase;
    color: var(--text-primary);
    margin: 0;
    padding: 80px 20px;
    letter-spacing: 0.02em;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}
.table-wrapper { overflow-x: auto; border-radius: 4px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--bg-secondary); }
thead { background: #f8f9fa; border-bottom: 2px solid var(--border); }
th { padding: 16px 20px; font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.8px; color: var(--text-secondary); }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.2s ease; }
tbody tr:hover { background: #f8f9fa; }
td { padding: 16px 20px; color: var(--text-primary); font-size: 0.938rem; }

/* =========================
   Vis3 Building Visualization
   ========================= */
.legend-box.occupied {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
}

.legend-box.vacant {
    background: #e2e8f0;
}

#buildings-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 25px;
    flex-wrap: wrap;
    padding: 40px 20px;
    min-height: 500px;
}

.city-building {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: transform 0.3s ease;
}

.smoke-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chimney {
    width: 35px;
    background: linear-gradient(135deg, #8b5a3c 0%, #654321 100%);
    border-radius: 5px 5px 0 0;
    position: relative;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #4a3421;
}

.chimney::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    height: 10px;
    background: #a0714f;
    border-radius: 3px;
    border: 2px solid #4a3421;
}

.chimney-dollar {
    color: #f39c12;
    font-weight: bold;
    font-size: 1.2em;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    z-index: 1;
}

.building {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    border-radius: 0 0 5px 5px;
    padding: 15px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    border: 3px solid #2d3748;
    border-top: none;
    position: relative;
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.windows-grid {
    display: grid;
    gap: 8px;
    width: 100%;
}
.window { width: 35px; height: 35px; border: 2px solid #2d3748; border-radius: 3px; }
.window.occupied { background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%); box-shadow: 0 0 12px rgba(237,137,54,0.5); }
.window.vacant { background: #e2e8f0; box-shadow: inset 0 0 5px rgba(0,0,0,0.1); }

.city-label {
    text-align: center;
    padding: 10px;
    background: rgba(255,255,255,0.9);
    border-radius: 5px;
    min-width: 150px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.city-label.high-vacancy {
    background: rgba(72,187,120,0.15);
}

.high-vacancy-badge {
    display: none;
}

.city-name { font-weight: bold; font-size: 1.1em; margin-bottom: 5px; color: #1a365d; }
.city-stats { font-size: 0.85em; color: #4a5568; line-height: 1.4; }
.rent-label { font-size: 0.75em; color: #4a5568; text-align: center; margin-top: 5px; }

/* Keep these from your original Vis3 CSS */
.legend-box {
    width: 20px;
    height: 20px;
    border: 2px solid #4a5568;
}

.legend-box.occupied {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
}

.legend-box.vacant {
    background: #e2e8f0;
}

/* Specific Vis3 legend layout */
.vis3-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: nowrap;       /* don’t wrap like Vis5 */
    background: transparent; /* remove Vis5 background/shadow/padding */
    padding: 0;
    box-shadow: none;
}

.vis3-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #2d3748;
}


.area {
  opacity: 0.7;
  clip-path: url(#clip);
}
.area:hover {
  opacity: 1;
}
/* =========================
   Income Rent Visualization
   ========================= */

.year-slider .form-range {
    accent-color: #6c757d;
}

.year-slider .form-range::-webkit-slider-thumb {
    background-color: #6c757d;
}

.year-slider .form-range::-moz-range-thumb {
    background-color: #6c757d;
}

.year-slider .form-range::-ms-thumb {
    background-color: #6c757d;
}

.year-slider .form-range {
    background-color: transparent;
}

.year-slider .form-range::-webkit-slider-runnable-track {
    background-color: #b4b4b4;
}

.year-slider .form-range::-moz-range-track,
.year-slider .form-range::-moz-range-progress {
    background-color: #b4b4b4;
}

.year-slider .form-range::-ms-track,
.year-slider .form-range::-ms-fill-lower,
.year-slider .form-range::-ms-fill-upper {
    background-color: #b4b4b4;
}

.city-card .city-card-bg,
.city-card .bachelor-block,
.city-card .onebr-block,
.city-card .twobr-block,
.city-card .threebr-block {
    stroke: #ffffff;
    stroke-width: 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.city-card.is-hovered .city-card-bg,
.city-card.is-hovered .bachelor-block,
.city-card.is-hovered .onebr-block,
.city-card.is-hovered .twobr-block,
.city-card.is-hovered .threebr-block {
    stroke: var(--text-primary);
    stroke-width: 1;
    filter: brightness(0.95);
}


.city-card.is-focused .city-card-bg,
.city-card.is-focused .bachelor-block,
.city-card.is-focused .onebr-block,
.city-card.is-focused .twobr-block,
.city-card.is-focused .threebr-block {
    stroke: #000000;
    stroke-width: 2;
}

.city-card.is-secondary .city-card-bg,
.city-card.is-secondary .bachelor-block,
.city-card.is-secondary .onebr-block,
.city-card.is-secondary .twobr-block,
.city-card.is-secondary .threebr-block {
    stroke: #000000;
    stroke-width: 2;
    stroke-dasharray: 5;
}

#vis4-rentinfo .rent-info-wrapper {
    background-color: transparent;
    border: none;
    padding: 0;
    max-width: 240px;
    min-width: 0;
    margin: 0 auto;
    text-align: left;
    position: relative;
    z-index: 0;
}

#vis4-container {
    position: relative;
    z-index: 1;
}

#vis4-rentinfo .rent-info-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#vis4-rentinfo .rent-info-legend-card {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #f3f4f6;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}
#vis4-rentinfo .rent-info-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: #1f2937;
}
#vis4-rentinfo .rent-info-legend-item {
    font-size: 0.82rem;
    color: #1f2937;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
#vis4-rentinfo .rent-info-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    display: inline-block;
    border: 1px solid rgba(17, 24, 39, 0.2);
}
#vis4-rentinfo .rent-info-legend-text {
    font-weight: 600;
    color: #111827;
}

#vis4-rentinfo .rent-info-card-row,
#vis4-rentinfo .graph-prompt-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: flex-start;
    align-items: stretch;
}
#vis4-rentinfo .rent-info-content > .rent-info-card {
    align-self: stretch;
}

#vis4-rentinfo .rent-info-card {
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    min-width: 0;
    max-width: 100%;
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#vis4-rentinfo .rent-info-card-title {
    font-weight: 700;
    color: #0f172a;
    font-size: 0.9rem;
}

#vis4-rentinfo .rent-info-card p {
    margin: 0;
    color: #1f2937;
    font-size: 0.85rem;
    line-height: 1.4;
}

#vis4-rentinfo .rent-info-card p + p {
    margin-top: 4px;
}

#vis4-rentinfo .rent-info-card-primary {
    border-left: 3px solid #2563eb;
}

#vis4-rentinfo .rent-info-card-secondary {
    border-left: 3px solid #4b5563;
}

#vis4-rentinfo .rent-info-card-change {
    border-left: 3px solid #059669;
}
#vis4-rentinfo .rent-info-card.flash {
    animation: rentinfo-flash 0.6s ease;
}

@keyframes rentinfo-flash {
    0% { box-shadow: 0 0 0 rgba(37, 99, 235, 0.35); }
    30% { box-shadow: 0 0 12px rgba(37, 99, 235, 0.45); }
    100% { box-shadow: 0 0 0 rgba(37, 99, 235, 0); }
}

#vis4-rentinfo .rent-info-card-empty {
    border-style: dashed;
    border-color: #d1d5db;
    color: #6b7280;
    align-items: center;
    text-align: center;
    font-size: 0.85rem;
}

#vis4-rentinfo .graph-prompt-card {
    border-style: dashed;
    border-color: #d1d5db;
    color: #6b7280;
    align-items: center;
    text-align: center;
    flex: 0 0 auto;
    font-size: 0.85rem;
}

#vis4-rentinfo .graph-prompt-title {
    font-weight: 600;
    color: #000000;
    font-size: 0.95rem;
    color: #4b5563;
    margin-bottom: 8px;
}
/* =========================
   Footer
   ========================= */
footer {
    text-align: center;
    padding: 18px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-top: 2px solid var(--border);
    background: #f9fafb;
    font-style: italic;
}

/* =========================
   Responsive Breakpoints
   ========================= */
@media (max-width: 1400px) {
    .controls-section { grid-template-columns: repeat(2,1fr); }
    .legend { border-right: none; border-top: 1px solid var(--border); grid-column: 1 / -1; }
    .info-section { grid-template-columns: 1fr; }
    .info-card { border-right: none; border-bottom: 1px solid var(--border); }
    .info-card:last-child { border-bottom: none; }
}

@media (max-width: 1024px) {
    body { padding: 20px; }
    .container { border-radius: 16px; }
    h1 { font-size: 2.25rem; }
    .controls-section { grid-template-columns: 1fr; }
    .income-control,.timeline-control,.legend { border-right:none; border-bottom:1px solid var(--border); }
    .legend { border-bottom:none; }
}

@media (max-width: 768px) {
    header { padding: 40px 30px; }
    h1 { font-size: 1.875rem; }
    .subtitle { font-size: 0.938rem; }
    #canada-map { height: 546px; max-height: 546px; min-height: 546px; }
    .income-control,.timeline-control,.legend,.info-card { padding: 30px; }
    .data-table-section { padding: 40px 30px; }
    #buildings-container { gap: 20px; padding: 20px 10px; }
    .window { width: 28px; height: 28px; }
    .legend { gap: 15px; }
}

@media (max-width: 480px) {
    body { padding: 10px; }
    .container { border-radius: 12px; }
    h1 { font-size: 1.5rem; }
    #canada-map { height: 546px; max-height: 546px; min-height: 546px; }
    .income-control,.timeline-control,.legend,.info-card { padding: 24px; }
    th, td { padding: 12px 16px; font-size: 0.875rem; }
}

#map {
    position: relative;
    width: 100%;
    height: 1000px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: visible;
}

#map svg {
    display: block;
}

/* Timeline styles */
.timeline-container {
    user-select: none;
}

.year-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.year-btn:active {
    transform: translateY(0);
}

/* Line chart styles */
.line-chart-container {
    max-height: 600px;
    overflow-y: auto;
}

.housing-toggle:hover {
    transform: scale(1.05);
}

.housing-toggle:active {
    transform: scale(0.98);
}

/* styling for the map and its button controls in the 4th visualization */

.rentalpricemap-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 6px 10px;
    width: 40px;
    height: 40px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.15s ease, transform 0.06s ease;
    color: #333;
}
.rentalpricemap-btn:hover {
    background: #f0f0f0;
}

.rentalpricemap-btn:active {
    transform: translateY(1px);
}

.rentalpricemap-btn.deselect-btn {
    width: 130px;
    height: 50px;
    font-size: 13px;
    padding: 8px 14px;
}

.zoom-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
    font-weight: 700;
    color: #333;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.zoom-btn.reset {
    font-size: 12px;
}

.map-controls {
    align-items: flex-start;
}

.map-controls .rentalpricemap-btn {
    width: 40px; 
}

.map-controls .rentalpricemap-btn.deselect-btn {
    width: 130px;
}

/* =========================
   Visualization 3 Filter Styles (Enhanced by Burak)
   ========================= */
.filters-container {
    display: grid;
    grid-template-columns: 2fr 0.8fr 1fr 1fr auto;
    grid-auto-rows: auto;
    column-gap: 20px;
    row-gap: 12px;
    margin-bottom: 35px;
    padding: 28px 32px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
}

/* Specific override for population/rent chart filters */
#vis5-filters-container {
    grid-template-columns: 1.5fr repeat(4, minmax(160px, 1fr)) auto;
    background: white;
    padding: 30px 35px;
    box-shadow: none;
    border: none;
}

.filter-labels-row {
    display: contents;
}

.filter-label-item {
    flex: 1;
    min-width: 180px;
    width: 100%;
    align-self: end;
}

.label-text {
    font-weight: 600;
    font-size: 0.85em;
    color: #4a5568;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    padding-left: 0;
    margin-bottom: 8px;
    display: block;
}

.filter-label-location {
    flex: 1.5;
    min-width: 250px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.filter-label-button {
    min-width: auto;
    flex: 0;
}

.filter-inputs-row {
    display: contents;
}

.filter-input-item {
    flex: 1;
    min-width: 180px;
    width: 100%;
    align-self: start;
}

.filter-input-location {
    flex: 1.5;
    min-width: 250px;
}

.filter-input-button {
    min-width: auto;
    flex: 0;
}

.city-selector-container {
    position: relative;
    width: 100%;
}

.selector-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: none;
    border-radius: 8px;
    overflow: visible;
    background: #f1f5f9;
}

.selector-tab {
    padding: 6px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #64748b;
}

.selector-tab:hover {
    background: #e2e8f0;
    color: #334155;
}

.selector-tab.active {
    background: #48bb78;
    color: white;
    box-shadow: 0 2px 4px rgba(72, 187, 120, 0.3);
}

.province-select {
    width: 100%;
    height: 44px;
    padding: 0 44px 0 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.2s ease;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%234a5568" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 16px center;
}

.province-select:hover {
    border-color: #48bb78;
    background-color: #f7fafc;
}

.province-select:focus {
    outline: none;
    border-color: #48bb78;
    box-shadow: 0 0 0 4px rgba(72, 187, 120, 0.12);
    background-color: white;
}

.city-search-input {
    width: 100%;
    height: 44px;
    padding: 0 40px 0 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.2s ease;
    background: white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%23718096" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><path d="m21 21-4.35-4.35"></path></svg>') no-repeat right 16px center;
}

.city-search-input:hover {
    border-color: #cbd5e0;
    background-color: #f7fafc;
}

.city-search-input:focus {
    outline: none;
    border-color: #48bb78;
    box-shadow: 0 0 0 4px rgba(72, 187, 120, 0.12);
    background-color: white;
}

.city-search-input::placeholder {
    color: #a0aec0;
}

.selected-cities {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 20px;
    margin-top: 5px;
    grid-column: 1 / -1;
}

.selected-city-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #48bb78;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s ease;
}

.selected-city-tag:hover {
    background: #38a169;
}

.selected-city-tag .remove-city {
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2em;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.selected-city-tag .remove-city:hover {
    opacity: 1;
}

.city-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-top: 6px;
    max-height: 290px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.city-dropdown::-webkit-scrollbar {
    width: 8px;
}

.city-dropdown::-webkit-scrollbar-track {
    background: #f7fafc;
}

.city-dropdown::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.city-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.city-list {
    padding: 8px;
}

.city-option {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.city-option:hover {
    background: #f7fafc;
}

.city-option .city-province {
    color: #718096;
    font-size: 0.85em;
    font-weight: 500;
}

.city-option.selected {
    background: #e6fffa;
    font-weight: 600;
    color: #2f855a;
}

.city-option.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f7fafc;
}

.city-option.disabled:hover {
    background: #f7fafc;
    transform: none;
}

.dropdown-header {
    padding: 8px 12px;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.8em;
    color: #718096;
    font-weight: 600;
}

.province-group-header {
    padding: 6px 12px;
    background: #edf2f7;
    font-size: 0.75em;
    color: #4a5568;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.filter-select {
    width: 100%;
    height: 44px;
    padding: 0 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    color: #2d3748;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%234a5568" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 44px;
}

.filter-select:hover {
    border-color: #48bb78;
    background-color: #f7fafc;
}

.filter-select:focus {
    outline: none;
    border-color: #48bb78;
    box-shadow: 0 0 0 4px rgba(72, 187, 120, 0.12);
    background-color: white;
}

.reset-btn {
    height: 44px;
    padding: 0 28px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(72, 187, 120, 0.25);
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
    letter-spacing: -0.01em;
}

.reset-btn:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.35);
    transform: translateY(-1px);
}

.reset-btn:active {
    transform: translateY(0px);
    box-shadow: 0 2px 6px rgba(72, 187, 120, 0.25);
}

.filter-count {
    text-align: center;
    padding: 15px;
    margin: 10px 0 20px 0;
    font-size: 1.1em;
    font-weight: 600;
    color: #2d3748;
    background: rgba(72, 187, 120, 0.1);
    border-left: 4px solid #48bb78;
    border-radius: 6px;
}

/* Carousel styles for Vis 3 */
.buildings-carousel {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.buildings-viewport {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 30px 20px;
    scroll-snap-type: x mandatory;
    scroll-padding-left: 1px;
    scroll-padding-right: 1px;
    scroll-behavior: smooth;
}

.buildings-viewport::-webkit-scrollbar {
    height: 8px;
}

.buildings-viewport::-webkit-scrollbar-track {
    background: #edf2f7;
    border-radius: 999px;
}

.buildings-viewport::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 999px;
}

.buildings-viewport::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Override buildings-container for carousel */
#buildings-container {
    display: flex;
    justify-content: flex-start;
    align-items: flex-end;
    gap: 25px;
    flex-wrap: nowrap;
    padding: 20px 10px;
    min-height: 520px;
}

.carousel-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #edf2f7;
    color: #2d3748;
    font-size: 1.5em;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.carousel-btn:hover:not(:disabled) {
    background: #e2e8f0;
    transform: translateY(-2px);
}

.carousel-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

.vacancy-wrapper {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(240px, 0.7fr);
    gap: 24px;
    align-items: stretch;
    width: 100%;
}

.vacancy-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 10px;
    align-items: end;
}

.vacancy-legend-bar {
    margin-bottom: 10px;
}

.vacancy-control label {
    display: block;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 6px;
}

.vacancy-control input[type="range"] {
    width: 100%;
}

.vacancy-control select {
}

.vacancy-year-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #718096;
    margin-top: 4px;
}

.vacancy-left {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}

.vacancy-left .buildings-viewport {
    max-height: none;
    overflow-y: visible;
}

.vacancy-info-panel {
    background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px 22px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.vacancy-info-panel h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1a365d;
}

.vacancy-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    font-size: 0.95rem;
    color: #4a5568;
}

.vacancy-stat strong {
    font-size: 1.05rem;
    color: #2d3748;
}

.vacancy-note {
    margin: 0;
    font-size: 0.9rem;
    color: #718096;
}

.vacancy-city-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vacancy-scale {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    background: #edf2f7;
    margin-bottom: 10px;
}

.vacancy-scale-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
}

.vacancy-window-empty {
    width: 20px;
    height: 20px;
    border: 1.2px solid #1a202c;
    border-radius: 3px;
    background: #5f5244;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.15), 0 1px 2px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.vacancy-scale .label {
    font-size: 0.85rem;
    color: #4a5568;
}

.vacancy-scale .value {
    font-weight: 700;
    color: #1a365d;
}

.vacancy-scale .note {
    font-size: 0.8rem;
    color: #718096;
}

@media (max-width: 900px) {
    .vacancy-wrapper {
        grid-template-columns: 1fr;
    }
}

.vacancy-city-row {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    background: #ffffff;
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) repeat(3, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
    overflow-wrap: anywhere;
    min-height: 68px;
}

.vacancy-city-row .name {
    font-weight: 700;
    color: #1a365d;
}

.vacancy-city-row .label {
    font-size: 0.85rem;
    color: #4a5568;
}

.vacancy-city-row .value {
    font-weight: 600;
    color: #2d3748;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}

.vacancy-estimate-tag {
    font-size: 0.65rem;
    color: #718096;
    font-weight: 500;
    margin-left: 4px;
}

.vacancy-empty {
    width: 100%;
    text-align: center;
    color: #718096;
    padding: 80px 20px;
    border: 1px dashed #cbd5e0;
    border-radius: 12px;
    background: #f7fafc;
}

.vacancy-city-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.vacancy-city-btn {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #2d3748;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.vacancy-city-btn:hover {
    border-color: #cbd5e0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.vacancy-city-btn.active {
    background: #ebf8ff;
    border-color: #63b3ed;
    color: #1a365d;
    box-shadow: 0 4px 12px rgba(99, 179, 237, 0.25);
}

.city-building {
    flex: 0 0 auto;
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

/* Responsive Design for Vis 3 Filters */
@media (max-width: 768px) {
    .filters-container {
        display: flex;
        flex-direction: column;
        padding: 20px;
        gap: 20px;
    }

    .filter-labels-row,
    .filter-inputs-row {
        display: flex;
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
        width: 100%;
    }

    .filter-label-item,
    .filter-input-item,
    .selected-cities {
        min-width: 100%;
        width: 100%;
        grid-column: auto;
    }

    .filter-label-location,
    .filter-input-location {
        min-width: 100%;
    }

    .filter-label-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .filter-select {
        font-size: 0.9em;
        padding: 10px 14px;
    }

    .selected-city-tag {
        font-size: 0.8em;
        padding: 5px 10px;
    }

    .city-dropdown {
        max-height: 200px;
    }

    .selector-tab {
        padding: 9px 18px;
        font-size: 0.85em;
    }

    .reset-btn {
        padding: 10px 20px;
        font-size: 0.9em;
        width: 100%;
    }

    .buildings-carousel {
        gap: 10px;
    }

    .carousel-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2em;
    }
}

:root {
            --folder-color: #e5e7eb; /* Light grey for official look */
            --tab-color: #d1d5db;
            --active-tab-color: #ffffff; /* White Paper */
            --page-color: #ffffff;
            --border-color: #9ca3af;
            --shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            --folder-margin: 10px; /* Define the gap size */

            /* Corner bend specific colors */
            --corner-size: 50px; /* Size of the bend */
            --corner-color: #d1d5db; /* Color of the bent-over part (grey) */
            --corner-shadow: rgba(0, 0, 0, 0.2); /* Shadow */
        }

        /* Allows main browser scrollbar */
        html, body {
            margin: 0;
            
        }

/* --- CRITICAL FIX: ABSOLUTE WIDTH STABILITY --- */
/* Remove 'overflow-y: scroll' from HTML if it was there */

#folder-container {
    position: relative; 
    
    /* Revert to wide percentage for dynamic size */
    width: 95%; 
    max-width: 1400px; 
    
    /* CRITICAL: Remove fixed height and overflow: hidden */
    height: auto; /* Let content dictate height */
    min-height: 50vh; /* Minimum height ensures it's visible */
    overflow: visible; /* Allows content to push height without internal scroll */
    
    /* Centering remains based on margin: auto */
    margin: 5vh auto; 
    
    display: flex;
    flex-direction: column;
    transform: perspective(1000px) rotateX(1deg); 
    box-sizing: border-box;

    background-color: var(--folder-color); 
    padding: var(--folder-margin); 
    border: 1px solid var(--border-color); 
    border-radius: 4px;
}
    /* --- TAB BAR STYLING (Margin Management) --- */
    #tab-bar {
        display: flex;
        gap: 0;
        z-index: 2;
        position: relative;
        padding-left: 20px;
        background-color: transparent;
        border-bottom: 2px solid var(--border-color);

        /* Margin still needs to compensate for container padding */
        margin-top: calc(-1 * var(--folder-margin)); 
        margin-left: calc(-1 * var(--folder-margin));
        margin-right: calc(-1 * var(--folder-margin));
        
        /* CRITICAL: Width must be 100% of the fixed container plus margins */
        width: calc(100% + (2 * var(--folder-margin)));
        padding-right: calc(var(--folder-margin) * 2);
        box-sizing: border-box;
    }

        .tab {
            padding: 10px 24px;
            background-color: var(--tab-color);
            border: 1px solid var(--border-color);
            border-bottom: none;
            border-radius: 4px 4px 0 0;
            cursor: pointer;
            font-weight: 600;
            color: #4b5563;
            user-select: none;
            margin-right: -1px;
            font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
            font-size: 0.9rem;
            letter-spacing: -0.01em;
        }

        .active-tab {
            background-color: var(--active-tab-color);
            color: #000;
            border-color: var(--border-color);
            z-index: 3;
            transform: translateY(-2px);
            box-shadow: 0 -3px 5px rgba(0, 0, 0, 0.1);
            font-weight: 700;
        }

    /* 2. FOLDER PAGE STYLING (The White Paper) */
    #folder-page {
        /* Set flex-grow to 0 so the container height is determined by the content */
        flex-grow: 0; 
        
        position: relative; 
        background-color: var(--page-color);
        border: 1px solid var(--border-color);
        border-top: none; 
        padding: 30px;
        box-shadow: var(--shadow);
        z-index: 1;
        
        overflow: visible;
        
        /* Enable 3D transforms for page flip */
        transform-style: preserve-3d;
        transition: transform 0.5s ease, opacity 0.3s ease;
        transform: perspective(2000px) rotateY(0deg);
        backface-visibility: hidden;
        opacity: 1;
        /* Required to make Flexbox work */
        display: flex;
        /* Centers children horizontally along the main axis */
        justify-content: center-top;
        /* Centers children vertically along the cross axis */
        align-items: center;
        /* Stacks children vertically instead of side-by-side */
        flex-direction: column;

        /* Keep existing styles */
        
    }
    
    #folder-page.flipping {
        opacity: 0;
        transition: transform 0.5s ease, opacity 0.2s ease;
    }

    /* The illusion of the yellow folder behind the white paper (NO CHANGE) */
    #folder-page::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: transparent; 
        border: none;
        z-index: -1; 
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }

            /* 3. VISUALIZATION AREA STYLING (NO CHANGE) */
    .content {
        display: none; 
        padding: 10px;
        height: auto; /* Content dictates size */
        box-sizing: border-box;
        border: 1px dashed #eee; 
    }

    .content.active {
        display: block; 
    }

        :root {
            /* Ensure these variables are correctly defined in your main :root block */
            --page-color: #ffffff;
            --corner-color: #e0e0e0;
            --corner-shadow: rgba(0, 0, 0, 0.3);
            --bend-size: 50px; 
        }

        .page-corner-bend {
            position: absolute;
            bottom: 0;
            right: 0;
            z-index: 10;
            cursor: grab;
            transition: all 0.3s ease-in-out;
            user-select: none; 
            
            /* 1. Create the main triangle shape using borders */
            width: 0;
            height: 0;
            border-style: solid;
            --bend-size: 50px; 

            /* CRITICAL: Border colors define the fold appearance (bottom-right fold) */
            /* bottom = folded color (grey) */
            /* right = page color (white) */
            border-width: 0 0 var(--bend-size) var(--bend-size);
            border-color: transparent transparent var(--corner-color) var(--page-color);
            
            /* Apply shadow for depth */
            box-shadow: -5px 5px 10px var(--corner-shadow);
        }

        /* --- HOVER EFFECT --- */
        .page-corner-bend:hover {
            /* Slightly increase the bend size */
            --bend-size: 60px;
            /* Update the border width based on the new bend size */
            border-width: 0 0 var(--bend-size) var(--bend-size);
            /* Make the shadow more pronounced */
            box-shadow: -8px 8px 15px var(--corner-shadow);
        }

   
        .page-corner-bend-left {
            position: absolute;
            bottom: 0;
            left: 0; /* Positioned on the left side */
            z-index: 10;
            cursor: grab;
            width: 0; /* Set to 0 for border triangle */
            height: 0;
            transition: all 0.3s ease-in-out;
            user-select: none; 
            
            /* Inherit the size variable */
            --bend-size: 50px; 
            border-style: solid;
            

            border-width: 0 var(--bend-size) var(--bend-size) 0;
            border-color: transparent var(--page-color) var(--corner-color) transparent;
            
            /* Shadow falls to the bottom-right of the fold (correct for left corner) */
            box-shadow: 5px 5px 10px var(--corner-shadow); 
        }

        /* We don't need a separate ::after element */

        /* HOVER EFFECT FOR LEFT CORNER */
        .page-corner-bend-left:hover {
            --bend-size: 60px; /* Increase size on hover */
            border-width: 0 var(--bend-size) var(--bend-size) 0;
            box-shadow: 8px 8px 15px var(--corner-shadow);
        }
        

/* Container for the Button */
#vis5-legend {
    /* Anchors the container to the bottom-left of the parent */
    position: absolute; 
    bottom: 0;
    left: 0;
    
    position: relative; 
    /* Use 'em' for padding so it scales with text size */
    padding: 0.8em 1em; 
    z-index: 999; 
    height: auto; 
}

/* The Toggle Button */
#legend-toggle-button {
    /* Use 'em' for padding for better scaling */
    padding: 0.5em 1em;
    font-size: 1em; /* Baseline text size */
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1001;
}

/* The Expanded Overlay Legend Container */
#expanded-legend-overlay {
    /* CRITICAL ALIGNMENT: Must match vis5-legend's bottom/left offset (padding) */
    position: absolute;
    bottom: 0.8em; 
    left: 1em; 
    
    /* REDUCED WIDTH: Adjusting to 35% of the parent width for desktop/larger screens */
    width: 35%; 
    /* Set max-width to a reasonable pixel limit for very large screens */
    max-width: 450px; 
    max-height: 80vh; /* Responsive height */
    
    background-color: white;
    border: 1px solid #333;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    padding: 1.5em; 
    /* We keep overflow-y: auto for vertical scroll if content is too tall */
    overflow-y: auto;
    /* Remove overflow-x property or set to hidden if you're certain it shouldn't scroll horizontally */
    overflow-x: hidden; /* Added this to ensure no horizontal scrollbar appears */
    z-index: 1000; 
    display: none; 
}

/* Responsive adjustment for small screens */
@media (max-width: 600px) {
    #expanded-legend-overlay {
        /* On small screens, keep it wide enough to be useful, but cap it */
        width: 80%; 
        max-width: none; /* Remove max-width limit on small screens */
        bottom: 0.5em;
        left: 0.5em;
    }
}

/* Close Button CSS (Remains the same) */
#close-legend-button {
    position: absolute; 
    top: 10px;
    right: 10px;
    padding: 5px 10px;
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1002;
}

/* Captions */
mark {
  background-color: #fff2ac;
}


.caption {
    font-size: 1em;
    color: #000000;
    text-align: center;
}
