/*
 * styles.css — All styling for the European virus surveillance map.
 *
 * Structure:
 *   1. Reset & base           – Universal reset, body/html.
 *   2. Sidebar layout         – Grid layout (topbar + map).
 *   3. Top bar                – Logo, virus buttons, search, Karta toggle.
 *   4. Map & overlays         – Map container, loading indicator, info boxes.
 *   5. ECDC source box        – Timestamp, license, mobile expand/collapse.
 *   6. Modals                 – Changelog and feedback dialogs.
 *   7. Mobile overrides       – @media (max-width: 768px) responsive rules.
 *
 * Naming: BEM-ish where practical. Mobile breakpoint: 768px.
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ========== LAYOUT (Google Maps-style) ==========
   Active when body has class "layout-sidebar".
   ========== */

/* Layout wrapper: topbar on row 1, sidebar+map on row 2 */
.layout-sidebar .layout-topbar-wrap {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr;
    height: 100vh;
    overflow: hidden;
}

.layout-sidebar .layout-main {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    min-height: 0;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom);
}

.layout-sidebar .layout-main #map {
    min-height: 0;
    position: relative;
    top: auto !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    max-width: none;
}

/* Top bar: full width, contains mode switcher, virus toggles, checkboxes */
.app-topbar {
    position: relative;
    width: 100%;
    min-height: 72px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    z-index: 1;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    padding-top: max(10px, env(safe-area-inset-top));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.topbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px 24px;
}

.app-topbar .mode-switcher {
    margin: 0;
    padding: 0;
    padding-right: 24px;
    border-right: 1px solid #e0e0e0;
    border-bottom: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.app-topbar .mode-toggle {
    display: flex;
    gap: 4px;
    background: #f5f5f5;
    border-radius: 6px;
    padding: 0;
    padding-right: 12px;
    margin-right: 12px;
    border-right: 1px solid #e0e0e0;
}

.app-topbar .mode-toggle button {
    padding: 6px 10px;
    font-size: 12px;
    height: 32px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-topbar .mode-toggle-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    box-sizing: border-box;
}

.app-topbar .mode-switcher .mode-toggle-logo-img {
    height: 32px;
    width: auto;
    display: block;
    vertical-align: middle;
}

.app-topbar .mode-switcher img {
    position: static;
    width: 23px;
    height: auto;
    margin-right: 6px;
    vertical-align: middle;
}

.app-topbar .mode-switcher .mode-switcher-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-right: 8px;
    vertical-align: middle;
}

/* Desktop: separator and wrapper hidden */
.app-topbar .mode-switcher-separator {
    display: none;
}
.app-topbar .mode-switcher-right {
    display: contents;
}

.app-topbar .disease-toggle {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.app-topbar .toggle-btn {
    min-width: 0;
    padding: 6px 12px;
    font-size: 12px;
    height: 32px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-topbar .checkboxes-wrapper {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.app-topbar .checkboxes-wrapper .checkbox-label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    margin: 0;
}

.app-topbar .checkboxes-wrapper input[type="checkbox"] {
    margin: 0;
}

.app-topbar .changelog-link-btn,
.app-topbar .feedback-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 13px;
    color: #1976d2;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}

.app-topbar .changelog-link-btn:hover,
.app-topbar .feedback-link-btn:hover {
    background: #f5f5f5;
    color: #1565c0;
}

.app-topbar .changelog-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}

.app-topbar .changelog-link-icon svg {
    display: block;
}

/* Search in topbar */
.app-topbar .topbar-search {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-topbar .topbar-search .search-input-wrapper {
    display: flex;
    gap: 0;
    margin: 0;
}

.app-topbar .topbar-search input {
    width: 180px;
    max-width: 200px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px 0 0 4px;
    font-size: 14px;
}

.app-topbar .topbar-search input:focus {
    outline: none;
    border-color: #a50f15;
}

.app-topbar .topbar-search button {
    padding: 6px 12px;
    background: #a50f15;
    color: white;
    border: none;
    border-radius: 0 4px 4px 0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.app-topbar .topbar-search button:hover {
    background: #8a0d12;
}

/* Zoom slot (mobile only) */
.app-topbar .topbar-zoom-wrap {
    display: none;
}

/* Virusfall aggregate box */
.app-topbar .disease-toggle .virusfall-aggregate-box {
    padding: 0 12px;
    height: 32px;
    box-sizing: border-box;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-topbar .disease-toggle .virusfall-aggregate-box.active {
    background: #a50f15;
    color: white;
    border-color: #a50f15;
}

.app-topbar .topbar-search #virusInfo {
    max-width: 200px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    display: none;
}

/* Search is in topbar; ECDC timestamp stays absolute over the map */

.layout-sidebar #ecdcTimestamp {
    left: max(10px, env(safe-area-inset-left)) !important;
    bottom: max(10px, env(safe-area-inset-bottom));
}

@media (max-width: 768px) {
    .layout-sidebar .layout-main {
        grid-template-columns: 1fr;
    }
    .layout-sidebar .app-topbar {
        padding-left: max(16px, env(safe-area-inset-left));
        min-height: 0;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .layout-sidebar #ecdcTimestamp {
        left: 10px !important;
        bottom: 8px !important;
    }
    /* Mobile topbar: row 1 = logo, row 2 = virus buttons (2x2), row 3 = search + Karta toggle */
    .app-topbar .topbar-row {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 8px 10px;
        align-items: center;
    }
    .app-topbar .mode-switcher {
        grid-column: 1 / -1;
        grid-row: 1;
        padding-right: 12px;
        margin-right: 0;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 8px;
        justify-content: flex-start;
    }
    .app-topbar .mode-switcher .mode-toggle {
        flex: 1;
        padding-right: 0;
        margin-right: 0;
        border-right: none;
        justify-content: flex-end;
    }
    .app-topbar .mode-switcher-separator {
        display: block;
        width: 1px;
        height: 24px;
        background: #e0e0e0;
        margin: 0 12px;
        flex-shrink: 0;
        position: relative;
        left: -8px;
    }
    .app-topbar .mode-switcher-right {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-left: 8px;
    }
    .app-topbar .topbar-zoom-wrap {
        display: none !important;
    }
    .app-topbar .topbar-search {
        grid-column: 1;
        grid-row: 3;
        margin-left: 0;
        min-width: 0;
        display: flex;
        flex: 1;
    }
    .app-topbar .topbar-search .search-input-wrapper {
        display: flex;
        flex: 1;
        min-width: 0;
    }
    .app-topbar .topbar-search input {
        flex: 1;
        min-width: 0;
        max-width: none;
    }
    .app-topbar .topbar-search button {
        flex-shrink: 0;
    }
    .app-topbar .checkboxes-wrapper {
        display: contents;
    }
    .app-topbar .karta-checkbox-wrap {
        grid-column: 2;
        grid-row: 3;
        align-self: center;
    }
    .app-topbar .checkboxes-wrapper .checkbox-label {
        white-space: nowrap;
        margin: 0;
    }
    #changelogBtn,
    #feedbackBtn {
        display: none;
    }
    .app-topbar .disease-toggle {
        grid-column: 1 / -1;
        grid-row: 2;
        margin: 0;
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 6px;
    }
    .app-topbar .disease-toggle .virusfall-aggregate-box {
        grid-column: 1;
        grid-row: 1;
        font-size: 11px;
        white-space: normal;
        line-height: 1.2;
        padding: 4px 6px;
    }
    .app-topbar .disease-toggle .toggle-btn:nth-of-type(1) {
        grid-column: 2;
        grid-row: 1;
    }
    .app-topbar .disease-toggle .toggle-btn:nth-of-type(2) {
        grid-column: 1;
        grid-row: 2;
    }
    .app-topbar .disease-toggle .toggle-btn:nth-of-type(3) {
        grid-column: 2;
        grid-row: 2;
    }
    .app-topbar .disease-toggle .toggle-btn {
        min-width: 0;
        padding: 6px 4px;
        font-size: 11px;
        text-align: center;
        white-space: normal;
        line-height: 1.2;
    }
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
}

.disease-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.toggle-btn {
    flex: 1;
    min-width: 90px;
    padding: 8px 10px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-btn:hover {
    border-color: #a50f15;
    color: #a50f15;
}

.toggle-btn.active {
    background: #a50f15;
    color: white;
    border-color: #a50f15;
}

.hover-info {
    position: absolute;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1;
    min-width: 250px;
    display: none;
    pointer-events: none;
}

.hover-info.visible {
    display: block;
}

.hover-info h3 {
    font-size: 16px;
    margin-bottom: 8px;
    color: #333;
}

.hover-info .stat {
    font-size: 13px;
    color: #666;
    margin: 4px 0;
}

.hover-info .stat strong {
    color: #333;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.search-popup {
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 250px;
    word-wrap: break-word;
    line-height: 1.4;
}

.search-popup .popup-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0,0,0,0.1);
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-popup .popup-close:hover {
    background: rgba(0,0,0,0.2);
}

.search-popup .popup-content {
    padding-right: 20px;
}

/* Tablet styles */
@media (max-width: 1024px) {
    .hover-info {
        max-width: calc(50vw - 20px);
    }
    
    .loading {
        padding: 15px 30px;
        font-size: 14px;
    }
}

/* Mobile overrides for overlays */
@media (max-width: 768px) {
    .hover-info {
        max-width: calc(100vw - 40px);
        min-width: 200px;
        padding: 12px;
        font-size: 12px;
    }
    
    .hover-info h3 {
        font-size: 14px;
    }
    
    .hover-info .stat {
        font-size: 11px;
    }
    
    #ecdcTimestamp {
        margin-bottom: 0 !important;
    }
    
    .loading {
        padding: 15px 30px;
        font-size: 14px;
        max-width: calc(100vw - 40px);
    }
}

/* Hide compass/rotation button on all screen sizes and make zoom control shorter */
/* Hide compass button */
.maplibregl-ctrl-compass {
    display: none !important;
}

/* Make zoom control shorter by removing space for compass */
.maplibregl-ctrl-group {
    height: auto !important;
    min-height: auto !important;
}

/* Remove border from last button (zoom out) since compass is hidden */
.maplibregl-ctrl-group button:last-of-type {
    border-bottom: none !important;
}

/* Ensure zoom buttons take up less space */
.maplibregl-ctrl-zoom-in,
.maplibregl-ctrl-zoom-out {
    height: 29px !important;
}

/* Keep tile attribution visible in bottom-right of map */
.maplibregl-ctrl-attrib {
    z-index: 2;
    pointer-events: auto;
}
.maplibregl-ctrl-attrib a {
    color: #333;
}

/* ECDC source box: desktop = always expanded, mobile = compact with expandable details */
.ecdc-header-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ecdc-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #1976d2;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}
.ecdc-info-icon:hover {
    background: #1565c0;
}
.ecdc-info-icon svg {
    display: block;
}

/* Plain-text ECDC label hidden by default (shown in mobile collapsed state) */
.ecdc-source-text .ecdc-plain {
    display: none;
}

/* Desktop: license inline with ECDC header, no info icon, license row in details hidden */
@media (min-width: 769px) {
    .ecdc-timestamp-box .ecdc-details {
        display: block;
    }
    .ecdc-timestamp-box .ecdc-info-icon {
        display: none !important;
    }
    .ecdc-timestamp-box .ecdc-details .ecdc-details-source {
        display: none;
    }
}

/* Mobile: plain ECDC label + info icon; expanded state shows link in details */
@media (max-width: 768px) {
    .ecdc-timestamp-box .ecdc-license-inline {
        display: none;
    }
    .ecdc-source-text .ecdc-link {
        display: none;
    }
    .ecdc-source-text .ecdc-plain {
        display: inline;
    }
    .ecdc-timestamp-box .ecdc-details {
        display: none;
        margin-top: 8px;
    }
    .ecdc-timestamp-box.ecdc-expanded .ecdc-details {
        display: block;
    }
}

@media (pointer: coarse) {
    .app-topbar .mode-toggle button,
    .app-topbar .toggle-btn,
    .app-topbar .disease-toggle .virusfall-aggregate-box,
    .app-topbar .topbar-search button,
    .app-topbar .changelog-link-btn,
    .app-topbar .feedback-link-btn {
        min-height: 44px;
        padding: 10px 14px;
    }
    .app-topbar .topbar-search input {
        min-height: 44px;
    }
}

/* Small mobile styles */
@media (max-width: 480px) {
    .toggle-btn {
        min-width: 60px;
        font-size: 9px;
        padding: 5px 4px;
    }
    
    .mode-toggle button {
        font-size: 10px;
        padding: 5px 6px;
    }
    
    .disease-toggle {
        gap: 6px;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#lastChangeText:hover {
    color: #1565c0 !important;
}

/* Feedback-modal */
.feedback-modal-close {
    background: #f5f5f5;
    border: none;
    border-radius: 4px;
    padding: 8px 14px;
    font-size: 16px;
    color: #666;
    cursor: pointer;
}
.feedback-modal-close:hover {
    background: #e0e0e0;
}
.feedback-btn {
    padding: 8px 18px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}
.feedback-btn-cancel {
    background: #f5f5f5;
    color: #333;
}
.feedback-btn-cancel:hover {
    background: #eee;
}
.feedback-btn-send {
    background: #1976d2;
    color: white;
}
.feedback-btn-send:hover {
    background: #1565c0;
}
