/* styles.css */
html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* Prevent scrolling */
    font-family: 'Roboto', sans-serif;
    background: #fff;
}

/* Header */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    z-index: 100;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logo-container img {
    height: 40px;
    /* Adjust based on SVG aspect ratio */
    display: block;
}

.maps-btn {
    background: #0000ff;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
}

/* Modal */
.modal-backdrop {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    overscroll-behavior: none;
}

.modal-backdrop.visible {
    display: flex;
}

.modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    position: relative;
    max-width: 80%;
    width: 80%;
    max-height: 90%;
    overflow: hidden;
    /* Allow touch events on buttons while preventing scroll */
    overscroll-behavior: none;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-content h2,
.modal-content h3 {
    font-size: 2.5rem;
    /* Significantly larger title */
    margin-top: 10px;
    margin-bottom: 20px;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    background: none;
    border: none;
    font-weight: bold;
    z-index: 10;
}

/* Generic modal image (e.g. about page) */
.modal-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 20px;
}

/* About Text Specific */
.modal-content.text-content {
    text-align: left;
}

/* Install Prompt Modal */
.modal-content.install-prompt-content {
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content.install-prompt-content h2 {
    color: #ff0000;
    font-size: 1.3rem;
    margin-bottom: 16px;
    text-align: center;
}

.modal-content.install-prompt-content h3 {
    color: #0000ff;
    font-size: 1.1rem;
    margin: 20px 0 10px;
}

.modal-content.install-prompt-content p {
    margin: 12px 0;
    line-height: 1.6;
}

.install-instructions {
    background: #f0f0f0;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.install-instructions ol {
    margin: 12px 0;
    padding-left: 24px;
}

.install-instructions li {
    margin: 8px 0;
    line-height: 1.6;
}

.install-note {
    background: #e3f2fd;
    border-left: 4px solid #0000ff;
    padding: 12px;
    margin: 16px 0;
    font-size: 0.95rem;
}

/* PWA Install Tip (top-right of Maps modal in browser mode) */
.pwa-install-tip {
    display: none;
    position: absolute;
    top: 50px;
    right: 10px;
    width: 240px;
    background: #fff;
    border: 2px solid #0000ff;
    border-radius: 8px;
    padding: 12px 16px 12px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 15;
    text-align: left;
    font-size: 13px;
    line-height: 1.4;
}

.pwa-install-tip.visible {
    display: block;
}

.install-tip-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    font-weight: bold;
    color: #666;
    line-height: 1;
    padding: 2px 4px;
}

.pwa-install-tip h4 {
    margin: 0 0 6px 0;
    color: #0000ff;
    font-size: 14px;
    font-weight: 700;
}

.pwa-install-tip p {
    margin: 0 0 6px 0;
    font-size: 13px;
}

.pwa-install-tip ol {
    margin: 0;
    padding-left: 18px;
}

.pwa-install-tip li {
    margin: 4px 0;
    line-height: 1.5;
    font-size: 12px;
}

/* Legend Specific: Fixed centered modal — must come AFTER generic .modal-content img */
.modal-content.legend-content {
    height: 80%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

.modal-content.legend-content img {
    width: auto;
    max-width: 100%;
    max-height: calc(100% - 70px);
    /* 100% of modal height minus title + margins */
    object-fit: contain;
    margin: 0 auto;
}

/* Welcome Card (first visit) */
.welcome-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.welcome-overlay.visible {
    display: flex;
}

.welcome-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px 20px;
    max-width: 320px;
    width: 85%;
    text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.welcome-card h2 {
    font-size: 1.3rem;
    color: #0000ff;
    margin: 0 0 14px;
    text-align: center;
}

.welcome-card p {
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    margin: 0 0 12px;
}

.welcome-got-it-btn {
    display: block;
    width: 100%;
    background: #0000ff;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 12px;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 16px;
}

/* Map Container */
#map {
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    right: 0;
}

/* Move bottom-right controls up and away from edge for easier tapping */
#map .maplibregl-ctrl-bottom-right {
    right: 12px;
    bottom: 80px;
}

/* Legend control button — match Mapbox GL control appearance */
#legend-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 29px;
    height: 29px;
    padding: 0;
    border: none;
    background: #fff;
    cursor: pointer;
}

/* MAPS Modal */
.maps-modal-content {
    max-width: 360px;
    width: 90%;
    padding: 24px 20px 32px;
    text-align: center;
}

.maps-modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin: 0 0 24px;
    color: #0000ff;
}

.maps-nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.maps-nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: #fff;
    border: 2px solid #0000ff;
    border-radius: 6px;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: #0000ff;
    cursor: pointer;
    text-align: left;
}

.maps-nav-btn:disabled {
    cursor: default;
    opacity: 0.85;
}

.maps-nav-btn svg {
    flex-shrink: 0;
}

/* Content Page (About) */
.page-content {
    margin-top: 80px;
    /* Below header */
    padding: 20px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* Maps Sub-screens */
.maps-subscreen-content {
    max-width: 90%;
    width: 90%;
    max-height: 85vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.modal-back-btn {
    position: absolute;
    top: 12px;
    left: 15px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
}

.maps-subscreen-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: #0000ff;
    text-align: center;
}

.maps-subscreen-subtitle {
    font-size: 0.8rem;
    color: #999;
    text-align: center;
    margin: 0 0 16px;
    line-height: 1.4;
}

/* Maps Nearby */
.nearby-regions-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 80px;
}

.loading-text {
    text-align: center;
    color: #666;
    margin-top: 20px;
}

/* Fallback notice when location unavailable */
.fallback-notice {
    background: #f0f0f0;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    text-align: center;
}

.fallback-notice p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Loading spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #0000ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.region-card {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.region-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.region-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
}

.region-size {
    font-size: 0.9rem;
    color: #666;
}

.region-distance {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 4px;
}

.download-btn {
    background: #0000ff;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 10px 16px;
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.download-btn:disabled {
    cursor: not-allowed;
}

/* Download button states */
.download-btn.downloading {
    --progress: 0%;
    background: linear-gradient(to right, #5bc534 var(--progress), #e0e0e0 var(--progress));
    color: #fff;
}

.download-btn.downloading span {
    position: relative;
    z-index: 1;
    color: #fff;
}

.download-btn.saved {
    background: #5bc534;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.download-btn.saved .open-btn {
    flex: 1;
    padding: 12px 16px;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
}

.download-btn.saved .delete-btn {
    padding: 10px 12px;
    color: #ff0000;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    border-left: 1px solid #ddd;
}

.download-btn.saved .open-btn:hover {
    background: #e8f5e9;
}

.download-btn.saved .delete-btn:hover {
    background: #ffebee;
}

/* Bottom bar download classes removed - all download progress now happens in-button */

/* Maps View - Split Screen Layout */
.maps-view-content {
    max-width: 95%;
    width: 95%;
    height: 85vh;
    max-height: 85vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: visible; /* Override .modal-content's overflow: hidden to enable child scrolling */
}

.maps-view-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 16px;
    color: #0000ff;
    text-align: center;
    flex-shrink: 0;
}

.maps-view-split-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 16px;
}

.maps-view-map-half {
    position: relative;
    width: 100%;
    flex: 0 0 45%;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #0000ff;
}

.maps-view-regions-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.maps-view-region-card {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    margin: 0 12px 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.maps-view-region-card:last-child {
    margin-bottom: 16px;
}

.maps-view-region-card:hover {
    border-color: #0000ff;
}

.maps-view-region-card.selected {
    border-color: #0000ff;
    background: #f0f0ff;
}

.maps-view-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

/* Collapsible Attribution Control */
.attribution-control {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .1);
    font-size: 11px;
    line-height: 1.4;
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
}

.attribution-toggle {
    background: none;
    border: none;
    cursor: pointer;
    width: 29px;
    height: 29px;
    padding: 0;
    color: #333;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attribution-text {
    display: none;
    color: #666;
    font-size: 10px;
    line-height: 1.3;
    padding: 4px 0 4px 8px;
    white-space: nowrap;
}

.attribution-control.expanded .attribution-text {
    display: block;
}

/* ── Custom Area Download Screen ─────────────────────────────────── */
.custom-download-content {
    max-width: 95%;
    width: 95%;
    height: 90vh;
    max-height: 90vh;
    padding: 10px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
}

.custom-download-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.custom-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0000ff;
    flex-shrink: 0;
}

.custom-download-content .custom-download-title {
    font-size: 1rem;
    font-weight: 700;
    color: #0000ff;
    margin: 0;
    white-space: nowrap;
    line-height: 1.2;
}

.custom-name-row {
    flex-shrink: 0;
}

.custom-area-name-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
}

.custom-area-name-input:focus {
    border-color: #0000ff;
}

.custom-area-name-input.input-error {
    border-color: #ff0000;
}

.custom-area-name-input.input-error::placeholder {
    color: #ff0000;
}

.custom-map-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #0000ff;
}

.custom-map-container {
    width: 100%;
    height: 100%;
}

/* Dashed blue rectangle overlay — matches "+ Download Custom Area" card style */
.custom-bbox-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 50%;
    border: 3px dashed #0000ff;
    background: rgba(0, 0, 255, 0.12);
    pointer-events: none;
    z-index: 10;
    box-sizing: border-box;
}

/* Crosshair at center */
.custom-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 11;
}

.custom-crosshair::before,
.custom-crosshair::after {
    content: '';
    position: absolute;
    background: #0000ff;
}

.custom-crosshair::before {
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    transform: translateY(-50%);
}

.custom-crosshair::after {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    transform: translateX(-50%);
}

/* Estimate text */
.custom-estimate {
    text-align: center;
    font-size: 14px;
    color: #666;
    flex-shrink: 0;
    min-height: 20px;
}

/* Download action button */
.custom-download-action-btn {
    flex-shrink: 0;
    margin-bottom: 24px;
}

/* "Download Custom Area" card in region list */
.custom-area-card {
    background: #fff;
    border: 2px dashed #0000ff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.custom-area-card:hover {
    background: #f0f0ff;
}

.custom-area-card-text {
    color: #0000ff;
    font-weight: 700;
    font-size: 15px;
}

.empty-maps-message {
    text-align: center;
    color: #999;
    font-size: 14px;
    padding: 24px 16px;
    line-height: 1.5;
}

/* Map Title Overlay (for opened saved maps) */
.map-title-overlay {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #0000ff;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 16px;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: pointer;
}

/* Version badge — bottom-left, subtle, safe-area aware */
.app-version {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: calc(16px + env(safe-area-inset-left, 0px));
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-family: 'Roboto', sans-serif;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.3px;
    z-index: 50;
    pointer-events: none;
    user-select: none;
}