/* ================================================================
   page-case-studies.css  –  Compliance Checker
   Styles for the /case-studies page.

   Layout model
   ─────────────
   .cs-toolbar           — view toggle + filter chips + results count
   .cs-layout            — CSS grid: .cs-rail (260px) + .cs-canvas (1fr)
     .cs-rail            — left filter column (selects, location, display,
                           supply-chain link checkboxes)
     .cs-canvas          — holds #table-view (row-card list) or #map-view

   Tokens come from tokens.css. A few rgba(0,0,0, X) shadow tints remain
   inline — they're generic neutral shadows, not brand colours.
   ================================================================ */


/* === PAGE LAYOUT =============================================== */

/* Every top-level block on the page is capped at the same width and
   centred, matching the pattern used on page-country.css and
   page-country-export.css. 95% of viewport up to 2400px keeps content
   off the screen edges on wide monitors while staying almost
   full-width on phones. */
h1 {
    max-width: min(95%, 2400px);
    margin-left: auto;
    margin-right: auto;
}

/* Short layman-friendly intro block directly under the page H1:
   paragraph on the left, nav bullets on the right. Columns auto-stack
   when neither side has room for its minimum width, so the layout
   responds without a hand-written @media breakpoint. */
.cs-intro-wrap {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
    gap: clamp(16px, 3vw, 40px);
    align-items: start;
    margin: 0 auto 18px;
    max-width: min(95%, 2400px);
}

.cs-intro,
.cs-intro-list {
    color: var(--color-muted);
    font-size: var(--fs-lg);
    line-height: 1.55;
    margin: 0;
}

.cs-intro-list          { padding-left: 18px; }
.cs-intro-list li       { margin-bottom: 4px; }
.cs-intro-list strong   { color: var(--ae-black); font-weight: 600; }

/* "Read more" methodology link — stands out against the muted body
   text so it reads as an action rather than blending into the prose. */
.cs-intro-link {
    color: var(--ae-darkblue);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}

.cs-intro-link:hover {
    color: var(--ae-lightgreen);
}


/* Toolbar row above the layout grid: view switch + active chips + count. */
.cs-toolbar {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    margin: 8px auto 16px;
    padding: 12px 16px;
    background: var(--white);
    border: 1px solid var(--color-track-bg);
    border-radius: var(--radius-dropdown);
    max-width: min(95%, 2400px);
}

/* Filter-drawer toggle, sticky header, and backdrop — hidden at
   desktop widths (rail is visible as a grid column there). Styled +
   revealed in the @media (max-width: 1400px) block below. */
.cs-filter-toggle,
.cs-rail-header,
.cs-rail-backdrop {
    display: none;
}

.cs-toolbar-meta {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
    color: var(--color-muted);
}

.cs-results-count b {
    color: var(--ae-black);
}

/* Segmented view switch (Table ↔ Map) */
.cs-view-switch {
    display: inline-flex;
    flex: 0 0 auto;
    padding: 4px;
    background: var(--color-track-bg);
    border-radius: var(--radius-pill);
    gap: 4px;
}

.cs-view-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
    background: transparent;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: color .15s, background-color .15s, box-shadow .15s;
}

.cs-view-btn:hover {
    color: var(--ae-darkblue);
}

.cs-view-btn.is-active {
    background: var(--ae-lightgreen);
    color: var(--ae-darkblue);
    /* Subtle lift */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 
                0 0 0 1px rgba(0, 0, 0, 0.04);
}

.cs-view-btn svg {
    flex: 0 0 auto;
}

/* Active filter chips (between view switch and results count) */
.cs-active-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
    flex: 1 1 auto;
    padding: 0 4px;
}

.cs-active-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    flex: 0 0 auto;
}

.cs-active-chips {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.cs-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 4px 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ae-darkblue);
    background: color-mix(in srgb, var(--color-chip-accent) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-chip-accent) 14%, transparent);
    border-radius: var(--radius-pill);
    max-width: 280px;
}

.cs-chip-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

.cs-chip-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    line-height: 1;
    font-size: 14px;
    color: var(--ae-darkblue);
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color .12s;
}

.cs-chip-x:hover {
    background: color-mix(in srgb, var(--color-chip-accent) 15%, transparent);
}

.cs-clear-all {
    font-size: 12px;
    font-weight: 600;
    color: var(--ae-darkblue);
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 4px 6px;
    flex: 0 0 auto;
}

.cs-clear-all:hover {
    text-decoration: underline;
}

/* Two-column layout: sticky filter rail + content canvas.
   Rail width scales with viewport so it doesn't feel stranded next to a
   wide canvas on ultrawide monitors. clamp() floors at 260px for normal
   laptop widths, ceilings at 360px so the rail never crowds the canvas. */
.cs-layout {
    display: grid;
    grid-template-columns: clamp(260px, 18vw, 360px) 1fr;
    gap: 20px;
    align-items: start;
    margin: 0 auto 24px;
    max-width: min(95%, 2400px);
}

.cs-rail {
    background: var(--white);
    border: 1px solid var(--color-track-bg);
    border-radius: var(--radius-dropdown);
    padding: 18px;
    position: sticky;
    top: calc(var(--nav-h) + 12px);
    align-self: start;
    /* Elevate the rail's stacking context above the Leaflet map. Without
       this, Leaflet's internal panes (transform-based stacking contexts
       up to z:700 for popups, plus controls at z:1000) can render on top
       of the rail's tooltip flyouts. */
    z-index: var(--z-elevated);
}

.cs-rail-group {
    margin-bottom: 20px;
}

.cs-rail-group:last-child {
    margin-bottom: 0;
}

/* Section title — doubles as the <summary> for the collapsible
   .cs-rail-group <details>. The trailing ▾ chevron indicates
   collapse state; rotates to ▸ when the section is closed. */
.cs-rail-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 10px;
    cursor: pointer;
    list-style: none;           /* hide Firefox's default marker */
    user-select: none;
}

/* Hide Safari/Chrome's default marker. */
.cs-rail-title::-webkit-details-marker {
    display: none;
}

/* Chevron (▾) on the right of the summary. */
.cs-rail-title::after {
    content: '';
    margin-left: auto;
    flex-shrink: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 5px 5px 0 5px;
    border-color: var(--color-muted) transparent transparent transparent;
    transition: transform .2s ease;
}

/* Rotate chevron to ▸ when the section is collapsed. */
details.cs-rail-group:not([open]) > .cs-rail-title::after {
    transform: rotate(-90deg);
}

/* Hover feedback so users realise the title is clickable. */
.cs-rail-title:hover {
    color: var(--ae-darkblue);
}
.cs-rail-title:hover::after {
    border-top-color: var(--ae-darkblue);
}

/* Keyboard focus ring for accessibility. */
.cs-rail-title:focus-visible {
    outline: 2px solid var(--ae-darkblue);
    outline-offset: 2px;
    border-radius: 2px;
}

.cs-rail-divider {
    height: 1px;
    background: var(--color-track-bg);
    margin: 12px 0;
}

.cs-rail-hint {
    font-size: 12px;
    color: var(--color-muted);
    margin: 10px 0 0;
    line-height: 1.45;
}

/* Rail buttons (Add location / Clear / layer toggles). */
.cs-rail-btn {
    width: 100%;
    justify-content: center;
    font-size: 13px;
    margin-top: 8px;
}

.cs-rail-btn-ghost {
    background: var(--white);
    color: var(--ae-darkblue);
    border: 1px solid var(--color-track-bg);
}

.cs-rail-btn-ghost:hover {
    background: var(--color-row-hover);
    color: var(--ae-darkblue);
}

.cs-coord-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.cs-rail #csv-file {
    font-size: 12px;
    width: 100%;
}

/* Filter inputs inside the rail */
.filter-input {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.filter-input:last-child {
    margin-bottom: 0;
}

.filter-input label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ae-darkblue);
}

.filter-select,
input[type="number"] {
    padding: 8px;
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    height: 36px;
    font-family: inherit;
    font-size: 13px;
    background: var(--white);
    color: var(--ae-black);
}

.filter-select:focus,
input[type="number"]:focus {
    outline: 2px solid var(--ae-green);
    outline-offset: -1px;
    border-color: var(--ae-green);
}

/* Supply-chain link checkbox filter */
.cs-link-filter {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cs-link-filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--ae-black);
    cursor: pointer;
    transition: opacity .15s;
}

.cs-link-filter-item:has(input:not(:checked)) {
    opacity: 0.45;
}

.cs-link-filter-cb {
    accent-color: var(--ae-darkblue);
    cursor: pointer;
}

/* Display-option checkboxes (Markers / Polygons / Scale by cleared area) */
.cs-display-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ae-black);
    cursor: pointer;
    padding: 4px 0;
    line-height: 1.3;
}

.cs-display-opt input[type="checkbox"] {
    accent-color: var(--ae-darkblue);
    cursor: pointer;
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    margin: 0;
}

.cs-display-opt:hover {
    color: var(--ae-darkblue);
}

/* Info button (rail + table header — opens the supply-chain modal) */
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: var(--ae-green);
    color: var(--white);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
}

.info-btn:hover {
    background: var(--ae-lightgreen);
    color: var(--ae-darkblue);
}

/* === MAP =============================== */

  .cs-canvas {                                                                                               
      align-self: stretch;                                                                                   
      min-width: 0;                                                                                          
  }   


/* === GROUP BY CONTROLS ========================================= */
/* White control bar above the table holding the Group-by pill cluster.
   Sorting lives on the column headers themselves (see .cs-sort-header). */

.cs-control-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--color-track-bg);
    box-shadow: var(--shadow);
}

.cs-control-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: var(--ls-uppercase);
    text-transform: uppercase;
    color: var(--color-muted);
    flex: 0 0 auto;
}

/* GROUP BY pills — segmented control on a track-bg base. The active
   pill lifts to a white surface with a faint shadow. */
.cs-groupby-pills {
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    background: var(--color-track-bg);
    border-radius: var(--radius-pill);
}

.cs-groupby-btn {
    border: 0;
    padding: 6px 14px;
    background: transparent;
    color: var(--color-muted);
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .15s, color .15s, box-shadow .15s;
}

.cs-groupby-btn:hover {
    color: var(--ae-darkblue);
}

.cs-groupby-btn.is-active {
    background: var(--white);
    color: var(--ae-darkblue);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* SORT — column-header buttons. The header text is wrapped in a button
   so the whole label is clickable. A small arrow sits next to the label,
   faint by default and bright on the active column. The arrow rotates
   180° when the active sort flips to descending. */
.cs-sort-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0;
    background: transparent;
    border: 0;
    color: inherit;
    font: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
    transition: opacity .15s;
}

.cs-sort-header:hover {
    opacity: 0.85;
}

.cs-sort-header:hover .cs-sort-arrow {
    opacity: 1;
}

.cs-sort-header .cs-sort-arrow {
    font-size: 10px;
    line-height: 1;
    opacity: 0.45;
    transition: transform .2s ease, opacity .15s;
}

.cs-sort-header.is-active .cs-sort-arrow {
    opacity: 1;
}

.cs-sort-header.is-active[data-direction="desc"] .cs-sort-arrow {
    transform: rotate(180deg);
}


/* === TABLE + GROUP HEADER ROWS ================================= */

.cs-table-card {
    background: var(--white);
    border: 1px solid var(--color-track-bg);
    border-radius: var(--radius-dropdown);
    overflow: hidden;
}

/* Shared column grid: 8 columns. Fixed-width columns use the fluid
   --col-* tokens (defined in tokens.css) so they grow proportionally
   on ultrawide monitors instead of leaving the 2fr/1.5fr columns to
   absorb all the extra space.
     2fr            property + location
   --col-md         commodity
     1.5fr          linked companies
   --col-sm         cleared area
   --col-md         clearance period
   --col-md         case date
   --col-lg         supply-chain link
   --col-xs         pdf icon */

.cs-table-header,
.cs-row {
    display: grid;
    grid-template-columns:
        2fr
        var(--col-md)
        1.5fr
        var(--col-sm)
        var(--col-md)
        var(--col-md)
        var(--col-lg)
        var(--col-xs);
    gap: 12px;
    align-items: start;
}

/* Column header row — dark-teal text on white, with a low-opacity
   dark-teal bottom border to separate it from the data rows without
   resorting to a filled background. Mirrors the small-uppercase label
   style used elsewhere in the page. */
.cs-table-header {
    padding: 14px 16px;
    background: var(--ae-darkblue);
    color: var(--white);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: var(--ls-uppercase);
    border-bottom: 1px solid color-mix(in srgb, var(--ae-darkblue) 25%, transparent);
}

.cs-table-header .cs-col {
    text-align: center;
}

.cs-row {
    padding: 14px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--color-track-bg);
    font-size: var(--fs-md);
    transition: background .12s;
}

.cs-row .cs-col-area {
    text-align: center;                                                        
}   

.cs-row .cs-col-date {
    text-align: center;                                                        
}   

.cs-row:last-child {
    border-bottom: none;
}

.cs-row:hover {
    background: color-mix(in srgb, var(--ae-lightgreen) 18%, transparent);
}

.cs-col {
    min-width: 0;           /* allow grid children to shrink + ellipsis */
}

.cs-col-property .cs-property-name {
    font-weight: 600;
    color: var(--ae-black);
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.3;
}

.cs-col-property .cs-property-location {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 2px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.cs-area-value {
    color: var(--ae-black);
    font-weight: 700;
}

.cs-area-unit {
    color: var(--color-muted);
    font-size: 12px;
    margin-left: 4px;
    font-weight: 500;
}

.cs-col-link,
.cs-col-pdf {
    text-align: center;
}

.cs-dash {
    color: var(--color-muted);
}

.cs-empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
    background: var(--card-bg);
}

/* Group header rows */
.cs-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 12px 8px;
    margin-top: 4px;
    border-bottom: 1px solid var(--color-track-bg);
    font-size: 13px;
    font-weight: 700;
    color: var(--ae-darkblue);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cs-group-header:first-child {
    padding-top: 8px;
    margin-top: 0;
}

.cs-group-flag {
    width: 22px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
    flex: 0 0 auto;
}

.cs-group-commodity-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 auto;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--ae-black) 6%, transparent);
}

.cs-group-name {
    flex: 0 0 auto;
}

.cs-group-count {
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--color-muted);
    font-size: 12px;
}

/* Commodity — dot + name inside each row */
.cs-commodity-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cs-commodity {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ae-black);
    text-decoration: none;
    line-height: 1.3;
}

.cs-commodity:hover {
    color: var(--ae-darkblue);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cs-commodity-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
    /* Fallback — overridden per commodity below. */
    background: var(--color-muted);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.04);
}

/* Per-commodity colours — tokens defined in tokens.css (--commodity-*).
   The "palm oil" and "timber" aliases map to the same token as their
   canonical keys so either data-commodity spelling renders correctly. */
.cs-commodity[data-commodity="cattle"]    .cs-commodity-dot { background: var(--commodity-cattle); }
.cs-commodity[data-commodity="cocoa"]     .cs-commodity-dot { background: var(--commodity-cocoa); }
.cs-commodity[data-commodity="coffee"]    .cs-commodity-dot { background: var(--commodity-coffee); }
.cs-commodity[data-commodity="corn"]      .cs-commodity-dot { background: var(--commodity-corn); }
.cs-commodity[data-commodity="cotton"]    .cs-commodity-dot { background: var(--commodity-cotton); }
.cs-commodity[data-commodity="palm"]      .cs-commodity-dot { background: var(--commodity-palm); }
.cs-commodity[data-commodity="palm oil"]  .cs-commodity-dot { background: var(--commodity-palm); }
.cs-commodity[data-commodity="poultry"]   .cs-commodity-dot { background: var(--commodity-poultry); }
.cs-commodity[data-commodity="rubber"]    .cs-commodity-dot { background: var(--commodity-rubber); }
.cs-commodity[data-commodity="soy"]       .cs-commodity-dot { background: var(--commodity-soy); }
.cs-commodity[data-commodity="wood"]      .cs-commodity-dot { background: var(--commodity-wood); }
.cs-commodity[data-commodity="timber"]    .cs-commodity-dot { background: var(--commodity-wood); }

/* Company pills (neutral grey) */
.cs-company-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cs-company-pill {
    display: inline-block;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    border: 1px solid var(--color-track-bg);
    font-size: 12px;
    color: var(--ae-black);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.cs-company-pill:hover {
    background: color-mix(in srgb, var(--ae-lightgreen) 25%, transparent);
    border-color: color-mix(in srgb, var(--ae-green) 40%, transparent);
    color: var(--ae-darkblue);
}


/* === BADGES AND STATUS PILLS ================================== */
/* Neutral confidence scale using the site's teal palette — darker +
   filled = stronger evidence. Explicitly NOT red/amber/green so it
   doesn't read as a risk traffic-light. */

.sc-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    border: 1px solid transparent;
    white-space: nowrap;
}

.sc-badge .sc-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex: none;
}

.sc-badge-confirmed {
    background: var(--ae-darkblue);
    color: var(--white);
    border-color: var(--ae-darkblue);
}
.sc-badge-confirmed .sc-dot { background: var(--white); }

.sc-badge-probable {
    /* light teal tint — uses color-mix so it tracks the darkblue token */
    background: color-mix(in srgb, var(--ae-darkblue) 15%, var(--white));
    color: var(--ae-darkblue);
    border-color: color-mix(in srgb, var(--ae-darkblue) 25%, transparent);
}
.sc-badge-probable .sc-dot { background: var(--ae-darkblue); }

.sc-badge-potential {
    /* near-neutral panel — faintest tier in the scale */
    background: var(--card-bg);
    color: var(--color-badge-potential-text);
    border-color: var(--color-track-bg);
}
.sc-badge-potential .sc-dot {
    background: var(--color-badge-potential-dot);
}

/* PDF icon button (in the last table column) */
.cs-pdf-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-track-bg);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--ae-darkblue);
    text-decoration: none;
    transition: background .12s, color .12s, border-color .12s;
}

.cs-pdf-icon:hover {
    background: var(--ae-darkblue);
    color: var(--white);
    border-color: var(--ae-darkblue);
}

.cs-pdf-icon svg {
    display: block;
}


/* === MAP VIEW ================================================== */

#map-view {
    display: none;
    position: sticky;
    top: calc(var(--nav-h) + 12px);
    height: clamp(620px, 55vh, 900px);
    width: 100%;
    border: 1px solid var(--color-track-bg);
    border-radius: var(--radius-dropdown);
    overflow: hidden;
}

#map-container {
    height: 100%;
    width: 100%;
}

/* Coordinate-tools buttons (shared with rail) */
.coordinate-btn {
    padding: 8px 12px;
    background: var(--ae-darkblue);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
}

.coordinate-btn:hover {
    background: var(--ae-lightgreen);
    color: var(--ae-darkblue);
}

/* === MAP — MARKERS ============================================ */
/* Leaflet markers built by divIcon */
.marker-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--white);
    box-shadow: 0 0 4px rgba(0, 0, 0, .25);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.marker-icon.is-active {
    transform: scale(1.28);
    border-color: var(--ae-yellow);
    box-shadow: 0 0 0 4px rgba(254, 227, 39, .45), 0 0 10px rgba(8, 120, 128, .35);
}

.custom-basic-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.csv-marker {
    width: 18px;
    height: 18px;
    background: red;                           /* diagnostic marker colour */
    border: 2px solid var(--white);
    box-shadow: 0 0 4px rgba(0, 0, 0, .25);
    border-radius: var(--radius-sm);
}

/* === MAP — LEGENDS ============================================ */
/* Commodity legend (top-right inside the map) */
.map-legend {
    position: absolute;
    top: 70px;
    right: 10px;
    width: 150px;
    background-color: var(--white);
    padding: 10px 15px;
    border-radius: var(--radius-dropdown);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
    font-size: 14px;
    z-index: var(--z-tooltip);
}

.map-legend h4 {
    margin: 0 0 5px;
    font-size: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border-radius: 50%;
    transform: rotate(-45deg);
    border: 1px solid var(--color-input-border);
}

/* Marker-size legend (appears only when "scale by cleared area" is on) */
.size-legend {
    top: 320px;
    right: 10px;
    width: 150px;
}

.size-legend .size-legend-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.size-legend .size-legend-item {
    display: grid;
    grid-template-columns: 50px 1fr;
    align-items: center;
    gap: 10px;
}

.size-legend .size-legend-circle-wrap {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.size-legend .size-legend-circle {
    border: 2px solid var(--ae-black);
    border-radius: 50%;
    background: var(--ae-darkblue);
    box-sizing: border-box;
}

.size-legend .size-legend-label {
    font-size: 12px;
    color: var(--ae-darkblue);
    line-height: 1.2;
    white-space: nowrap;
}

.size-legend .size-legend-sub {
    font-size: 12px;
    color: var(--ae-darkblue);
    margin-top: 2px;
}

/* WorldCover land-use legend (bottom-left when the WMS overlay is on) */
.wms-legend {
    background: var(--white);
    padding: 10px 12px;
    border-radius: var(--radius-dropdown);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 1.2;
    max-width: 240px;
}

.wms-legend .legend-title {
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--ae-darkblue);
}

.wms-legend .legend-subtitle {
    font-size: 11px;
    opacity: 0.75;
    margin-bottom: 8px;
}

.wc-legend-items {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.wc-legend-item {
    display: grid;
    grid-template-columns: 14px 1fr;
    gap: 8px;
    align-items: center;
}

.wc-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.wc-label {
    color: var(--ae-black);
    font-size: 12px;
}

/* === MAP — POPUPS ============================================= */
/* Leaflet popup overrides — Leaflet ships its own CSS at higher
   specificity / inline styles, so !important is necessary on the
   width + close-button properties. */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-dropdown);
    padding: 0;
    overflow: hidden;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.leaflet-popup-content {
    margin: 0;
    padding: 0;
    width: 300px !important;
    font-family: inherit;
}

.leaflet-popup-close-button {
    color: var(--white) !important;
    top: 6px !important;
    right: 8px !important;
    font-size: 18px !important;
    opacity: 0.9;
}

.leaflet-popup-tip {
    background: var(--white);
}

/* Custom popup layout (inside each marker / polygon popup) */
.custom-popup {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.popup-header {
    padding: 12px 14px;
    /* Colour is set inline per-popup by pickPopupTextColor() so dark
       commodity backgrounds get white text and light ones get black.
       The fallback here is only used if the JS ever skips the inline
       assignment. */
    color: var(--white);
}

.popup-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    /* Inherit from .popup-header so the JS-set colour actually reaches
       the title. Typography.css sets h3 { color: var(--ae-black) } as a
       direct rule, which would otherwise beat inheritance. */
    color: inherit;
}

.popup-content {
    padding: 12px 14px 14px 14px;
    background: var(--white);
    font-size: 13px;
    line-height: 1.4;
}

.popup-grid {
    display: grid;
    grid-template-columns: 90px 1fr;
    row-gap: 6px;
    column-gap: 8px;
    margin-bottom: 12px;
}

.popup-label {
    font-weight: 700;
    color: var(--color-muted);
}

.popup-value {
    color: var(--ae-black);
}

/* PDF-link button inside the popup — !important forces white text
   against any inherited link colour. */
.popup-button {
    display: inline-block;
    padding: 8px 12px;
    background: var(--ae-darkblue);
    color: var(--white) !important;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    transition: background var(--transition-base);
}

.popup-button:hover {
    background: var(--ae-lightgreen);
    color: var(--ae-darkblue) !important;
}


/* === MODAL (supply-chain link classification info) =========== */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
}

.modal.is-open {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--ae-black) 55%, transparent);
    z-index: 0;
}

.modal-dialog {
    position: relative;
    width: 1000px;
    max-width: 120vw;
    margin: 6vh auto;
    background: var(--white);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--ae-darkblue);
    color: var(--white);
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close {
    border: none;
    background: transparent;
    color: var(--white);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 14px 16px;
    overflow: auto;
    font-size: 14px;
    line-height: 1.4;
}

.modal-body h4 {
    margin: 14px 0 6px 0;
}

.modal-body ul {
    margin: 6px 0 0 18px;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--color-track-bg);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-primary {
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--ae-darkblue);
    color: var(--white);
    cursor: pointer;
}

.modal-primary:hover {
    background: var(--ae-lightgreen);
    color: var(--ae-darkblue);
}


/* === TOOLTIP (rail ⓘ info flyouts) ============================ */
/* .csv-info-text is portaled to <body> on DOMContentLoaded so it
   can never be trapped inside a transformed/contained ancestor.
   z-index 1050 sits between the map/legends (1000) and the nav (1100). */

.csv-info-tooltip {
    cursor: help;
    font-weight: bold;
    margin-left: 6px;
    color: var(--ae-green);
    position: relative;
}

.csv-info-text {
    display: none;
    position: fixed;
    z-index: var(--z-portal);
    background: var(--ae-black);
    color: var(--white);
    padding: 10px;
    border-radius: var(--radius-sm);
    width: 260px;
    white-space: pre-line;
    font-weight: normal;
    font-size: 12px;
    line-height: 1.4;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.csv-info-text.is-shown {
    display: block;
}


/* === RESPONSIVE (tablet) ======================================= */
/* At widths ≤1200 the rail becomes an off-canvas drawer that slides
   in from the left. The canvas goes full-width; the drawer sits on
   top of the table/map with a soft backdrop so filter changes are
   visible live. The table also uses a tighter column grid. */

@media (max-width: 1200px) {
    /* Canvas takes full width — rail is out of flow as a drawer. */
    .cs-layout {
        grid-template-columns: 1fr;
    }

    /* Filters toggle button in the toolbar */
    .cs-filter-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 14px;
        background: var(--ae-darkblue);
        color: var(--white);
        border: none;
        border-radius: var(--radius-pill);
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        flex: 0 0 auto;
        transition: background-color .15s, color .15s;
    }
    .cs-filter-toggle:hover {
        background: var(--ae-lightgreen);
        color: var(--ae-darkblue);
    }

    /* Rail becomes a fixed left-drawer that starts below the fixed
       nav so the whole content is visible (no clipping behind nav). */
    .cs-rail {
        position: fixed;
        top: calc(var(--nav-h) + 12px);
        left: 0;
        bottom: 0;
        width: min(360px, 90vw);
        max-width: 100vw;
        padding: 0 18px 18px;
        border: none;
        border-right: 1px solid var(--color-track-bg);
        border-radius: 0;
        overflow-y: auto;
        max-height: calc(100vh - var(--nav-h) - 24px);                                                         
        transform: translateX(-100%);
        transition: transform .25s ease;
        /* Above the map (1000) but below the fixed nav (1100) and
           the portaled tooltip (1050). */
        z-index: var(--z-drawer);
        box-shadow: 4px 0 18px rgba(0, 0, 0, 0.15);
    }
    .cs-rail.is-open {
        transform: translateX(0);
    }

    /* Sticky drawer header — stays at the top of the drawer when the
       user scrolls the filter list. The close button inside uses a
       label (not just an icon) so the action is unambiguous. */
    .cs-rail-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        position: sticky;
        top: 0;
        /* Escape the rail's horizontal padding so the header spans
           edge-to-edge of the drawer. */
        margin: 0 -18px 16px;
        padding: 12px 16px;
        background: var(--ae-darkblue);
        color: var(--white);
        z-index: 2;
    }

    .cs-rail-header-title {
        font-size: 13px;
        font-weight: 700;
        letter-spacing: var(--ls-uppercase);
        text-transform: uppercase;
    }

    .cs-rail-close {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        background: color-mix(in srgb, var(--white) 15%, transparent);
        color: var(--white);
        border: 1px solid color-mix(in srgb, var(--white) 25%, transparent);
        border-radius: var(--radius-pill);
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: background-color .15s, color .15s, border-color .15s;
    }
    .cs-rail-close:hover {
        background: var(--white);
        color: var(--ae-darkblue);
        border-color: var(--white);
    }

    /* Backdrop starts below the nav so the nav itself isn't dimmed.
       Soft tint so the table/map stays readable behind the drawer. */
    .cs-rail-backdrop {
        display: block;
        position: fixed;
        top: var(--nav-h);
        right: 0;
        bottom: 0;
        left: 0;
        background: color-mix(in srgb, var(--ae-black) 18%, transparent);
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease, visibility 0s linear .2s;
        z-index: var(--z-drawer-bg);
    }
    .cs-rail-backdrop.is-open {
        opacity: 1;
        visibility: visible;
        transition: opacity .2s ease, visibility 0s linear 0s;
    }

    /* Lock body scroll while drawer is open so the drawer itself
       scrolls internally instead of dragging the page under it. */
    body.cs-rail-open {
        overflow: hidden;
    }

    /* Tighter table-row grid on narrow viewports */
    .cs-table-header,
    .cs-row {
        grid-template-columns: 1.8fr 95px 1.6fr 90px 95px 90px 110px 40px;
        gap: 10px;
    }
}

/* === RESPONSIVE (mobile) ======================================= */
/* At ≤768 the table scrolls horizontally inside its
   .table-scroll-wrapper (overflow-x from table.css); min-width on
   the grid keeps the layout readable. */

@media (max-width: 768px) {
    .cs-table-card .table-scroll-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .cs-table-header,
    .cs-row {
        min-width: 980px;
    }
}
