/*
 * Phone ergonomics shared by IceReports and BoatRampsMap (loaded after the page's own
 * styles so equal-specificity rules here win).
 *
 * - Touch targets of at least 44px on coarse pointers (zoom control, toolbar buttons,
 *   tabs, legend rows, links in panels).
 * - Form fields at 16px on small screens, so iOS Safari does not zoom the page when
 *   a field gets focus.
 * - Modals become bottom sheets on small screens; marker details open in a bottom
 *   sheet (static/js/mobile.js) instead of a map popup.
 * - Safe-area insets for phones with a notch or home indicator (viewport-fit=cover).
 * - Outdoor readability: bigger marker labels with a halo that holds on any map, and a
 *   high-contrast mode (html[data-contrast="high"], switched in Settings by mobile.js)
 *   with opaque surfaces, solid marker fills and a crisper map, in both themes.
 */

:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --touch: 44px;
}

/* ---- Touch targets ------------------------------------------------------------ */
@media (pointer: coarse) {
    .leaflet-touch .leaflet-bar a,
    .leaflet-bar a {
        width: var(--touch);
        height: var(--touch);
        line-height: var(--touch);
        font-size: 22px;
    }
    .leaflet-touch .leaflet-control-zoom-in,
    .leaflet-touch .leaflet-control-zoom-out { font-size: 22px; }
    .leaflet-control-zoom a { width: var(--touch) !important; height: var(--touch) !important; line-height: var(--touch) !important; font-size: 22px !important; }
    .leaflet-popup-close-button { width: var(--touch) !important; height: var(--touch) !important; font-size: 24px !important; line-height: var(--touch) !important; }

    /* Toolbar and panel buttons */
    .btn-theme, .btn-settings, .btn-offline, .btn-boat-parking, .btn-satellite, .btn-locate,
    .control-btn, .legend-btn { width: var(--touch); height: var(--touch); }
    .tab-btn, .btn-apply, .btn-play, .season-toggle button, .filter-btn, .search-btn, .modal-close,
    .btn-save-offline, .btn-clear-offline, .photo-capture-btn, .btn-flag-report, .btn-edit-report,
    .flag-reason-btn, .btn-cancel-delete, .btn-confirm-delete, .season-select, .date-input,
    .legend-item.filterable, .disclaimer-link { min-height: var(--touch); }
    .modal button, .detail-sheet button, .leaflet-popup-content button,
    .location-instruction button, .pending-panel button, { min-height: var(--touch); }
    .modal-close, .modal-header > button, .modal > div:first-child > button:last-child, .mobile-close-legend {
        min-width: var(--touch); min-height: var(--touch); display: inline-flex; align-items: center; justify-content: center;
    }
    .legend-item.filterable { padding: 0.5rem; margin-bottom: 0; }
    .disclaimer-link { padding: 0.5rem 0.25rem; }
    .filter-btn, .search-btn { padding: 0.55rem 0.85rem; font-size: 0.85rem; }
}

/* ---- Small screens ------------------------------------------------------------- */
@media (max-width: 768px) {
    /* 16px stops iOS from zooming into a focused field */
    body input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    body select:not([data-native-size]),
    body textarea:not([data-native-size]) { font-size: 16px; }

    /* Modals as bottom sheets */
    .modal-overlay { align-items: flex-end; justify-content: center; padding: 0; }
    .modal-overlay .modal {
        width: 100%;
        max-width: none;
        max-height: min(92vh, 92dvh);
        border-radius: 20px 20px 0 0;
        border-left: none; border-right: none; border-bottom: none;
        padding-bottom: calc(1.5rem + var(--safe-bottom));
        margin: 0;
    }
    .modal-overlay .modal::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--border);
        margin: -0.5rem auto 0.9rem;
    }

    /* Toasts near the top on phones: the bottom is where the thumb, the panel and the buttons are.
       Below the two rows of map buttons (travel, legend, weather; SOS, estimate), which stay usable. */
    .toast {
        top: calc(7.25rem + var(--safe-top));
        bottom: auto;
        left: 0.75rem;
        right: 0.75rem;
        max-width: none;
        text-align: center;
        transform: translateY(-16px);
    }
    .toast.show { transform: translateY(0); }
    body > .toast { transform: translateY(-16px); }
    body > .toast.show { transform: translateY(0); }

    /* Bottom-fixed chrome keeps clear of the home indicator */
    .history-panel { padding-bottom: var(--safe-bottom); }
    .legend-btn, .control-buttons, .fab-container, .fab { margin-bottom: var(--safe-bottom); }
    .season-badge { top: calc(0.75rem + var(--safe-top)); }
}

/* ---- Marker detail sheet (static/js/mobile.js) ---------------------------------- */
.detail-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1500;
    background: var(--card-bg, var(--bg, #fff));
    color: var(--text-main, #111);
    border: 1px solid var(--border, #ddd);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 40px var(--shadow, rgba(0,0,0,0.25));
    backdrop-filter: blur(15px);
    max-height: min(72vh, 72dvh);
    display: flex;
    flex-direction: column;
    transform: translateY(105%);
    transition: transform 0.25s ease;
    padding-bottom: var(--safe-bottom);
    touch-action: none;
}
.detail-sheet.open { transform: translateY(0); }
.detail-sheet.dragging { transition: none; }
.detail-sheet-handle {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    cursor: grab;
}
.detail-sheet-handle::before {
    content: "";
    width: 40px; height: 4px;
    border-radius: 2px;
    background: var(--border, #ccc);
}
.detail-sheet-close {
    position: absolute;
    top: 4px; right: 6px;
    width: 44px; height: 44px;
    border: none; background: none;
    color: var(--text-muted, #666);
    font-size: 1.6rem;
    cursor: pointer;
    border-radius: 50%;
}
.detail-sheet-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 0 0.25rem 0.5rem;
}
.detail-sheet-body .leaflet-popup-content { width: auto !important; max-height: none; }
.detail-sheet-body img { max-width: 100%; height: auto; }

/* ---- Outdoor readability ----------------------------------------------------------- */
/* A halo in the opposite colour keeps marker labels legible over water, land and satellite. */
:root { --halo: rgba(2, 6, 23, 0.9); --marker-base: #0f1d33; }
[data-theme="light"] { --halo: rgba(255, 255, 255, 0.95); --marker-base: #ffffff; }

/* Marker tints sit on a solid base in the theme's colour, so the label's contrast no longer
   depends on the water, land or satellite photo under the marker. */
.ice-marker.danger { background: linear-gradient(var(--danger-bg), var(--danger-bg)), var(--marker-base); }
.ice-marker.caution { background: linear-gradient(var(--caution-bg), var(--caution-bg)), var(--marker-base); }
.ice-marker.safe { background: linear-gradient(var(--safe-bg), var(--safe-bg)), var(--marker-base); }
.location-marker.ramp { background: linear-gradient(var(--ramp-bg), var(--ramp-bg)), var(--marker-base); }
.location-marker.parking { background: linear-gradient(var(--parking-bg), var(--parking-bg)), var(--marker-base); }
.location-marker.street { background: linear-gradient(var(--street-bg), var(--street-bg)), var(--marker-base); }
.location-marker.combo { background: linear-gradient(135deg, var(--ramp-bg) 50%, var(--parking-bg) 50%), var(--marker-base); }

.ice-marker { font-size: 15px; font-weight: 800; text-shadow: 0 0 2px var(--halo), 0 0 3px var(--halo); }
.ice-marker.camera, .ice-marker.sponsor { text-shadow: none; }
.marker-cluster div span { font-size: 14px; font-weight: 800; }
/* Price and free badges on BoatRampsMap markers: 8px white on light green was about 2:1 */
.free-badge, .price-badge { font-size: 10px; background: #15803d; color: #fff; }
.price-badge.tier-2 { background: #b45309; }
.price-badge.tier-3 { background: #b91c1c; }

/* Settings row for the switch (both apps) */
.contrast-row {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.75rem 0; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.contrast-row small { display: block; font-size: 0.8rem; color: var(--text-muted); }
.contrast-toggle {
    min-width: 4.5rem; min-height: var(--touch); padding: 0 1rem; border-radius: 999px;
    border: 2px solid var(--accent); background: transparent; color: var(--text-main);
    font: inherit; font-weight: 700; cursor: pointer;
}
.contrast-toggle[aria-pressed="true"] { background: var(--accent); color: var(--btn-text); }

/* ---- High contrast (dark theme first, light below) ---------------------------------- */
html[data-contrast="high"] {
    --bg: #000814;
    --card-bg: #0b1626;
    --border: #7dd3fc;
    --text-main: #ffffff;
    --text-muted: #e2e8f0;
    --accent: #7dd3fc;
    --btn-text: #020617;
    --accent-bg: #0b1626;
    --fill: #0b1626;
    --input-bg: #000814;
    --shadow: rgba(0, 0, 0, 0.6);
    --halo: #000;
    --ring: #fff;
}
html[data-contrast="high"][data-theme="light"] {
    --bg: #ffffff;
    --card-bg: #ffffff;
    --border: #0f172a;
    --text-main: #000000;
    --text-muted: #1e293b;
    --accent: #075985;
    --btn-text: #ffffff;
    --accent-bg: #e0f2fe;
    --fill: #ffffff;
    --input-bg: #ffffff;
    --shadow: rgba(0, 0, 0, 0.35);
    --halo: #fff;
    --ring: #000;
}
/* Glass panels wash out in the sun: opaque surfaces only */
html[data-contrast="high"] * { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
/* The basemap itself: deeper water, darker roads and labels */
html[data-contrast="high"] .leaflet-tile-pane { filter: contrast(1.25) saturate(1.2); }

/* Solid marker fills with the label colour that reads best on each (all 5:1 or better),
   and a ring in the theme's contrast colour so the marker separates from any map. */
html[data-contrast="high"] .ice-marker,
html[data-contrast="high"] .location-marker {
    border-width: 3px;
    box-shadow: 0 0 0 2px var(--ring), 0 4px 12px var(--shadow);
}
/* 16px is the most a three-character label (12") fits inside the 3px border */
html[data-contrast="high"] .ice-marker { font-size: 16px; letter-spacing: -0.04em; }
html[data-contrast="high"] .ice-marker.danger { background: #b91c1c; border-color: #fff; color: #fff; text-shadow: 0 0 2px #000; }
html[data-contrast="high"] .ice-marker.caution { background: #fbbf24; border-color: #000; color: #000; text-shadow: 0 0 2px #fff; }
html[data-contrast="high"] .ice-marker.safe { background: #4ade80; border-color: #000; color: #000; text-shadow: 0 0 2px #fff; }
html[data-contrast="high"] .ice-marker.camera,
html[data-contrast="high"] .location-marker.camera { background: var(--card-bg); border-color: #c084fc; }
html[data-contrast="high"] .location-marker.ramp { background: #1d4ed8; border-color: #fff; }
html[data-contrast="high"] .location-marker.parking { background: #c2410c; border-color: #fff; }
html[data-contrast="high"] .location-marker.street { background: #0f766e; border-color: #fff; }
html[data-contrast="high"] .location-marker.combo { background: linear-gradient(135deg, #1d4ed8 50%, #c2410c 50%); border-color: #fff; }
html[data-contrast="high"] .marker-cluster-small,
html[data-contrast="high"] .marker-cluster-medium,
html[data-contrast="high"] .marker-cluster-large { background-color: var(--ring) !important; }
html[data-contrast="high"] .marker-cluster-small div,
html[data-contrast="high"] .marker-cluster-medium div,
html[data-contrast="high"] .marker-cluster-large div { background-color: var(--accent) !important; color: var(--btn-text) !important; }
html[data-contrast="high"] .marker-cluster div span { font-size: 16px; }

/* ---- Connection status pill (static/js/netcache.js) --------------------------------- */
/* Shown only while the data on screen is not fresh: updating, offline or failed + Retry.
   Each app can move it below its own top bar with --net-status-top. */
.net-status {
    position: fixed;
    top: calc(var(--net-status-top, 0.75rem) + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    display: flex; align-items: center; gap: 0.5rem;
    max-width: calc(100vw - 7rem);
    padding: 0.35rem 0.4rem 0.35rem 0.85rem;
    border-radius: 999px;
    background: var(--card-bg, #fff);
    color: var(--text-main, #111);
    border: 1px solid var(--border, #ccc);
    box-shadow: 0 4px 16px var(--shadow, rgba(0,0,0,0.25));
    font-size: 0.85rem; font-weight: 600;
    white-space: nowrap;
}
.net-status[hidden] { display: none; }
.net-status-text { overflow: hidden; text-overflow: ellipsis; }
.net-status.net-status-failed { border-color: var(--caution, #d97706); }
.net-status-retry {
    flex: 0 0 auto;
    min-height: 36px; padding: 0 0.9rem; border-radius: 999px;
    border: none; background: var(--accent, #0369a1); color: var(--btn-text, #fff);
    font: inherit; font-weight: 700; cursor: pointer;
}
.net-status-retry[hidden] { display: none; }
@media (pointer: coarse) { .net-status-retry { min-height: var(--touch); } }
