/* NC Weekly Crop Survey drought dashboard.
 * Self-contained CSS (no Tailwind build step required). */

.dm {
    --dm-navy: #1e3a5f;
    --dm-ink: #1f2933;
    --dm-line: #c9d2df;
    /* Mirrors the theme's Tailwind red-200/red-300 (NC State brand red) — kept as
       literals here so this stylesheet stays self-contained. See
       theme/static_src/tailwind.config.js. */
    --dm-red: #cc0000;
    --dm-red-dark: #b40000;
    --dm-radius: 8px;
    color: var(--dm-ink);
}

/* Link colour reset. Wrapped in :where() so it carries no specificity from `.dm`
   — otherwise it outranks the single-class component rules below (`.dm a` is
   0-1-1, `.dm-action-link` is 0-1-0) and every link falls back to --dm-ink. */
:where(.dm) a { color: inherit; }

/* ---------- header ---------- */

.dm-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--dm-navy);
}

/* Grows to fill the title row so the Edit button is pushed to the right edge;
   min-width: 0 lets a long title wrap rather than shove the button off. */
.dm-header__intro {
    flex: 1 1 auto;
    min-width: 0;
}

.dm-header__title {
    margin: 0;
    font-size: clamp(1.5rem, 3.2vw, 2.35rem);
    font-weight: 800;
    line-height: 1.15;
    color: var(--dm-navy);
}

.dm-header__subtitle {
    margin: 0.35rem 0 0;
    font-size: 1rem;
    color: #4a5568;
}

/* Full-width row so the actions can sit against the header's right edge, with the
   stat cards keeping their natural width on the left. `stretch` keeps the two
   cards the same height even if one's label wraps. */
.dm-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    flex: 1 1 100%;
    gap: 0.75rem;
}

/* Equal flex basis + matching min/max keeps both cards exactly the same width at
   every viewport, rather than each sizing to its own label. The floor clears the
   longest label ("Counties Mapped") on one line; the ceiling stops them sprawling
   on wide screens. */
.dm-stat {
    flex: 1 1 0;
    min-width: 10rem;
    max-width: 12rem;
    padding: 0.6rem 1.1rem;
    text-align: center;
    border: 2px solid var(--dm-navy);
    border-radius: var(--dm-radius);
}

.dm-stat__label {
    display: block;
    white-space: nowrap;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--dm-navy);
}

.dm-stat__value {
    display: block;
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.1;
    color: #2e7d32;
}

/* The PDF download link, against the right edge of the stat row and centred
   against the cards. (The Edit button sits up in the title row instead.) */
.dm-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    margin-left: auto;
}

/* Plain links rather than buttons, matching the download link in the admin at
   /admin/drought-tools/ — the stat cards stay the only boxed elements in the row. */
.dm-action-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--dm-navy);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.dm-action-link:hover {
    color: #16293f;
    text-decoration-thickness: 2px;
}

.dm-action-link:focus-visible {
    outline: 2px solid var(--dm-navy);
    outline-offset: 3px;
}

/* The editor action is a solid button so it reads as the primary in-place action
   for the editors who can see it. It sits in the title row, right-aligned against
   the heading; flex: none keeps it from being squeezed by a long title. */
.dm-edit-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    background: var(--dm-red);
    border-radius: var(--dm-radius);
    text-decoration: none;
}

.dm-edit-btn:hover {
    color: #fff;
    background: var(--dm-red-dark);
}

.dm-edit-btn:focus-visible {
    outline: 2px solid var(--dm-red);
    outline-offset: 2px;
}

/* Shared by both actions; stroke="currentColor" so each glyph tracks its own
   text colour, including on hover. */
.dm-action-icon {
    width: 1rem;
    height: 1rem;
    flex: none;
}

/* ---------- week navigation ---------- */

.dm-weeknav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.9rem;
}

.dm-weeknav__step {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--dm-navy);
    background: #fff;
    border: 2px solid var(--dm-navy);
    border-radius: var(--dm-radius);
}

.dm-weeknav__step:hover {
    color: #fff;
    background: var(--dm-navy);
}

.dm-weeknav__step.is-disabled {
    color: #97a1b0;
    background: #f3f5f8;
    border-color: var(--dm-line);
    cursor: not-allowed;
}

.dm-weeknav__form {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
}

.dm-weeknav__select {
    padding: 0.4rem 0.6rem;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--dm-ink);
    background: #fff;
    border: 2px solid var(--dm-line);
    border-radius: var(--dm-radius);
}

.dm-weeknav__select:focus-visible,
.dm-weeknav__step:focus-visible {
    outline: 2px solid var(--dm-navy);
    outline-offset: 2px;
}

.dm-weeknav__go {
    padding: 0.4rem 0.75rem;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    background: var(--dm-navy);
    border: 2px solid var(--dm-navy);
    border-radius: var(--dm-radius);
    cursor: pointer;
}

.dm-weeknav__go[hidden] { display: none; }

.dm-weeknav__meta {
    margin: 0;
    margin-left: auto;
    font-size: 0.82rem;
    color: #4a5568;
}

/* ---------- main grid ---------- */

/* The map takes the row; only the legend keys share it. Trends and concerns run
   full width underneath so they cost vertical, not horizontal, space. */
.dm-grid {
    display: grid;
    grid-template-columns: minmax(0, 7.75rem) minmax(0, 1fr);
    gap: 0.5rem;
    align-items: start;
    margin-top: 1.25rem;
}

.dm-legend-col {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.dm-side-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1.25rem;
    align-items: start;
    margin-top: 1.25rem;
}

/* Stacked layout: the map leads, directly under the week nav, and the two legend
   panels sit half-width beneath it. */
@media (max-width: 60rem) {
    .dm-grid { grid-template-columns: minmax(0, 1fr); }

    .dm-map-panel { order: 1; }
    .dm-legend-col { order: 2; }

    .dm-legend-col {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }
}

/* Below this, half a screen can't hold "No mapped response" on one line. */
@media (max-width: 33rem) {
    .dm-legend-col { grid-template-columns: minmax(0, 1fr); }

    /* Two 10rem cards no longer fit side by side, so let them share the row
       equally instead — `flex: 1 1 0` gives both the same width whatever their
       label length, and the label may wrap again. */
    .dm-stat {
        flex: 1 1 0;
        min-width: 0;
        padding: 0.6rem 0.5rem;
    }

    .dm-stat__label { white-space: normal; }

    /* Actions drop to their own full-width row under the cards. */
    .dm-actions {
        flex: 1 1 100%;
        justify-content: flex-start;
        margin-left: 0;
    }
}

.dm-panel {
    border: 2px solid var(--dm-navy);
    border-radius: var(--dm-radius);
    background: #fff;
    overflow: hidden;
}

.dm-panel__title {
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.dm-panel__title--plain {
    color: var(--dm-navy);
}

.dm-panel__title--filled {
    background: var(--dm-navy);
    color: #fff;
    text-align: center;
}

/* Parenthetical qualifiers stay sentence case inside an uppercased title. */
.dm-panel__title span {
    font-weight: 400;
    text-transform: none;
}

.dm-panel__body { padding: 0.75rem; }

/* ---------- legend ---------- */

/* Both keys are reference material, not the story — they run a step down in
   size from the panels below the map. */
.dm-legend .dm-panel__title {
    padding: 0.35rem 0.5rem 0.15rem;
    font-size: 0.72rem;
    line-height: 1.25;
}

.dm-legend .dm-panel__body { padding: 0.5rem 0.55rem; }

.dm-legend__hint {
    margin: 0 0.55rem 0.4rem;
    font-size: 0.7rem;
    font-style: italic;
    line-height: 1.3;
    color: #6b7280;
}

.dm-legend__list {
    margin: 0;
    padding: 0 0.55rem 0.55rem;
    list-style: none;
}

.dm-legend__item + .dm-legend__item { margin-top: 0.1rem; }

.dm-legend__button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.12rem 0.2rem;
    font: inherit;
    font-size: 0.7rem;
    line-height: 1.2;
    text-align: left;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
}

.dm-legend__button:hover { background: #f1f5f9; }

.dm-legend__button.is-active {
    background: #e8eef7;
    border-color: var(--dm-navy);
    font-weight: 700;
}

.dm-legend__swatch {
    flex: none;
    width: 1.25rem;
    height: 0.7rem;
    border: 1px solid #9aa4b2;
    border-radius: 2px;
}

.dm-signal {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    font-size: 0.7rem;
    line-height: 1.25;
}

.dm-signal + .dm-signal { margin-top: 0.3rem; }

.dm-signal__glyph {
    flex: none;
    width: 1rem;
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
}

/* ---------- map ---------- */

.dm-map-panel { padding: 0.2rem; }

/* North Carolina is roughly 2.9:1, so an aspect-ratio box keeps fitBounds from
   leaving a tall band of dead space under the state. */
#drought-map {
    width: 100%;
    aspect-ratio: 2.9 / 1;
    min-height: 20rem;
    max-height: 44rem;
    background: #fff;
    border-radius: 4px;
}

/* Map status line: load progress, load failure, and the active legend filter.
   Real text in a role="status" element rather than generated content — CSS
   ::after is read inconsistently by assistive tech and can't announce a change. */
.dm-map-status {
    margin: 0;
    padding: 0.5rem 0.25rem 0.25rem;
    font-size: 0.9rem;
    text-align: center;
    color: #52606d;
}

/* #b91c1c on white is 6.4:1 — passes AA for body text. */
.dm-map-status.is-error { color: #b91c1c; font-weight: 500; }

/* Text equivalent for the map. Assistive tech is told to ignore the choropleth,
   so this is the only county-by-county reading it can reach — but it's a plain
   disclosure rather than sr-only, because everyone benefits from a list. */
.dm-map-list {
    margin: 0.75rem 0 1.25rem;
    border: 1px solid var(--dm-line);
    border-radius: var(--dm-radius);
    padding: 0.5rem 1rem;
}

.dm-map-list > summary {
    cursor: pointer;
    padding: 0.35rem 0;
    font-weight: 600;
    color: var(--dm-navy);
}

.dm-map-list__level {
    margin: 0.9rem 0 0.35rem;
    font-size: 0.95rem;
    color: var(--dm-navy);
}

.dm-map-list__counties {
    margin: 0 0 0.5rem;
    padding-left: 1.1rem;
    columns: 3;
    font-size: 0.9rem;
}

.dm-map-list__counties li { break-inside: avoid; }

@media (max-width: 48rem) {
    .dm-map-list__counties { columns: 1; }
}

/* Leaflet's default grey canvas — the survey map has no basemap. */
.dm .leaflet-container { background: #fff; font: inherit; }

.dm-label { width: 0; height: 0; }

.dm-label__inner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: max-content;
    transform: translate(-50%, -50%);
    transition: opacity 0.15s ease;
}

.dm-label.is-dimmed .dm-label__inner { opacity: 0.2; }

/* Too small to hold its name at this zoom — keep the signal glyph only. */
.dm-label.is-compact .dm-label__name { display: none; }

/* Hovering the county always brings its name back, above its neighbours. */
.dm-label.is-revealed { z-index: 700 !important; }
.dm-label.is-revealed .dm-label__name { display: inline-block; }

.dm-label__name {
    padding: 0 3px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.35;
    color: #111827;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid #9aa4b2;
    border-radius: 2px;
}

.dm-label__signal {
    margin-top: 1px;
    font-size: 15px;
    font-weight: 900;
    line-height: 1;
    text-shadow:
        0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
}

.dm-tooltip {
    font-size: 0.8rem;
    font-weight: 600;
}

.dm-popup { font-size: 0.85rem; }

.dm-popup__name {
    font-size: 1rem;
    font-weight: 800;
    color: var(--dm-navy);
}

.dm-popup__impact {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.3rem;
    font-weight: 600;
}

.dm-popup__swatch {
    width: 0.9rem;
    height: 0.9rem;
    border: 1px solid #9aa4b2;
    border-radius: 2px;
}

.dm-popup__signal {
    margin-top: 0.2rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.dm-popup__comment {
    margin: 0.45rem 0 0;
    line-height: 1.45;
    color: #374151;
}

/* ---------- statewide trends / concerns ---------- */

.dm-trend {
    display: flex;
    gap: 0.65rem;
    padding: 0.55rem 0;
    font-size: 0.83rem;
    line-height: 1.4;
}

.dm-trend + .dm-trend { border-top: 1px solid #e5e7eb; }

.dm-trend__icon { flex: none; width: 1.75rem; height: 1.75rem; }

/* The site's CSS reset strips list markers, so restore them explicitly. */
.dm-concerns {
    margin: 0;
    padding: 0.75rem 0.75rem 0.75rem 1.9rem;
    font-size: 0.83rem;
    line-height: 1.45;
    list-style: disc outside;
}

.dm-concerns li + li { margin-top: 0.35rem; }

/* ---------- region cards ---------- */

.dm-regions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.dm-region {
    border: 2px solid var(--dm-region-color, var(--dm-navy));
    border-radius: var(--dm-radius);
    background: #fff;
    overflow: hidden;
}

.dm-region:focus-within,
.dm-region:hover {
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.15);
}

.dm-region__title {
    margin: 0;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    font-weight: 800;
    color: #fff;
    text-align: center;
    text-transform: uppercase;
    background: var(--dm-region-color, var(--dm-navy));
}

.dm-region__counties {
    margin: 0;
    padding: 0.55rem 0.7rem 0;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
    color: var(--dm-region-color, var(--dm-navy));
}

.dm-region__bullets {
    margin: 0.5rem 0 0;
    padding: 0 0.85rem 0.85rem 1.7rem;
    font-size: 0.82rem;
    line-height: 1.45;
    list-style: disc outside;
}

.dm-region__bullets li + li { margin-top: 0.4rem; }

/* ---------- highlights ---------- */

.dm-highlights { margin-top: 1.25rem; }

.dm-highlights__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
    gap: 0.5rem;
    padding: 0.75rem;
}

.dm-highlight {
    display: grid;
    grid-template-columns: 6.5rem minmax(0, 1fr);
    border: 1px solid var(--dm-line);
    border-radius: 4px;
    overflow: hidden;
}

.dm-highlight__county {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.35rem;
    font-size: 0.82rem;
    font-weight: 800;
    text-align: center;
}

.dm-highlight__comment {
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
    line-height: 1.4;
}

/* ---------- note ---------- */

.dm-note {
    margin-top: 1rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #4a5568;
}

.dm-note strong { color: var(--dm-ink); }
