:root {
    --bg-dark: #1a1a1a;
    --glass-bg: rgba(20, 20, 20, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #eab308;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --header-height: 60px;
    --pill-height: 50px;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 16px;
    pointer-events: none;
    /* Let clicks pass through to map where no UI exists */
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    pointer-events: auto;
    /* Re-enable clicks */
    color: var(--text-primary);
    transition: all 0.3s ease;
}

#settings-sheet {
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 80vh;
    overflow-y: auto;
}

/* Utility Classes */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex !important;
    }

    .desktop-only {
        display: none !important;
    }

    #settings-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
        z-index: 2000;
        padding-bottom: 40px;
        /* Safe area */
    }

    #settings-sheet.open {
        transform: translateY(0);
    }

    #sheet-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1900;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    body.sheet-open #sheet-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
}

.sheet-handle {
    display: none;
    width: 48px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    align-self: center;
    margin-bottom: 6px;
}

.sub-card {
    padding: 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    border: 1px solid var(--glass-border);
}

.header-row h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

select,
input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

select:focus,
input:focus {
    border-color: var(--accent-color);
}

.control-group {
    position: relative;
}

#searchButton {
    position: absolute;
    right: 4px;
    top: 24px;
    /* Align with input */
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

#searchButton:hover {
    color: var(--text-primary);
}

#updateBtn {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

#updateBtn:hover {
    background: var(--accent-hover);
}

#updateBtn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.status-message {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    border-top: 1px solid var(--glass-border);
    padding-top: 12px;
}

.status-message.error {
    color: var(--danger-color);
}

#legend-panel {
    width: 280px;
    padding: 12px 16px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
}

#legend-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#legend-content.hidden {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

#info-panel {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 240px;
    z-index: 1000;
    max-width: 350px;
    max-height: 400px;
    overflow-y: auto;
}

#info-panel h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
}

#info-panel p {
    margin: 4px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Leaflet Dark Mode Overrides (Optional, for map tiles if we want to invert them) */
/* For now, we'll keep standard tiles but maybe dim them slightly */
.leaflet-layer {
    filter: brightness(0.8) contrast(1.2) grayscale(0.2);
}

#top-deals-panel {
    width: 280px;
    padding: 16px;
}

#top-deals-panel .header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}

#top-deals-panel h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#top-deals-panel .subtitle {
    font-size: 11px;
    color: var(--text-secondary);
}

.deal-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--glass-border);
    font-size: 13px;
}

.deal-item:last-child {
    border-bottom: none;
}

.deal-country {
    font-weight: 500;
    color: var(--text-primary);
}

.deal-value {
    font-weight: 600;
    color: var(--success-color);
}

.deal-code {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.secondary-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    width: 400px;
    max-width: 90%;
    background: var(--bg-dark);
    /* Solid background for readability */
    border: 1px solid var(--glass-border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 12px;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.modal-body {
    line-height: 1.6;
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-body p {
    margin-bottom: 12px;
}

.modal-body strong {
    color: var(--text-primary);
}

#baseCurrencyBadge {
    position: absolute;
    bottom: 20px;
    left: 20px;
    padding: 12px 16px;
    z-index: 1000;
    min-width: 120px;
}

.badge-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.badge-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-color);
}

#info-panel {
    max-width: 350px;
    max-height: 400px;
    overflow-y: auto;
}

#info-panel img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 12px;
}

#info-panel h4 {
    margin: 0 0 8px 0;
    font-size: 20px;
}

#info-panel .wiki-extract {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

#info-panel .wiki-link {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 12px;
}

#info-panel .wiki-link:hover {
    text-decoration: underline;
}

.deal-item {
    cursor: pointer;
    transition: background 0.2s;
}

.deal-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mode-toggle {
    display: flex;
    gap: 8px;
}

.mode-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

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

.col-index-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.col-index-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 10px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
}

.col-index-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.col-index-btn.active {
    background: linear-gradient(135deg, var(--accent-color), #667eea);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.data-attribution {
    font-size: 11px;
    color: var(--text-secondary);
    padding-top: 8px;
    border-top: 1px solid var(--glass-border);
    margin-top: 8px;
}

.hidden {
    display: none !important;
}

/* Mobile Specific Components */
#mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    box-sizing: border-box;
}

.header-title {
    font-weight: 600;
    font-size: 16px;
}

#status-pill {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 12px 24px;
    z-index: 900;
    font-weight: 500;
    font-size: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.2s;
}

#status-pill:active {
    transform: translateX(-50%) scale(0.95);
}

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

.sheet-header h2 {
    margin: 0;
    font-size: 18px;
}

/* Mobile Responsive Overrides */
@media (max-width: 768px) {

    body,
    html {
        overflow: hidden;
    }

    #ui-layer {
        position: fixed;
        inset: 0;
        padding: 0;
        pointer-events: none;
        z-index: 2000;
    }

    /* Allow clicking on the sheet when it's open */
    #settings-sheet {
        pointer-events: auto;
    }

    .sheet-handle {
        display: block;
        margin: 0 auto 12px;
    }

    #time-currency-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .col-index-buttons {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 6px;
        /* Hide scrollbar for cleaner look */
        scrollbar-width: none;
        /* Firefox */
        -ms-overflow-style: none;
        /* IE/Edge */
    }

    .col-index-buttons::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    .col-index-btn {
        min-width: 90px;
        white-space: nowrap;
    }

    #info-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        /* Hidden by default */
        transition: transform 0.3s ease;
        z-index: 1500;
        /* Below settings sheet */
        margin: 0;
        display: block !important;
        /* Override inline display none */
    }

    #info-panel.visible {
        transform: translateY(0);
    }

    /* Hide status pill when info panel or settings are open */
    body.sheet-open #status-pill,
    body.info-open #status-pill {
        opacity: 0;
        pointer-events: none;
    }
}