/*
 * Coral Reef Data Explorer — stylesheet
 *
 * Hand-written, committed, no build step. Replaces the Tailwind-compiled
 * version of this file; the class names in index.html and app.js are the
 * ones defined here.
 *
 * Rules:
 *   - No <style> blocks and no style="" attributes anywhere: the CSP in
 *     _headers forbids both. app.js writes the few dynamic values (loading
 *     bar width, depth bar heights and colours) through the CSSOM.
 *   - Leaflet's own rules live in vendor/leaflet/1.9.4/leaflet.css; only the
 *     overrides this app needs are at the bottom of this file.
 */

/* ---------------------------------------------------------------------------
 * 1. Design tokens
 * ------------------------------------------------------------------------ */

:root {
    --white: #fff;

    --gray-50: #f9fafb;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;

    --blue-50: #eff6ff;
    --blue-200: #bfdbfe;
    --blue-300: #93c5fd;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;

    --violet-500: #8b5cf6;
    --pink-500: #ec4899;
    --red-500: #ef4444;
    --red-600: #dc2626;
    --green-600: #16a34a;
    --orange-500: #f97316;
    --yellow-400: #facc15;
    --cyan-200: #a5f3fc;
    --cyan-400: #22d3ee;

    --amber-50: #fffbeb;
    --amber-200: #fde68a;
    --amber-800: #92400e;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-full: 9999px;

    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------------------------------------------------------------------------
 * 2. Baseline reset
 *
 * The small subset of a normalising reset this page relies on. Keep the
 * border shorthand in the universal rule: components below set only
 * border-width or border-color in places, and they expect a solid style.
 * ------------------------------------------------------------------------ */

*,
*::before,
*::after {
    box-sizing: border-box;
    border: 0 solid var(--gray-200);
}

html {
    font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    line-height: inherit;
    background-image: linear-gradient(to right bottom, var(--blue-50), #ecfeff);
}

h1,
h2 {
    font-size: inherit;
    font-weight: inherit;
    margin: 0;
}

p,
ul {
    margin: 0;
}

ul {
    list-style: none;
    padding: 0;
}

a {
    color: inherit;
    text-decoration: inherit;
}

b,
strong {
    font-weight: bolder;
}

img,
svg,
video {
    display: block;
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-feature-settings: inherit;
    font-variation-settings: inherit;
    font-size: 100%;
    font-weight: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    color: inherit;
    margin: 0;
    padding: 0;
}

/* Native selects keep their own box; only text transforms are normalised. */
button,
select {
    text-transform: none;
}

button,
input[type="button"],
input[type="reset"],
input[type="submit"] {
    -webkit-appearance: button;
    background-color: transparent;
    background-image: none;
}

input::placeholder {
    opacity: 1;
    color: var(--gray-400);
}

[role="button"],
button {
    cursor: pointer;
}

:disabled {
    cursor: default;
}

/* Toggled from app.js on the loading overlay, panels and status rows. */
.hidden {
    display: none !important;
}

/* ---------------------------------------------------------------------------
 * 3. Page scaffolding
 * ------------------------------------------------------------------------ */

#loading {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-inline: 1.5rem;
    background-image: linear-gradient(to right bottom, var(--blue-50), #ecfeff);
    z-index: 1000;
}

#app {
    min-height: 100vh;
    padding: 1.5rem;
}

.container {
    width: 100%;
    max-width: 80rem;
    margin-inline: auto;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-title {
    font-size: 2.25rem;
    line-height: 2.5rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

.page-subtitle {
    color: var(--gray-600);
}

/* White card used for every section of the page. */
.panel {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.panel-title {
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 1rem;
}

/* Last panel on the page: spaced from above, nothing follows it. */
.panel--top {
    margin-top: 1.5rem;
    margin-bottom: 0;
}

/* ---------------------------------------------------------------------------
 * 4. Loading overlay
 * ------------------------------------------------------------------------ */

.loading-card {
    width: 100%;
    max-width: 28rem;
    border-radius: var(--radius-lg);
    background-color: var(--white);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.loading-title {
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: 600;
    color: var(--gray-800);
}

.loading-status {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.loading-status.is-error {
    color: var(--red-600);
}

.loading-track {
    margin-top: 1rem;
    height: 0.5rem;
    width: 100%;
    overflow: hidden;
    border-radius: var(--radius-full);
    background-color: var(--gray-200);
}

.loading-bar {
    height: 100%;
    width: 0;
    background-color: var(--blue-500);
    transition: all 0.3s var(--ease);
}

.loading-details {
    margin-top: 1rem;
    text-align: left;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-600);
}

.loading-details > * + * {
    margin-top: 0.25rem;
}

/* One row per coral group, written by app.js while fetching. */
.loading-step {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.loading-step-state {
    color: var(--gray-500);
}

.is-loading {
    animation: pulse 2s var(--ease) infinite;
}

@keyframes pulse {
    50% {
        opacity: 0.5;
    }
}

#loading-retry {
    margin-top: 1rem;
}

.loading-note {
    margin-top: 1rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-500);
}

/* ---------------------------------------------------------------------------
 * 5. Coral type cards
 *
 * Selected state is driven from the checkbox itself, so the cards are correct
 * on first paint and app.js does not have to mirror the state in classes.
 * ------------------------------------------------------------------------ */

.coral-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.coral-card {
    flex: 1 1 0%;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.coral-card:hover:not(:has(input:checked)) {
    border-color: var(--blue-300);
}

.coral-card:has(input:checked) {
    border-color: var(--blue-500);
    background-color: var(--blue-50);
}

.coral-check {
    margin-top: 0.25rem;
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.coral-card-title {
    font-weight: 600;
    color: var(--gray-800);
}

.coral-card-desc {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-600);
}

.coral-type-status {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.coral-type-status.is-error {
    color: var(--red-600);
}

/* ---------------------------------------------------------------------------
 * 6. Map layer controls
 * ------------------------------------------------------------------------ */

.layer-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.layer-card {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
}

.layer-card:hover {
    background-color: var(--gray-50);
}

.layer-check {
    margin-top: 2px;
    width: 1rem;
    height: 1rem;
    border-radius: var(--radius-sm);
}

.layer-check--basemap {
    color: var(--gray-600);
}

.layer-check--observations {
    color: var(--blue-600);
}

.layer-check--reefs {
    color: var(--green-600);
}

.layer-check--temperature {
    color: var(--red-600);
}

.layer-title {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
}

.layer-desc {
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-500);
}

.legend,
.reef-status {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.legend-title,
.status-title {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.75rem;
    line-height: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-swatch {
    width: 1rem;
    height: 1rem;
}

.legend-swatch--reef {
    border: 2px solid var(--cyan-400);
    background-color: var(--cyan-200);
}

.heat-swatches {
    display: flex;
    gap: 0.25rem;
}

.heat-swatch {
    width: 0.75rem;
    height: 1rem;
    border-radius: var(--radius-sm);
}

.heat-swatch--low {
    background-color: var(--yellow-400);
}

.heat-swatch--mid {
    background-color: var(--orange-500);
}

.heat-swatch--high {
    background-color: var(--red-600);
}

.status-body {
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-600);
}

/* ---------------------------------------------------------------------------
 * 7. Filters
 * ------------------------------------------------------------------------ */

.filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
}

.field-label {
    display: block;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.field-input,
.field-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
}

.filter-summary {
    margin-top: 1rem;
}

.filter-count {
    margin-left: 0.75rem;
    display: inline-block;
    vertical-align: middle;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.filter-summary .btn {
    vertical-align: middle;
}

/* ---------------------------------------------------------------------------
 * 8. Buttons and selects
 * ------------------------------------------------------------------------ */

.btn {
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
    transition-duration: 0.15s;
    transition-timing-function: var(--ease);
}

.btn-primary {
    background-color: var(--blue-500);
    color: var(--white);
}

.btn-primary:hover {
    background-color: var(--blue-600);
}

.btn-secondary {
    background-color: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background-color: var(--gray-300);
}

.btn-sm {
    font-size: 0.875rem;
    line-height: 1.25rem;
}

/* Timeline buttons narrow their horizontal padding on phones. */
.btn-narrow {
    padding-inline: 0.75rem;
}

.btn-wide {
    padding-inline: 1rem;
}

.select-inline {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------------
 * 9. Timeline
 * ------------------------------------------------------------------------ */

.timeline-head {
    text-align: center;
    margin-bottom: 1rem;
}

.year-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.year-start {
    font-size: 1.875rem;
    line-height: 2.25rem;
    font-weight: 700;
    color: var(--gray-600);
}

.year-arrow {
    font-size: 1.5rem;
    line-height: 2rem;
    color: var(--gray-400);
}

.year-end {
    font-size: 3rem;
    line-height: 1;
    font-weight: 700;
    color: var(--blue-600);
}

.year-range {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.timeline-slider-row {
    margin-bottom: 1rem;
}

.range {
    width: 100%;
    height: 0.5rem;
    background-color: var(--gray-200);
    border-radius: var(--radius-lg);
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.range--end {
    background-color: var(--blue-200);
}

.range-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-600);
}

.undated-row {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
}

.check {
    margin-top: 2px;
    width: 1rem;
    height: 1rem;
    color: var(--blue-600);
    border-radius: var(--radius-sm);
}

.checkbox-label {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-700);
}

.timeline-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Button labels must not break mid-word on narrow screens. */
.timeline-controls .btn {
    white-space: nowrap;
}

/* ---------------------------------------------------------------------------
 * 10. Stats and notices
 * ------------------------------------------------------------------------ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1rem;
}

.stat-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.stat-value {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    color: var(--gray-800);
}

.notice {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
}

.notice--warning {
    background-color: var(--amber-50);
    border: 1px solid var(--amber-200);
    color: var(--amber-800);
}

.notice-title {
    font-weight: 600;
}

.notice-text {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
}

/* ---------------------------------------------------------------------------
 * 11. Map, details and depth chart
 * ------------------------------------------------------------------------ */

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
}

/* The grid gap spaces these cards; a bottom margin would add to it. */
.map-layout > .panel {
    margin-bottom: 0;
}

.details-panel {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-500);
    font-style: italic;
}

/* Panels written by app.js when a marker is clicked. */
.details-list {
    font-size: 0.875rem;
    line-height: 1.25rem;
}

.details-list > * + * {
    margin-top: 0.75rem;
}

.details-label {
    font-weight: 600;
    color: var(--gray-700);
}

.details-value {
    color: var(--gray-600);
}

.details-value--italic {
    font-style: italic;
}

.depth-legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 1rem;
    row-gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    white-space: nowrap;
}

.depth-key {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.depth-dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: var(--radius-full);
}

.depth-dot--0m {
    background-color: var(--blue-500);
}

.depth-dot--20m {
    background-color: var(--violet-500);
}

.depth-dot--50m {
    background-color: var(--pink-500);
}

.depth-dot--100m {
    background-color: var(--red-500);
}

.depth-key-label {
    color: var(--gray-600);
}

.depth-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 12rem;
}

/* app.js builds one column per depth bucket. */
.depth-bar-col {
    flex: 1 1 0%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.depth-bar {
    width: 100%;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: all 0.15s var(--ease);
}

.depth-bar:hover {
    opacity: 0.8;
}

.depth-bar-label {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-600);
}

.depth-bar-count {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 600;
    color: var(--gray-800);
}

.depth-empty {
    flex: 1 1 0%;
    align-self: center;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-500);
}

/* ---------------------------------------------------------------------------
 * 12. Leaflet overrides
 * ------------------------------------------------------------------------ */

.leaflet-container {
    height: 100%;
    width: 100%;
}

/* Guarantee a visible focus ring on every keyboard-reachable control. */
:focus-visible {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
}

/* A fixed 500px map is a tall, narrow sliver on phones */
#map {
    height: 320px;
    border-radius: var(--radius-lg);
}

/* Tighten the popup chrome so it does not cover the whole map on a phone */
@media (max-width: 480px) {
    .leaflet-popup-content {
        margin: 8px 22px 8px 10px;
    }
}

.popup-body {
    min-width: 150px;
}

/* ---------------------------------------------------------------------------
 * 13. Breakpoints (768px tablet, 1024px desktop)
 * ------------------------------------------------------------------------ */

@media (min-width: 768px) {
    .coral-options {
        flex-direction: row;
    }

    .layer-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .filter-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .btn-narrow {
        padding-inline: 1rem;
    }

    .btn-wide {
        padding-inline: 1.5rem;
    }

    .timeline-controls {
        gap: 1rem;
    }

    .depth-legend {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    #map {
        height: 500px;
    }
}

@media (min-width: 1024px) {
    .map-layout {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .panel--wide {
        grid-column: span 2;
    }
}
