/* History Styles V4.1 - Vertical Card Stats */

.history-container { padding-top: 20px; max-width: 1200px; margin: 0 auto; }

.history-header {
    background: #fff; padding: 20px; border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08); margin-bottom: 20px;
}

.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.history-header h1 { margin: 0; color: #2c3e50; font-size: 1.5rem; }

.lang-switcher { display: flex; gap: 10px; }
.lang-flag { cursor: pointer; opacity: 0.5; transition: 0.2s; border: 1px solid #ddd; border-radius: 3px; width: 24px; }
.lang-flag:hover, .lang-flag.active { opacity: 1; transform: scale(1.15); box-shadow: 0 2px 5px rgba(0,0,0,0.2); }

.controls-wrapper { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
select, .btn-primary, .btn-secondary { padding: 8px 12px; border-radius: 6px; border: 1px solid #ddd; font-size: 14px; background: #fff; cursor: pointer; }
.btn-primary { background: #3498db; color: white; border: none; cursor: pointer; }
.btn-primary:hover { background: #2980b9; }
.btn-secondary { background: #ecf0f1; color: #333; text-decoration: none; display: inline-block; }

/* ========== COMPARISON TOGGLE ========== */
.comparison-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: #f8f9fa;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
}

.toggle-label {
    font-size: 13px;
    color: #555;
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #3498db;
}

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

/* ========== CARDS GRID ========== */
.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.history-card {
    background: #fff; border-radius: 12px; padding: 15px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06); border: 1px solid #f0f0f0;
    display: flex; flex-direction: column;
}

.history-card h3 { 
    margin: 0 0 10px 0; 
    font-size: 1.1rem; 
    color: #444; 
    border-bottom: 1px solid #f8f8f8; 
    padding-bottom: 8px; 
}

/* ========== STATS ROW ========== */
.stats-row {
    margin-bottom: 12px;
    font-size: 0.85rem;
    color: #666;
    min-height: 28px;
}

.stats-row .no-data {
    color: #999;
    font-style: italic;
}

/* ========== SIMPLE STATS (No Comparison) ========== */
.stats-simple {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stats-simple .stat-box {
    background: #f8f9fa;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #eee;
    font-size: 0.85rem;
}

.stats-simple .stat-box.max { color: #e74c3c; border-left: 3px solid #e74c3c; }
.stats-simple .stat-box.avg { color: #27ae60; border-left: 3px solid #27ae60; }
.stats-simple .stat-box.min { color: #3498db; border-left: 3px solid #3498db; }

/* ========== VERTICAL STAT CARDS (With Comparison) ========== */
.stats-cards-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 100px;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card.max { border-top: 3px solid #e74c3c; }
.stat-card.avg { border-top: 3px solid #27ae60; }
.stat-card.min { border-top: 3px solid #3498db; }

.stat-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    padding-bottom: 4px;
    border-bottom: 1px dashed #eee;
}

.stat-card-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
}

.stat-card-row .year-badge {
    background: #3498db;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 36px;
    text-align: center;
}

.stat-card-row.previous .year-badge {
    background: #95a5a6;
}

.stat-card-row .value {
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.9rem;
}

.stat-card-row .label {
    color: #888;
    font-size: 0.7rem;
}

.stat-card-diff {
    text-align: center;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-top: 2px;
}

.stat-card-diff.positive {
    background: rgba(39, 174, 96, 0.15);
    color: #27ae60;
}

.stat-card-diff.negative {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

/* ========== CHART AREA ========== */
.chart-container { position: relative; height: 250px; width: 100%; }

.chart-legend { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    gap: 20px; 
    margin-top: 10px; 
    font-size: 0.85rem; 
    color: #555; 
    padding-top: 8px; 
    border-top: 1px dashed #eee; 
}

.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-color { width: 12px; height: 12px; display: inline-block; }
.legend-color.line-solid { background: #3498db; border-radius: 50%; }
.legend-color.line-dashed { border-bottom: 2px dashed #95a5a6; width: 16px; height: 0; margin-top: 6px; }

/* ========== WIND ROSE ========== */
.wind-rose-wrapper { 
    width: 100%; 
    aspect-ratio: 1 / 1; 
    max-height: 350px; 
    margin: 0 auto; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    position: relative; 
}

#chart-windrose { 
    width: auto !important; 
    height: auto !important; 
    max-width: 100%; 
    max-height: 100%; 
}

/* ========== DARK MODE ========== */
body.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

body.dark-mode .history-header,
body.dark-mode .history-card {
    background-color: #1e1e1e;
    color: #e0e0e0;
    border: 1px solid #333;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3 {
    color: #ffffff;
    border-bottom-color: #333;
}

body.dark-mode .stats-simple .stat-box {
    background-color: #2d2d2d;
    border-color: #444;
}

body.dark-mode .stat-card {
    background: linear-gradient(135deg, #252525 0%, #1e1e1e 100%);
    border-color: #444;
}

body.dark-mode .stat-card-title {
    color: #aaa;
    border-bottom-color: #444;
}

body.dark-mode .stat-card-row .value {
    color: #fff;
}

body.dark-mode .stat-card-row .label {
    color: #888;
}

body.dark-mode .stat-card-diff.positive {
    background: rgba(39, 174, 96, 0.25);
    color: #51cf66;
}

body.dark-mode .stat-card-diff.negative {
    background: rgba(231, 76, 60, 0.25);
    color: #ff6b6b;
}

body.dark-mode .comparison-toggle {
    background: #2d2d2d;
    border-color: #444;
}

body.dark-mode .toggle-label {
    color: #ccc;
}

body.dark-mode select,
body.dark-mode .btn-secondary,
body.dark-mode .btn-primary {
    background-color: #2d2d2d;
    color: #fff;
    border: 1px solid #444;
}

body.dark-mode .btn-primary:hover {
    background-color: #3d3d3d;
}

body.dark-mode .chart-legend {
    color: #aaa;
    border-top-color: #333;
}

body.dark-mode::-webkit-scrollbar-track { background: #121212; }
body.dark-mode::-webkit-scrollbar-thumb { background: #444; }

/* ========== MOBILE RESPONSIVE ========== */
@media (max-width: 900px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .history-container {
        width: 100% !important;
        max-width: none !important;
        padding: 8px !important;
        margin: 0 !important;
        overflow-x: hidden;
    }

    .history-header {
        padding: 12px;
        border-radius: 8px;
    }

    .history-header h1 {
        font-size: 1.2rem;
    }

    .controls-wrapper {
        gap: 6px;
    }

    select, .btn-primary, .btn-secondary {
        padding: 6px 10px;
        font-size: 13px;
    }

    .comparison-toggle {
        padding: 3px 8px;
    }

    .toggle-label {
        font-size: 12px;
    }

    .toggle-switch {
        width: 38px;
        height: 20px;
    }

    .toggle-slider:before {
        height: 14px;
        width: 14px;
    }

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

    .history-container .history-card,
    .card {
        max-width: unset !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
        border-radius: 8px !important;
        padding: 12px;
    }

    .cards-grid {
        display: block !important;
        gap: 12px;
    }

    .cards-grid .history-card {
        margin-bottom: 12px;
    }

    .chart-container {
        width: 100% !important;
        padding: 0 !important;
        height: 220px;
    }

    /* Stat cards on mobile - still horizontal but smaller */
    .stats-cards-container {
        gap: 6px;
    }

    .stat-card {
        min-width: 80px;
        padding: 8px;
        gap: 4px;
    }

    .stat-card-title {
        font-size: 0.65rem;
    }

    .stat-card-row {
        font-size: 0.7rem;
        gap: 4px;
    }

    .stat-card-row .year-badge {
        padding: 1px 4px;
        font-size: 0.6rem;
        min-width: 30px;
    }

    .stat-card-row .value {
        font-size: 0.8rem;
    }

    .stat-card-row .label {
        font-size: 0.6rem;
    }

    .stat-card-diff {
        font-size: 0.65rem;
        padding: 3px 6px;
    }

    .chart-legend {
        gap: 12px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .history-header h1 {
        font-size: 1rem;
    }

    .controls-wrapper {
        justify-content: center;
    }

    /* Very small screens: stack cards vertically */
    .stats-cards-container {
        flex-direction: column;
        gap: 8px;
    }

    .stat-card {
        min-width: unset;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
    }

    .stat-card-title {
        width: 100%;
        text-align: left;
        padding-bottom: 6px;
        margin-bottom: 4px;
    }

    .stat-card-row {
        flex: 1;
    }

    .stat-card-diff {
        margin-top: 0;
        margin-left: auto;
    }
}

/* ========== LANDSCAPE PHONE ========== */
@media (max-height: 500px) and (orientation: landscape) {
    .chart-container {
        height: 180px;
    }

    .stat-card {
        padding: 6px 8px;
    }

    .stat-card-row .value {
        font-size: 0.75rem;
    }
}
