/* STREACS Project - Main Styles */

:root {
    /* Color palette for market structure codes */
    --color-1a: #d73027; /* VIU State-owned - Dark Red */
    --color-1b: #fc8d59; /* VIU Private - Orange */
    --color-2a: #fee090; /* SBM with gen - Light Yellow */
    --color-2b: #e0f3f8; /* SBM without gen - Light Blue */
    --color-3a: #91bfdb; /* Wholesale bilateral - Medium Blue */
    --color-3b: #4575b4; /* Wholesale pool - Dark Blue */
    --color-3c: #74add1; /* Wholesale cost-based - Light Blue */
    --color-3d: #313695; /* Wholesale bid-based - Navy */
    --color-4a: #abd9e9; /* Retail partial - Cyan */
    --color-4b: #2c7bb6; /* Retail full - Deep Blue */
    --color-none: #cccccc; /* No data - Gray */

    /* UI Colors */
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --background: #f5f7fa;
    --card-bg: #ffffff;
    --text-color: #2c3e50;
    --border-color: #e1e8ed;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.main-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 30px 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.main-header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

/* Panels */
.panel {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    margin: 30px 0;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
}

.panel h2 {
    font-size: 1.8em;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 3px solid var(--secondary-color);
    padding-bottom: 10px;
}

.panel h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
    color: var(--primary-color);
}

/* Timeline Controls */
.timeline-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 25px;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
}

.timeline-controls label {
    font-weight: 600;
    font-size: 1.1em;
}

#current-year {
    color: var(--secondary-color);
    font-weight: bold;
    font-size: 1.3em;
    margin-left: 10px;
}

#year-slider {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    outline: none;
    background: linear-gradient(to right, var(--secondary-color) 0%, var(--accent-color) 100%);
}

#year-slider::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--secondary-color);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#play-btn {
    padding: 10px 25px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background 0.3s;
}

#play-btn:hover {
    background: #2980b9;
}

/* Map Mode Toggle */
.map-mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid var(--secondary-color);
    margin-left: 10px;
}

.mode-btn {
    padding: 10px 25px;
    background: transparent;
    color: var(--secondary-color);
    border: none;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
    background: var(--secondary-color);
    color: white;
}

.mode-btn:not(.active):hover {
    background: rgba(52, 152, 219, 0.1);
}

/* World Map */
#world-map {
    width: 100%;
    height: 600px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: #f0f8ff;
}

#world-map svg {
    display: block;
}

.country {
    stroke: #fff;
    stroke-width: 0.5;
    cursor: pointer;
    transition: all 0.2s;
}

.country:hover {
    stroke: var(--primary-color);
    stroke-width: 2;
    filter: brightness(1.1);
}

/* Legend */
.legend {
    margin-top: 20px;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
}

#market-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: box-shadow 0.2s, opacity 0.2s;
    border: 2px solid transparent;
}

.legend-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.legend-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 2px 10px rgba(44,62,80,0.25);
}

.legend-item.dimmed {
    opacity: 0.35;
}

.legend-color {
    width: 30px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.legend-label {
    font-size: 0.9em;
    flex: 1;
}

/* Legend country list panel */
#legend-country-list {
    display: none;
    margin-top: 20px;
    padding: 16px 20px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.country-list-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.country-list-code {
    padding: 3px 10px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 1em;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.country-list-count {
    color: #888;
    font-size: 0.9em;
    margin-left: auto;
}

.country-list-close {
    background: none;
    border: none;
    font-size: 1.3em;
    cursor: pointer;
    color: #aaa;
    line-height: 1;
    padding: 0 4px;
}

.country-list-close:hover {
    color: var(--accent-color);
}

.country-list-names {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.country-list-names span {
    padding: 4px 10px;
    background: var(--background);
    border-radius: 4px;
    font-size: 0.88em;
    border: 1px solid var(--border-color);
    cursor: pointer !important;
    transition: background 0.15s, border-color 0.15s;
}

.country-list-names span:hover {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    animation: fadeIn 0.3s;
}

.modal.active {
    display: block;
}

.modal.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 5px 30px rgba(0,0,0,0.3);
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close-btn:hover {
    color: var(--accent-color);
}

#country-name {
    color: var(--primary-color);
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--secondary-color);
}

.country-details {
    display: grid;
    gap: 20px;
}

.detail-section {
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    border-left: 4px solid var(--secondary-color);
    overflow: hidden;
}

.detail-section h3 {
    color: var(--primary-color);
    margin-bottom: 12px;
}

.detail-section canvas {
    max-height: 300px;
    width: 100% !important;
    height: 300px !important;
}

/* Armenia Analysis */
.armenia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
}

.chart-container {
    background: var(--background);
    padding: 20px;
    border-radius: 8px;
}

.chart-container.full-width {
    grid-column: 1 / -1;
}

#armenia-timeline {
    padding: 20px;
}

.timeline-event {
    display: flex;
    margin-bottom: 20px;
    position: relative;
    padding-left: 30px;
}

.timeline-event::before {
    content: '';
    position: absolute;
    left: 0;
    top: 5px;
    width: 12px;
    height: 12px;
    background: var(--secondary-color);
    border-radius: 50%;
}

.timeline-year {
    font-weight: bold;
    color: var(--secondary-color);
    min-width: 60px;
}

.timeline-description {
    flex: 1;
}

/* Comparison Tool */
.comparison-controls {
    margin-bottom: 25px;
}

.country-selector {
    margin-bottom: 20px;
}

#country-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 15px;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.country-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.country-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.btn-primary {
    padding: 12px 30px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #2980b9;
}

.comparison-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 25px;
}

/* Scenarios */
.scenario-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 25px;
}

.scenario-legend, .scenario-info {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid var(--secondary-color);
}

.scenario-legend p, .scenario-info p {
    margin-bottom: 8px;
}

.metrics-box {
    padding: 25px;
    background: var(--background);
    border-radius: 8px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.metric {
    padding: 20px;
    background: white;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.metric label {
    display: block;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.metric span {
    font-size: 1.8em;
    color: var(--secondary-color);
    font-weight: bold;
}

/* Liberalization Mode Button */
.mode-btn--lib {
    border-left: 2px solid var(--secondary-color);
}

.mode-btn--lib.active {
    background: var(--primary-color);
    color: white;
}

/* Liberalization Legend */
.lib-legend {
    margin-top: 20px;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    flex-direction: column;
    gap: 12px;
}

.lib-legend__title {
    font-size: 1em;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 0.03em;
    margin: 0;
}

.lib-legend__scale {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.lib-legend__item {
    display: flex;
    align-items: center;
    gap: 7px;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    color: var(--text-color);
    transition: box-shadow 0.2s;
}

.lib-legend__item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.lib-legend__swatch {
    width: 22px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    flex-shrink: 0;
}

/* Liberalization info block in modal */
.lib-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.lib-info__badge {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2em;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.lib-info__details p {
    margin: 4px 0;
    font-size: 0.95em;
}

.lib-legend__note {
    font-size: 0.8em;
    color: #888;
    margin: 0;
    padding-top: 4px;
    border-top: 1px solid var(--border-color);
}

/* Footer */
.main-footer {
    background: var(--primary-color);
    color: white;
    padding: 30px 0;
    margin-top: 50px;
    text-align: center;
}

.main-footer p {
    margin: 5px 0;
    opacity: 0.9;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-header h1 {
        font-size: 1.8em;
    }

    .panel {
        padding: 20px;
    }

    .armenia-grid,
    .comparison-charts,
    .scenario-grid {
        grid-template-columns: 1fr;
    }

    #world-map {
        height: 400px;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
    }
}

/* Loading State */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 400px;
    font-size: 1.2em;
    color: var(--secondary-color);
}

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

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Armenia Market Intelligence Styles */
.section-subtitle {
    color: #666;
    font-size: 0.95rem;
    margin-top: -10px;
    margin-bottom: 20px;
}

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

.chart-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.chart-controls label {
    font-weight: 500;
    font-size: 0.9rem;
}

.chart-controls select,
.chart-controls input[type="date"] {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.timezone-note {
    font-size: 0.85rem;
    color: #999;
    margin-left: 10px;
}

#aex-mcp-chart {
    max-height: 300px;
}

.d3-container {
    min-height: 600px;
    overflow: auto;
    background: #fafafa;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

#aex-surplus-heatmap {
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.heatmap-tooltip {
    position: absolute;
    background: linear-gradient(135deg, rgba(30, 30, 30, 0.95), rgba(20, 20, 20, 0.98));
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    min-width: 200px;
}

.heatmap-cell {
    transition: opacity 0.2s ease, stroke-width 0.2s ease, stroke 0.2s ease;
}

.heatmap-cell:hover {
    filter: brightness(1.1);
}

/* Rotate Device Overlay */
.rotate-device-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.rotate-device-message {
    text-align: center;
    color: white;
    padding: 30px;
    max-width: 280px;
}

.rotate-icon {
    font-size: 4em;
    margin-bottom: 15px;
    animation: rotateAnimation 2s ease-in-out infinite;
}

@keyframes rotateAnimation {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-15deg); }
    75% { transform: rotate(15deg); }
}

.rotate-device-message p {
    font-size: 1.2em;
    font-weight: bold;
    margin: 10px 0;
}

.rotate-subtitle {
    font-size: 0.9em !important;
    font-weight: normal !important;
    opacity: 0.9;
    line-height: 1.4;
}

/* Show overlay only on mobile portrait mode */
@media (max-width: 768px) and (orientation: portrait) {
    .chart-container:has(#aex-surplus-heatmap) {
        position: relative;
    }

    #aex-surplus-heatmap {
        position: relative;
    }

    .rotate-device-overlay {
        display: flex !important;
    }
}

/* Hide overlay in landscape mode */
@media (orientation: landscape) {
    .rotate-device-overlay {
        display: none !important;
    }
}

/* Rotate Banner - less intrusive */
.rotate-banner {
    display: none;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 15px;
    text-align: center;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.85em;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.rotate-banner-icon {
    font-size: 1.2em;
    animation: wiggle 1s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.rotate-banner-text {
    flex: 1;
    max-width: 600px;
}

.rotate-banner-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.5em;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background 0.3s ease;
}

.rotate-banner-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Show banner only on mobile portrait */
@media (max-width: 768px) and (orientation: portrait) {
    .rotate-banner {
        display: flex !important;
    }
}

/* Hide banner in landscape */
@media (orientation: landscape) {
    .rotate-banner {
        display: none !important;
    }
}

/* Country Search Styles */
.country-search-container {
    position: relative;
    margin-bottom: 15px;
}

.country-search-input {
    width: 100%;
    padding: 10px 40px 10px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

.country-search-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.country-search-input::placeholder {
    color: #999;
}

.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2em;
    pointer-events: none;
    opacity: 0.5;
}

#country-checkboxes {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    background: #fafafa;
}

.country-checkbox-item {
    padding: 8px;
    margin: 4px 0;
    border-radius: 4px;
    transition: background 0.2s ease;
    display: block;
}

.country-checkbox-item:hover {
    background: #e3f2fd;
}

.country-checkbox-item.hidden {
    display: none !important;
}

.navigation-buttons {
    margin-top: 30px;
    text-align: center;
}

.btn-secondary {
    padding: 12px 24px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s ease;
}

.btn-secondary:hover {
    background: #2980b9;
}

/* Responsive adjustments for Market Intelligence */
@media (max-width: 1024px) {
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .chart-controls {
        flex-wrap: wrap;
    }
}

/* ============================================
   MOBILE OPTIMIZATION (All Modules)
   ============================================ */

/* Tablet and below (768px) */
@media (max-width: 768px) {
    /* Typography */
    body {
        font-size: 14px;
    }

    .main-header h1 {
        font-size: 1.8em;
    }

    .main-header .subtitle {
        font-size: 1em;
    }

    /* Containers */
    .container {
        padding: 0 20px;
    }

    .panel {
        padding: 20px;
        margin-bottom: 20px;
    }

    .panel h2 {
        font-size: 1.3em;
    }

    .panel h3 {
        font-size: 1.1em;
    }

    /* Chart containers */
    .chart-container {
        margin-bottom: 25px;
    }

    #aex-mcp-chart {
        max-height: 250px;
    }

    /* D3 heatmap - make scrollable horizontally */
    .d3-container {
        min-height: 400px;
        max-height: 600px;
        padding: 10px;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    .d3-container svg {
        display: block;
        max-width: none !important;
    }

    /* Scenario grid - ensure single column on mobile */
    .scenario-grid {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    .comparison-charts {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    .armenia-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* Controls - stack vertically on mobile */
    .chart-controls {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 10px;
    }

    .chart-controls select,
    .chart-controls input[type="date"] {
        width: 100%;
        padding: 8px;
        font-size: 14px;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    /* Timeline controls */
    .timeline-controls {
        flex-direction: column;
        gap: 10px;
    }

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

    /* Mode toggle — full width, buttons share space equally */
    .map-mode-toggle {
        width: 100%;
        margin-left: 0;
    }

    .mode-btn {
        flex: 1;
        padding: 10px 6px;
        font-size: 0.85em;
    }

    /* Liberalization info badge stacks on mobile */
    .lib-info {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Country modal */
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 15px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content h2 {
        font-size: 1.3em;
    }

    .close-btn {
        font-size: 1.8em;
        top: 5px;
        right: 10px;
    }

    /* Legend - make scrollable */
    .legend {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #market-legend {
        flex-wrap: nowrap;
        min-width: max-content;
    }

    /* Comparison controls */
    .comparison-controls {
        padding: 15px;
    }

    #country-checkboxes {
        max-height: 200px;
        overflow-y: auto;
    }

    /* Buttons */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 12px;
        font-size: 14px;
    }

    .navigation-buttons {
        margin-top: 20px;
    }

    /* Armenia timeline */
    .armenia-milestones {
        padding: 10px;
    }

    .timeline-event {
        padding: 10px;
        margin-bottom: 10px;
    }

    /* Tooltips */
    .heatmap-tooltip {
        font-size: 0.75rem;
        padding: 8px 12px;
        min-width: 150px;
    }

    /* Metrics */
    .forecast-metrics,
    .metrics-grid {
        flex-direction: column;
        gap: 10px;
    }

    .metric-value {
        font-size: 1.1rem;
    }

    /* Forecast grid */
    .forecast-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* Scenario specific fixes */
    .scenario-grid .chart-container {
        width: 100%;
    }

    .scenario-grid canvas {
        max-width: 100%;
    }
}

/* Mobile phones (480px and below) */
@media (max-width: 480px) {
    /* Even smaller typography */
    body {
        font-size: 13px;
    }

    .main-header h1 {
        font-size: 1.8em;
    }

    .mode-btn {
        padding: 8px 4px;
        font-size: 0.78em;
    }

    .panel h2 {
        font-size: 1.2em;
    }

    .panel h3 {
        font-size: 1em;
    }

    /* Reduce padding */
    .container {
        padding: 0 15px;
    }

    .panel {
        padding: 15px;
    }

    /* Chart adjustments */
    #aex-mcp-chart {
        max-height: 200px;
    }

    .d3-container {
        min-height: 300px;
        max-height: 500px;
        padding: 5px;
        overflow: auto;
        width: 100%;
    }

    /* Heatmap - ensure scrollable */
    .d3-container svg {
        max-width: none !important;
        height: auto;
        display: block;
    }

    /* Ensure grids are single column */
    .scenario-grid,
    .comparison-charts,
    .armenia-grid {
        display: flex !important;
        flex-direction: column;
        gap: 15px;
    }

    .chart-container {
        width: 100%;
        margin-bottom: 15px;
    }

    /* Hide some chart elements on very small screens */
    .chart-legend {
        font-size: 0.7em;
    }

    /* Smaller buttons */
    .btn-primary,
    .btn-secondary {
        padding: 10px;
        font-size: 13px;
    }

    /* Timeline */
    .timeline-year {
        font-size: 1em;
    }

    .timeline-description {
        font-size: 0.85em;
    }

    /* Modal adjustments */
    .modal-content {
        width: 98%;
        margin: 2% auto;
        padding: 10px;
    }

    /* Comparison checkboxes */
    .country-selector label {
        font-size: 0.85em;
        padding: 6px;
    }

    /* Scenario info boxes */
    .scenario-legend p,
    .scenario-info p {
        font-size: 0.85em;
    }

    /* Footer */
    .main-footer {
        padding: 15px 10px;
        font-size: 0.85em;
    }
}

/* Very small phones (360px and below) */
@media (max-width: 360px) {
    .main-header h1 {
        font-size: 1.8em;
    }

    .main-header .subtitle {
        font-size: 1em;
    }

    .panel h2 {
        font-size: 1.1em;
    }

    #aex-mcp-chart {
        max-height: 180px;
    }

    .chart-controls select,
    .chart-controls input {
        font-size: 12px;
        padding: 6px;
    }

    .heatmap-tooltip {
        font-size: 0.7rem;
        padding: 6px 10px;
    }

    /* Force single column layout */
    .scenario-grid,
    .comparison-charts,
    .armenia-grid,
    .forecast-grid {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    .chart-container,
    .forecast-item {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Ensure heatmap scrolls properly */
    #aex-surplus-heatmap {
        overflow-x: auto !important;
        overflow-y: auto !important;
        max-width: 100vw;
        padding-right: 10px;
    }
}

/* Portrait orientation - taller MCP chart */
@media (max-width: 768px) and (orientation: portrait) {
    #aex-mcp-chart {
        max-height: 400px !important;
    }
}

@media (max-width: 480px) and (orientation: portrait) {
    #aex-mcp-chart {
        max-height: 450px !important;
    }
}

@media (max-width: 360px) and (orientation: portrait) {
    #aex-mcp-chart {
        max-height: 400px !important;
    }
}

/* Landscape orientation optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 95vh;
        overflow-y: auto;
    }

    .panel {
        padding: 10px;
    }

    #aex-mcp-chart {
        max-height: 150px;
    }

    .d3-container {
        min-height: 250px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap targets */
    button,
    select,
    input,
    a {
        min-height: 44px;
        min-width: 44px;
    }

    .close-btn {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Remove hover effects on touch devices */
    .country:hover,
    .btn-primary:hover,
    .btn-secondary:hover {
        transform: none;
    }

    /* Larger checkboxes */
    input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
}
