/* ============================================================================
   LiteFarm Dashboard — Field Atlas shared stylesheet (single source of truth)
   ----------------------------------------------------------------------------
   Included ONCE globally via litefarm_ui/navbar.py -> ui.include_css(). Every
   page imports the navbar, so every page gets this file. Reference tokens by
   var(--name); never hard-code a hex in a component.

   Sections:
     1  Fonts + design tokens (:root)        — source of truth (design-tokens.css)
     2  Base / reset / typography
     3  App shell + vertical nav rail (.lf-rail)
     4  Components  (lf- prefix; avoids Bootstrap .card/.badge collisions)
     5  Scope filter + Analyse  (.scope-*)
     6  Overlays  (info popover, progress toast)
     7  Plotly / Folium hooks
     8  LEGACY  — classes used by not-yet-migrated pages, re-themed to tokens.
                  Remove a block here once its page is migrated to section 4/5.

   Spec component -> class map:
     Card/panel        .lf-card / .lf-card-pad         KPI/metric   .lf-metric
     Button            .lf-btn / .lf-btn-ghost         Segmented    .lf-seg
     Table             .lf-tbl                         Badge        .lf-badge
     Input/select      .lf-field / .lf-input / .lf-label
     Page header       .lf-topbar                      Scope bar    .scope-bar
   ============================================================================ */

/* ====================== 1 · FONTS + TOKENS ============================== */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700;800&family=Hanken+Grotesk:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* ---- Surfaces ---- */
  --paper:      #F4F1EA;
  --paper-2:    #E9E4DA;
  --card:       #FDFCF9;
  --card-2:     #F6F3EC;
  --line:       #E3DCCF;
  --line-soft:  #EDE8DE;

  /* ---- Ink / text ---- */
  --ink:    #2A2317;
  --ink-2:  #5B5240;
  --ink-3:  #8C8268;
  --ink-4:  #ABA088;

  /* ---- Greens (primary) ---- */
  --canopy:   #2E5A39;
  --pine:     #3C6E47;
  --leaf:     #4F8A4C;
  --leaf-bri: #6FA85C;
  --sprout:   #93B86E;
  --moss:     #8C9667;

  /* ---- Earth (support) ---- */
  --soil:       #6E4F38;
  --soil-deep:  #4A3526;
  --wheat:      #D7A23E;
  --wheat-soft: #E8C878;
  --clay:       #C2674A;
  --clay-soft:  #DDA088;
  --sky:        #6C8AA0;
  --sky-soft:   #A6BDCB;

  /* ---- Status (fg + tinted bg pairs) ---- */
  --good:   #4F8A4C;  --good-bg: #E2EFD9;  --good-tx: #2C6A30;
  --warn:   #C99528;  --warn-bg: #F6EBCE;  --warn-tx: #8A6612;
  --bad:    #BB5A3D;  --bad-bg:  #F3DDD2;  --bad-tx:  #9A4128;

  /* ---- Location / area types (LiteFarm parity — keys MUST stay stable) ---- */
  --loc-field:         #9C6526;
  --loc-barn:          #BB4A3E;
  --loc-greenhouse:    #3B7A40;
  --loc-natural-area:  #D7A53A;
  --loc-garden:        #6B7587;
  --loc-farm-boundary: #8A57BE;
  --loc-residence:     #1C6157;
  --loc-ceremonial:    #2E8276;
  --loc-surface-water: #3F73B2;
  --loc-watercourse:   #3F73B2;
  --loc-buffer-zone:   #D7A53A;
  --loc-fence:         #6B7587;
  --loc-soil-sample:   #8A5630;
  --loc-gate:          #79828F;
  --loc-water-valve:   #5C82A6;
  --loc-other:         #828C8C;
  --loc-unknown:       #99A2A1;

  /* ---- Radii ---- */
  --r-xs: 7px;
  --r-sm: 11px;
  --r:    16px;
  --r-lg: 24px;
  --r-xl: 34px;

  /* ---- Shadows (warm-tinted) ---- */
  --sh-1: 0 1px 2px rgba(74,53,38,.07), 0 2px 5px rgba(74,53,38,.05);
  --sh-2: 0 4px 16px rgba(74,53,38,.10), 0 1px 3px rgba(74,53,38,.06);
  --sh-3: 0 16px 40px rgba(74,53,38,.16), 0 3px 10px rgba(74,53,38,.08);
  --sh-inset: inset 0 1px 0 rgba(255,255,255,.6);

  /* ---- Type families ---- */
  /* --serif is the TITLE / display role (page titles, section headers, metric
     numbers, brand). Now Montserrat (a geometric sans), not a serif — name kept
     to avoid churn across var(--serif) references. */
  --serif: "Montserrat", "Segoe UI", system-ui, sans-serif;
  --sans:  "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --mono:  "IBM Plex Mono", ui-monospace, monospace;

  /* ---- Spacing ---- */
  --sp-1: 2px;  --sp-2: 4px;  --sp-3: 6px;  --sp-4: 8px;
  --sp-5: 12px; --sp-6: 14px; --sp-7: 16px; --sp-8: 18px;
  --sp-9: 20px; --sp-10: 24px; --sp-11: 30px; --sp-12: 34px;

  /* ---- Layout ---- */
  --sidebar-w: 282px;
  --sidebar-w-collapsed: 64px;

  /* Sidebar (dark surface — literal values per spec) */
  --rail-bg-top: #335640;
  --rail-bg-mid: #2C4E39;
  --rail-bg-bot: #29472F;
  --rail-text:   #EDE7D6;
  --rail-head:   #FBF6E8;
}

/* ====================== 2 · BASE / RESET / TYPE ========================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  /* Make room for the fixed nav rail; content shifts right of it. */
  padding-left: var(--sidebar-w);
  transition: padding-left .2s ease;
}
/* Collapsed rail: content shifts left to the narrow (icon-only) rail width. */
body.lf-rail-collapsed { padding-left: var(--sidebar-w-collapsed); }

/* Kill Bootstrap's default container padding so pages sit flush by the rail. */
body > .container-fluid:first-child { padding: 0 !important; }

.lf-ic { stroke: currentColor; fill: none; flex-shrink: 0; vertical-align: middle; }

/* Type role utilities */
.lf-display     { font-family: var(--serif); font-size: 40px;  font-weight: 500; line-height: 1.05; letter-spacing: -.01em; }
.lf-h1          { font-family: var(--serif); font-size: 27px;  font-weight: 500; line-height: 1.05; letter-spacing: -.015em; }
.lf-panel-title { font-family: var(--serif); font-size: 19px;  font-weight: 500; letter-spacing: -.01em; }
.lf-kicker      { font-family: var(--mono);  font-size: 11px;  font-weight: 500; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); }
.lf-label       { font-family: var(--mono);  font-size: 10px;  font-weight: 400; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.lf-caption     { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.lf-mono        { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ====================== 3 · APP SHELL + NAV RAIL ======================= */
.lf-rail {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--rail-bg-top) 0%, var(--rail-bg-mid) 38%, var(--rail-bg-bot) 100%);
  color: var(--rail-text);
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .2s ease;
}

/* Brand / wordmark */
.lf-rail-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 16px;
}
.lf-rail-brand .lf-brand-mark {
  width: 34px; height: 34px;
  border-radius: var(--r-xs);
  object-fit: contain;
  background: #fff;          /* light tile so the logo reads on the dark rail */
  padding: 3px;
  box-shadow: var(--sh-inset);
  flex-shrink: 0;
}
.lf-rail-brand .lf-brand-word {
  font-family: var(--serif);          /* Montserrat — matches the logo wordmark */
  font-size: 19px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--rail-head);
  line-height: 1;
}
.lf-rail-brand .lf-brand-lite { font-weight: 300; }   /* LITE — light */
.lf-rail-brand .lf-brand-farm { font-weight: 800; }   /* FARM — bold */
.lf-rail-brand .lf-brand-sub {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--rail-text);
  opacity: .55;
  display: block;
  margin-top: 1px;
}

.lf-rail-nav { padding: 8px 12px 16px; }

.lf-rail-group { margin-top: 16px; }
.lf-rail-group:first-child { margin-top: 4px; }
.lf-rail-group-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--rail-text);
  opacity: .5;
  padding: 0 11px;
  margin-bottom: 6px;
}

/* Nav item */
.lf-rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  margin: 2px 0;
  border-radius: var(--r-sm);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--rail-text);
  opacity: .82;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease, opacity .15s ease;
}
.lf-rail-item .lf-ic { opacity: .9; }
.lf-rail-item:hover {
  background: rgba(231, 222, 201, .09);
  color: var(--rail-head);
  opacity: 1;
  text-decoration: none;
}
.lf-rail-item.active {
  background: linear-gradient(90deg, rgba(231,222,201,.18), rgba(231,222,201,.07));
  border-color: rgba(231, 222, 201, .22);
  color: var(--rail-head);
  opacity: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
/* Active seed-tab marker on the left edge */
.lf-rail-item.active::before {
  content: "";
  position: absolute;
  /* Flush to the rail's (page's) left edge: counteract .lf-rail-nav's 12px
     left padding so the seed-tab marker sits at x=0, not at the item edge. */
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 5px; height: 26px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--wheat), var(--leaf-bri));
}

/* Locked / SSO-gated item — VISUAL ONLY (no auth wired yet) */
.lf-rail-item.locked { opacity: .42; cursor: default; pointer-events: none; }
.lf-rail-item.locked:hover { background: transparent; }
.lf-rail-item.locked .lf-ic { opacity: .5; }
.lf-rail-item .lf-lock { margin-left: auto; opacity: .7; }
/* "Sign in to access" nudge shown under a locked group for guests */
.lf-rail-nudge {
  margin: 10px 11px 0;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: rgba(231, 222, 201, .08);
  border: 1px solid rgba(231, 222, 201, .14);
  font-size: 12px;
  line-height: 1.45;
  color: var(--rail-text);
  opacity: .8;
}

.lf-rail-foot { margin-top: auto; padding: 14px 18px; }

/* Collapse / expand handle — a circle straddling the rail's right edge, level
   with the logo (fixed, so the rail's overflow doesn't clip it). The chevron
   points the way the rail will move. */
.lf-rail-toggle {
  position: fixed; top: 24px; left: var(--sidebar-w);
  transform: translateX(-50%);
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--rail-bg-top);          /* same green as the sidebar */
  border: 1px solid var(--rail-text);      /* thin cream ring */
  border-radius: 50%;
  color: var(--rail-head); box-shadow: var(--sh-1); cursor: pointer; z-index: 1001;
  transition: left .2s ease, background .15s ease, color .15s ease, border-color .15s ease;
}
.lf-rail-toggle:hover { background: var(--canopy); border-color: var(--rail-head); }
/* chevron-left's open arms sit right of its tip, so nudge it left to optically centre. */
.lf-rail-toggle .lf-ic { display: block; transform: translateX(-0.75px); }

/* ── Collapsed (icon-only) rail ── */
body.lf-rail-collapsed .lf-rail { width: var(--sidebar-w-collapsed); }
/* hide all text; keep icons + the active highlight */
body.lf-rail-collapsed .lf-brand-text,
body.lf-rail-collapsed .lf-rail-group-label,
body.lf-rail-collapsed .lf-rail-item > span,
body.lf-rail-collapsed .lf-rail-item .lf-lock,
body.lf-rail-collapsed .lf-rail-nudge { display: none; }
/* center the remaining icons */
body.lf-rail-collapsed .lf-rail-brand { justify-content: center; padding: 20px 0 16px; }
body.lf-rail-collapsed .lf-rail-item { justify-content: center; gap: 0; }
body.lf-rail-collapsed .lf-rail-toggle { left: var(--sidebar-w-collapsed); }
body.lf-rail-collapsed .lf-rail-toggle .lf-ic { transform: rotate(180deg) translateX(-0.75px); }  /* › — expand (nudge keeps it centred after the flip) */

/* Page scroll area (apply on a page's content wrapper as pages migrate) */
.lf-page { padding: 30px 34px; }

/* Sticky topbar / page header */
.lf-topbar {
  position: sticky; top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 28px 34px 22px;
  background: linear-gradient(180deg, var(--card), rgba(252, 250, 243, .55));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.lf-topbar .lf-crumb { font-family: var(--mono); font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: var(--sp-3); }
.lf-topbar .lf-topbar-title { font-family: var(--serif); font-size: 32px; font-weight: 500; line-height: 1.05; letter-spacing: -.015em; margin: 0; }
.lf-topbar .lf-topbar-sub { font-size: 13.5px; color: var(--ink-2); margin-top: var(--sp-3); }

/* ====================== 4 · COMPONENTS ================================= */
/* --- Card / panel --- */
.lf-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
}
.lf-card-pad { padding: 22px 24px; }
.lf-panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}

/* --- KPI / metric callout --- */
.lf-metric {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
  padding: 18px 20px;
}
.lf-metric::after {
  content: "";
  position: absolute; right: -22px; top: -22px;
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--accent, var(--leaf));
  opacity: .08;
}
.lf-metric .lf-metric-label { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.lf-metric .lf-metric-value { font-family: var(--serif); font-size: 38px; font-weight: 600; line-height: 1.05; letter-spacing: -.02em; color: var(--ink); margin-top: 6px; }
.lf-metric .lf-metric-value .lf-unit { font-size: 17px; color: var(--ink-3); }
.lf-metric .lf-trend { font-size: 12.5px; font-weight: 600; margin-top: 9px; }
.lf-metric .lf-trend.up { color: var(--good); }
.lf-metric .lf-trend.down { color: var(--bad); }

/* --- Buttons --- */
.lf-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--sans); font-size: 13.5px; font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--r-xs);
  border: 1px solid transparent;
  background: var(--leaf); color: #fff;
  box-shadow: var(--sh-1);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .15s ease;
}
.lf-btn:hover { background: var(--pine); transform: translateY(-1px); box-shadow: var(--sh-2); color: #fff; }
.lf-btn-ghost {
  background: var(--card); color: var(--ink); border-color: var(--line); box-shadow: none;
}
.lf-btn-ghost:hover { background: var(--card-2); border-color: var(--moss); transform: none; box-shadow: none; }

/* --- Segmented control / tabs --- */
.lf-seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 30px;
}
.lf-seg > button, .lf-seg > .lf-seg-btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--ink-2);
  padding: 6px 15px; border: none; background: transparent; border-radius: 24px;
  cursor: pointer; transition: all .15s ease;
}
.lf-seg > button:hover, .lf-seg > .lf-seg-btn:hover { color: var(--ink); }
.lf-seg > button.on, .lf-seg > .lf-seg-btn.on { background: var(--card); color: var(--canopy); box-shadow: var(--sh-1); }

/* --- Input / select / field --- */
.lf-field { margin-bottom: 14px; }
.lf-field > label, .lf-label-block {
  display: block;
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 6px;
}
.lf-input, .lf-field input[type="text"], .lf-field input[type="search"], .lf-field select, .lf-field .selectize-input {
  width: 100%;
  font-family: var(--sans); font-size: 13.5px; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-xs);
  padding: 9px 12px;
  transition: border-color .15s, box-shadow .15s ease;
}
.lf-input:focus, .lf-field input:focus, .lf-field select:focus, .lf-field .selectize-input.focus {
  outline: none; border-color: var(--leaf);
  box-shadow: 0 0 0 3px rgba(79, 138, 76, .14);
}
.lf-help { font-size: 11.5px; color: var(--ink-4); margin-top: 4px; }

/* --- Table --- */
.lf-tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lf-tbl thead th {
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .10em; text-transform: uppercase;
  color: var(--ink-3); text-align: left;
  padding: 10px 14px; border-bottom: 1.5px solid var(--line); white-space: nowrap;
}
.lf-tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); color: var(--ink); vertical-align: middle; }
.lf-tbl tbody tr:last-child td { border-bottom: none; }
.lf-tbl tbody tr { transition: background .12s ease; }
.lf-tbl tbody tr:hover { background: var(--card-2); }
.lf-tbl .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- Badge / status pill --- */
.lf-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px;
}
.lf-badge.good { background: var(--good-bg); color: var(--good-tx); }
.lf-badge.warn { background: var(--warn-bg); color: var(--warn-tx); }
.lf-badge.bad  { background: var(--bad-bg);  color: var(--bad-tx); }
.lf-badge.neutral { background: var(--paper-2); color: var(--ink-2); }

/* ====================== 5 · SCOPE FILTER + ANALYSE ===================== */
.scope-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.scope-pills { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scope-head {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3);
}
/* divider between "what" pills and "how" config controls */
.scope-div { width: 1px; align-self: stretch; min-height: 26px; background: var(--line); margin: 0 2px; }

.scope-pill {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--card); border: 1px solid var(--line); border-radius: 30px;
  padding: 9px 14px;
  font-family: var(--sans); font-size: 14px; color: var(--ink);
  box-shadow: var(--sh-1); white-space: nowrap; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.scope-pill:hover { border-color: var(--moss); }
.scope-pill.active { border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .16), var(--sh-1); }
.scope-pill .scope-label { color: var(--ink-2); font-weight: 500; }
.scope-pill .scope-val   { color: var(--ink); font-weight: 600; }
.scope-pill .scope-chev  { color: var(--ink-3); transition: transform .15s ease; }
.scope-pill.active .scope-chev { transform: rotate(180deg); }
.scope-count { display: inline-flex; align-items: baseline; gap: 3px; background: var(--paper-2); border-radius: 8px; padding: 2px 9px; font-variant-numeric: tabular-nums; }
.scope-count b { color: var(--ink); font-weight: 700; font-size: 13.5px; }
.scope-count .scope-slash { color: var(--ink-3); font-size: 12.5px; }
.scope-add { border-style: dashed; color: var(--ink-3); box-shadow: none; font-weight: 600; }

/* Multi-select popover */
.scope-pop { width: 372px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-3); overflow: hidden; }
.scope-pop .scope-search { display: flex; align-items: center; gap: 9px; margin: 14px 14px 4px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 11px 13px; color: var(--ink-3); font-size: 14px; }
.scope-pop .scope-tools { display: flex; align-items: center; gap: 14px; padding: 10px 16px 6px; }
.scope-pop .scope-tools a { color: var(--canopy); font-weight: 600; font-size: 13px; text-decoration: none; cursor: pointer; }
.scope-pop .scope-sort { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); }
.scope-pop .scope-row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.scope-pop .scope-row:hover { background: var(--card-2); }
.scope-pop .scope-name { font-size: 14px; font-weight: 500; color: var(--ink); flex: 1; }
.scope-pop .scope-ha { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.scope-pop .scope-check { width: 21px; height: 21px; border-radius: 6px; border: 1.5px solid var(--ink-4); background: var(--card); display: grid; place-items: center; flex-shrink: 0; color: #fff; }
.scope-pop .scope-check.on { background: var(--leaf); border-color: var(--leaf); }
.scope-pop .scope-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--card-2); }
.scope-pop .scope-foot .scope-ct { font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* Slider pill popover */
.scope-slider-pop { padding: 16px; min-width: 260px; }
.scope-slider-val { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
.scope-slider-val .scope-unit { font-family: var(--mono); font-size: 13px; color: var(--ink-3); margin-left: 4px; }
.scope-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 7px; border-radius: 6px; border: 1px solid var(--line); outline: none;
  background: linear-gradient(90deg, var(--leaf) var(--fill, 30%), var(--paper-2) var(--fill, 30%));
}
.scope-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--card); border: 3px solid var(--leaf); box-shadow: var(--sh-2); cursor: pointer; transition: transform .1s ease; }
.scope-slider::-webkit-slider-thumb:active { transform: scale(1.12); }
.scope-slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--card); border: 3px solid var(--leaf); box-shadow: var(--sh-2); cursor: pointer; }
.scope-ends { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: var(--ink-4); margin-top: 6px; }
.scope-chips { display: flex; gap: 7px; margin-top: 10px; flex-wrap: wrap; }
.scope-chip { padding: 7px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xs); font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.scope-chip.on { background: var(--good-bg); border-color: var(--leaf); color: var(--canopy); }

/* Toggle pill (boolean) — the pill IS the switch */
.scope-toggle { gap: 9px; }
.scope-toggle.on { border-color: var(--leaf); background: var(--good-bg); }
.scope-toggle.on .scope-label { color: var(--canopy); font-weight: 600; }
.scope-switch { width: 34px; height: 19px; border-radius: 20px; background: var(--ink-4); position: relative; display: inline-block; transition: background .18s; flex-shrink: 0; }
.scope-switch.on { background: var(--leaf); }
.scope-switch .knob { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: left .18s cubic-bezier(.2,.8,.3,1); }
.scope-switch.on .knob { left: 17px; }

/* Toggle pill backed by a real ui.input_switch (Bootstrap form-switch) — themed
   to Field Atlas so the native switch reads as a scope toggle. */
.scope-toggle-pill { display: inline-flex; align-items: center; gap: 8px; }
/* Collapse every Shiny/Bootstrap wrapper to a content-width inline row so the
   pill hugs the switch + label. Bootstrap's .form-check/.form-switch otherwise
   render block, full-width, with a 2.5em left pad — which made the pill long. */
.scope-toggle-pill .shiny-input-container,
.scope-toggle-pill .form-group,
.scope-toggle-pill .form-check,
.scope-toggle-pill .form-switch,
.scope-toggle-pill .checkbox {
  display: inline-flex !important;
  align-items: center;
  gap: 9px;
  width: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}
.scope-toggle-pill .form-check-input {
  width: 34px; height: 19px; min-width: 34px; flex: 0 0 auto;
  margin: 0 !important; cursor: pointer;
  background-color: var(--ink-4); border-color: var(--ink-4); box-shadow: none;
}
.scope-toggle-pill .form-check-input:checked { background-color: var(--leaf); border-color: var(--leaf); }
.scope-toggle-pill .form-check-input:focus { box-shadow: 0 0 0 3px rgba(79, 138, 76, .14); border-color: var(--leaf); }
/* Match the other pills' .scope-label (ink-2 / 500 / 14px / title-case / inline).
   The !important overrides bleed from the legacy `.shiny-input-container label`
   rule, which forces uppercase + a light rail-text colour + display:block. */
.scope-toggle-pill .form-check-label {
  font-family: var(--sans) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: var(--ink-2) !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  display: inline !important;
  margin: 0 !important;
  cursor: pointer;
}

/* ====================== 6b · .fa-page (migrated-page wrapper) =========== */
/* Opt-in: add class_="fa-page" on a migrated page's content wrapper. Re-themes
   Bootstrap/Shiny defaults (cards, headers, outline buttons, nav-tabs, data
   grids, contextual text) to Field Atlas without rewriting every ui.card. */
.fa-page { color: var(--ink); }
.fa-page h1, .fa-page h2 { font-family: var(--serif); font-weight: 500; letter-spacing: -.015em; color: var(--ink); }
.fa-page h3, .fa-page h4, .fa-page h5 { font-family: var(--serif); font-weight: 500; color: var(--ink); }
.fa-page .card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-1); }
.fa-page .card-header { background: var(--card-2); border-bottom: 1px solid var(--line); font-family: var(--serif); font-weight: 500; font-size: 16px; color: var(--ink); }
.fa-page .text-success { color: var(--leaf) !important; }
.fa-page .text-primary { color: var(--canopy) !important; }
.fa-page .text-info   { color: var(--sky) !important; }
.fa-page .text-muted  { color: var(--ink-3) !important; }
.fa-page .btn-outline-success { color: var(--leaf); border-color: var(--line); border-radius: var(--r-xs); font-weight: 600; }
.fa-page .btn-outline-success:hover { background: var(--good-bg); color: var(--canopy); border-color: var(--leaf); }
.fa-page .nav-tabs { border-bottom: 1px solid var(--line); }
.fa-page .nav-tabs .nav-link { color: var(--ink-2); border: none; font-weight: 600; }
.fa-page .nav-tabs .nav-link:hover { color: var(--ink); }
.fa-page .nav-tabs .nav-link.active { color: var(--canopy); background: transparent; border-bottom: 2px solid var(--leaf); }
.fa-page .alert-warning { background: var(--warn-bg); color: var(--warn-tx); border-color: var(--wheat-soft); border-radius: var(--r-xs); }
.fa-page .shiny-data-frame thead th { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
/* Location-type pills in card headers: badges inherit the header's serif font,
   whose metrics push the text high in the pill. Force sans + centered flex so
   the label (e.g. "Garden") sits dead-centre. */
.fa-page .card-header .badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--sans); line-height: 1; padding: 5px 11px;
}

/* Field Atlas form controls inside .fa-page (light context). Overrides the
   legacy dark-sidebar `.shiny-input-container label` styling so labels read on a
   light card; themes selectize / text inputs to tokens. */
.fa-page .shiny-input-container label,
.fa-page .input-label {
  color: var(--ink-3) !important;
  font-family: var(--mono); font-size: 10px; font-weight: 400;
  letter-spacing: .12em; text-transform: uppercase; margin-bottom: 6px;
}
.fa-page .selectize-input,
.fa-page input[type="text"], .fa-page input[type="search"], .fa-page select {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-xs); color: var(--ink);
}
/* Native <select>: replace the browser arrow with a tokenized chevron so it
   reads like the rest of the Field Atlas controls (and matches selectize). */
.fa-page select, .fa-page select.form-control, .fa-page select.form-select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding: 8px 34px 8px 12px; font-family: var(--sans); font-size: 13.5px;
  line-height: 1.4; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238C8268' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.fa-page .selectize-input.focus,
.fa-page input[type="text"]:focus, .fa-page input[type="search"]:focus, .fa-page select:focus {
  border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .14);
  outline: none;
}
.fa-page .selectize-dropdown { border: 1px solid var(--line); border-radius: var(--r-xs); box-shadow: var(--sh-2); z-index: 1000; }
.fa-page .selectize-dropdown .active { background: var(--good-bg); color: var(--canopy); }

/* Segmented radio — turns an inline ui.input_radio_buttons into a Field Atlas
   segmented control (e.g. the chart-type toggle). Reusable across data pages.
   !important + the extra .shiny-options-group scope beat the .fa-page label rule
   above so the pills aren't restyled as mono field-labels. */
.fa-seg-radio .control-label { display: none !important; }
/* Segmented track ("huge pill") holding the options; ample gap between them. */
.fa-seg-radio .shiny-options-group {
  display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 4px; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 30px;
}
.fa-seg-radio .shiny-options-group .radio,
.fa-seg-radio .shiny-options-group .radio-inline,
.fa-seg-radio .shiny-options-group .form-check,
.fa-seg-radio .shiny-options-group .form-check-inline { margin: 0; padding: 0; min-height: 0; }
.fa-seg-radio .shiny-options-group input[type="radio"] { display: none !important; }
.fa-seg-radio .shiny-options-group label {
  display: inline-flex !important; align-items: center; margin: 0 !important;
  /* !important so the side padding wins over the .radio-inline reset above
     (in Shiny the option label IS .radio-inline). */
  padding: 3px 10px !important; border-radius: 24px; cursor: pointer; white-space: nowrap;
  font-family: var(--sans) !important; font-size: 12px !important; font-weight: 600 !important;
  color: var(--ink-2) !important; text-transform: none !important; letter-spacing: normal !important;
  transition: all .15s ease;
}
.fa-seg-radio .shiny-options-group label:hover { color: var(--ink) !important; }
/* Selected type: chocolate fill on the cream track, cream text — strong, warm. */
.fa-seg-radio .shiny-options-group label:has(input:checked) {
  background: var(--soil); color: var(--card) !important; box-shadow: var(--sh-1);
}

/* Standard vertical rhythm for a result view (reuse on every migrated page,
   instead of scattered Bootstrap margin utilities):
   - .fa-result-head : the page/result title block (title + subtitle + rule).
   - .fa-section     : a section header (icon + serif title) between cards. */
.fa-result-head {
  margin: 0;
  padding-bottom: var(--sp-6);      /* 14px */
  border-bottom: 3px solid var(--leaf);
}
/* Result heading is the page's secondary title — smaller than the topbar's
   "page title" (.lf-topbar-title, 32px) so the page title reads as primary. */
.fa-result-head h2 { font-size: 27px; }
/* Guaranteed (non-collapsing) breathing room between the tabs and the title —
   a margin-top on the title collapses through the tab-pane wrappers. */
.fa-page .tab-content { padding-top: var(--sp-9); }   /* 20px */
.fa-section {
  display: flex;
  align-items: center;
  gap: var(--sp-2);                 /* icon ↔ title */
  margin: var(--sp-11) 0 var(--sp-6);  /* 30px above between sections, 14px below */
}
.fa-section .lf-panel-title { font-size: 21px; }   /* slightly larger section headers */
.fa-result-head + .fa-section { margin-top: var(--sp-6); }  /* 14px after the title */
.fa-section:first-child { margin-top: 0; }  /* first section relies on page padding */
/* Left-aligned action toolbar (e.g. a Download button) above a section; keep the
   following section close rather than the full 30px inter-section gap. */
.fa-toolbar { display: flex; margin: 0; }
.fa-toolbar + .fa-section { margin-top: var(--sp-10); }  /* 12px after a toolbar */

/* Analyse button + status */
.scope-status { font-size: 12.5px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 7px; }
.scope-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); }
.scope-status.dirty { color: var(--wheat); font-weight: 600; }
.scope-status.dirty::before { background: var(--wheat); box-shadow: 0 0 0 3px rgba(215, 162, 58, .2); }
.scope-analyse {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 18px; border-radius: 30px;
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; background: var(--leaf); color: #fff;
  box-shadow: 0 4px 14px rgba(79, 138, 76, .32); cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .15s ease;
}
.scope-analyse:hover { transform: translateY(-1px); }
.scope-analyse.idle { background: var(--card); color: var(--ink-3); border: 1px solid var(--line); box-shadow: none; cursor: default; }
.scope-analyse.idle:hover { transform: none; }
.scope-pending { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 20px; background: rgba(255, 255, 255, .25); font-family: var(--mono); font-size: 11px; font-weight: 700; }
.scope-spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: lf-spin .7s linear infinite; }
@keyframes lf-spin { to { transform: rotate(360deg); } }

/* ====================== 6 · OVERLAYS =================================== */
/* Info popover (click-to-open metric help) */
.info-btn { display: inline-grid; place-items: center; width: 24px; height: 24px; border: none; background: transparent; color: var(--ink-4); border-radius: 50%; cursor: pointer; transition: all .12s ease; vertical-align: middle; }
.info-btn:hover { color: var(--leaf); background: var(--card-2); }
.info-btn.open { color: var(--leaf); background: var(--good-bg); }
/* "How to use" guide rendered inside an info popover (Activity Tracker etc.) */
.lf-howto { font-family: var(--sans); }
.lf-howto .lf-howto-kicker { font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: 2px; }
.lf-howto .lf-howto-title { font-family: var(--serif); font-size: 18px; font-weight: 500; letter-spacing: -.01em; color: var(--ink); margin: 0 0 12px; }
.lf-howto .lf-howto-head { font-family: var(--sans); font-size: 12.5px; font-weight: 600; color: var(--canopy); margin: 13px 0 4px; }
.lf-howto .lf-howto-head:first-of-type { margin-top: 0; }
.lf-howto p { font-family: var(--sans); font-size: 13px; line-height: 1.55; color: var(--ink-2); margin: 0 0 4px; }
.info-pop { position: relative; width: 286px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-3); padding: 15px 16px 16px; }
.info-pop::before { content: ""; position: absolute; top: -6px; left: 16px; width: 11px; height: 11px; background: var(--card); border-left: 1px solid var(--line); border-top: 1px solid var(--line); transform: rotate(45deg); }
.info-pop .info-x { position: absolute; top: 11px; right: 11px; width: 23px; height: 23px; border-radius: 50%; border: 1px solid var(--line); background: var(--card-2); color: var(--ink-3); display: grid; place-items: center; cursor: pointer; }
.info-pop .info-x:hover { background: var(--bad-bg); color: var(--bad); }
.info-pop .info-k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.info-pop .info-t { font-family: var(--serif); font-size: 17px; font-weight: 600; color: var(--ink); line-height: 1.15; margin-top: 3px; padding-right: 22px; }
.info-pop .info-b { font-size: 13px; line-height: 1.5; color: var(--ink-2); margin-top: 8px; }
.info-pop .info-s { margin-top: 11px; padding-top: 10px; border-top: 1px dashed var(--line); font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }

/* Progress toast (determinate, pinned bottom-right) */
.scope-progress { position: fixed; right: 26px; bottom: 26px; z-index: 1200; width: 372px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-3); padding: 16px 18px; }
.scope-progress-bar { height: 7px; border-radius: 6px; background: var(--paper-2); overflow: hidden; margin: 2px 0 14px; }
.scope-progress-fill { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--leaf), var(--leaf-bri)); transition: width .28s ease; background-size: 28px 28px; animation: lf-stripe 1s linear infinite; }
.scope-progress.done .scope-progress-fill { background: var(--leaf); animation: none; }
@keyframes lf-stripe { from { background-position: 0 0; } to { background-position: 28px 0; } }
.scope-progress-row { display: flex; align-items: center; gap: 12px; }
.scope-progress-ic { width: 30px; height: 30px; border-radius: 9px; background: var(--paper-2); display: grid; place-items: center; color: var(--ink-3); flex-shrink: 0; }
.scope-progress.done .scope-progress-ic { background: var(--good-bg); color: var(--canopy); }
.scope-progress-title { font-family: var(--serif); font-size: 16px; font-weight: 600; color: var(--ink); line-height: 1.15; }
.scope-progress-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.scope-progress-pct { margin-left: auto; font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--ink-3); }
.scope-progress-x { position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-4); cursor: pointer; }
.scope-progress-x:hover { background: var(--paper-2); }
.scope-spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(79, 138, 76, .25); border-top-color: var(--leaf); animation: lf-spin .7s linear infinite; display: inline-block; }

/* Bootstrap popover shell (scope-pill / info popovers attach to <body>, so
   they live OUTSIDE any .fa-page wrapper and need global theming). */
.popover { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-3); max-width: 396px; font-family: var(--sans); }
.popover .popover-body { padding: 14px 16px; color: var(--ink); }
/* bslib renders a tiny (0.55rem) ✕ close button with inline sizing — enlarge it
   so it's an easy target. !important is needed to beat the inline styles. Extra
   body padding-top keeps it clear of the first row of content. */
.popover .btn-close {
  width: 0.7rem !important; height: 0.7rem !important;
  background-size: 0.7rem !important;
  top: 0.6rem !important; right: 0.6rem !important;
  opacity: .5; transition: opacity .12s ease;
}
.popover .btn-close:hover { opacity: 1; }
.popover:has(.btn-close) .popover-body { padding-top: 20px; }
.popover .popover-header { background: var(--card-2); border-bottom: 1px solid var(--line); font-family: var(--serif); color: var(--ink); }
.popover .shiny-input-container { margin-bottom: 10px; }
.popover label { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.popover .selectize-input, .popover input[type="text"], .popover select {
  border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--card); color: var(--ink);
}
.popover .selectize-input.focus, .popover input[type="text"]:focus, .popover select:focus {
  border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .14);
}
.popover .selectize-dropdown { border: 1px solid var(--line); border-radius: var(--r-xs); box-shadow: var(--sh-2); }
.popover .selectize-dropdown .active { background: var(--good-bg); color: var(--canopy); }

/* Multi-select checklist popover (farms / locations) — the spec's .scope-pop
   pattern rendered with Shiny checkbox inputs. */
.scope-checklist-wrap { width: 100%; }
/* Search box above Select-all (client-side filter of the options). */
.scope-search {
  width: 100%; margin: 0 0 10px; padding: 9px 12px;
  font-family: var(--sans); font-size: 14px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.scope-search:focus { outline: none; border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .14); }
.scope-search::placeholder { color: var(--ink-4); }
.scope-checklist-all { padding: 2px 2px 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.scope-checklist { max-height: 240px; overflow-y: auto; margin: 0; }
/* Force readable ink on the option labels regardless of Shiny's markup
   (.checkbox/.radio>label>span in some versions, .form-check>.form-check-label
   in others) — without this they inherit a faint tone. Covers both the
   multi-select checklists and the single-select radiolist (Soil farm picker). */
.popover .scope-checklist-wrap .checkbox label,
.popover .scope-checklist-wrap .checkbox label span,
.popover .scope-checklist-wrap .radio label,
.popover .scope-checklist-wrap .radio label span,
.popover .scope-checklist-wrap .form-check-label,
.popover .scope-checklist-wrap .form-check-label span {
  color: var(--ink) !important;
  font-family: var(--sans);
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
}
/* Rows: Shiny renders input_checkbox(_group)/radio_buttons as
   `.checkbox/.radio > label > input + span`. */
.popover .scope-checklist-wrap .shiny-input-container,
.popover .scope-checklist-wrap .checkbox,
.popover .scope-checklist-wrap .radio { margin: 0; }
.popover .scope-checklist-wrap .checkbox > label,
.popover .scope-checklist-wrap .radio > label {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 6px; margin: 0; width: 100%;
  font-family: var(--sans); font-size: 14px; font-weight: 500; color: var(--ink);
  text-transform: none; letter-spacing: normal; border-radius: var(--r-xs); cursor: pointer;
}
.popover .scope-checklist .checkbox > label:hover,
.popover .scope-checklist .radio > label:hover { background: var(--card-2); }
.popover .scope-checklist-wrap input[type="checkbox"],
.popover .scope-checklist-wrap input[type="radio"] {
  -webkit-appearance: auto; appearance: auto;
  width: 18px; height: 18px; min-width: 18px; margin: 0;
  accent-color: var(--leaf); flex-shrink: 0; cursor: pointer;
}
.scope-checklist-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--line);
}
.scope-checklist-foot .scope-ct { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.scope-checklist-foot .lf-btn { padding: 8px 22px; }

/* ionRangeSlider (ui.input_slider) themed to leaf — used in scope slider pills
   and elsewhere. */
.irs--shiny .irs-bar { background: var(--leaf); border-color: var(--leaf); }
.irs--shiny .irs-handle > i:first-child { background-color: var(--leaf); }
.irs--shiny .irs-single, .irs--shiny .irs-from, .irs--shiny .irs-to { background-color: var(--leaf); }
.irs--shiny .irs-line { background: var(--paper-2); border-color: var(--line); }
.irs--shiny .irs-min, .irs--shiny .irs-max { background: var(--paper-2); color: var(--ink-3); font-family: var(--mono); }

/* Shiny progress notifications ("Fetching biodiversity data…" / "Loading
   location data…"): force the detail line onto its own row (it's a span that
   otherwise renders cramped right after the bold message). Folded in from main. */
.progress-text .progress-detail { display: block; }

/* ====================== 7 · PLOTLY / FOLIUM HOOKS ===================== */
/* Plot area is themed in Python (field_atlas template). Tame the modebar here. */
.modebar { opacity: .55; transition: opacity .2s ease; }
.modebar:hover { opacity: 1; }
.js-plotly-plot .modebar-btn path { fill: var(--ink-3) !important; }
.js-plotly-plot .modebar-btn.active path,
.js-plotly-plot .modebar-btn:hover path { fill: var(--leaf) !important; }
/* Folium popup ("field passport") shell — match card styling */
.leaflet-popup-content-wrapper { border-radius: var(--r-sm) !important; box-shadow: var(--sh-3) !important; background: var(--card) !important; }
.leaflet-popup-tip { background: var(--card) !important; }
/* Folium map host — give it height and a tokenized live-loading overlay. */
#map_container { position: relative; min-height: 520px; }
#map_container.recalculating { opacity: .55; pointer-events: none; }
#map_container.recalculating::before {
  content: "Loading map…"; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); z-index: 1000;
  font-family: var(--serif); font-size: 16px; color: var(--ink);
  background: var(--card); padding: 12px 22px; border-radius: var(--r);
  box-shadow: var(--sh-3); border: 1px solid var(--line);
}

/* ============================================================================
   8 · LEGACY — used by pages not yet migrated to the Field Atlas components.
        Re-themed to tokens so half-migrated pages stay coherent. Delete each
        block as its page moves onto sections 4/5.
   ============================================================================ */
html { font-family: var(--sans); }

/* Old per-page filter sidebar (dark). Re-themed slate -> Field Atlas green. */
.sidebar-container {
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--rail-bg-top), var(--rail-bg-bot));
  border-right: 1px solid var(--canopy);
  padding: 25px;
  box-shadow: var(--sh-1);
  transition: all 0.3s ease;
  flex: 0 0 auto; align-self: stretch; min-height: 100vh;
}
.sidebar-collapsed { width: 60px !important; overflow: hidden; padding: 10px !important; }
.sidebar-collapsed *:not(.collapse-toggle):not(script):not(style) { display: none !important; }
.sidebar-container h3, .sidebar-container h4 { color: var(--rail-head); font-weight: 600; margin-top: 10px; }
.sidebar-container .help-block, .sidebar-container p { color: var(--rail-text) !important; font-size: 0.85em; margin-bottom: 8px; }

.input-label, .shiny-input-container label { color: var(--rail-text) !important; font-weight: 500; font-size: 0.9em; text-transform: uppercase; margin-bottom: 6px; display: block; }
.sidebar-container .shiny-input-container input,
.sidebar-container .shiny-input-container select,
.sidebar-container .shiny-input-container .selectize-input {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xs);
  padding: 10px 15px; color: var(--ink); font-size: 0.95em; width: 100%;
}
.sidebar-container .shiny-input-container input:focus,
.sidebar-container .shiny-input-container select:focus,
.sidebar-container .shiny-input-container .selectize-input.focus {
  outline: none; border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .14);
}
.collapse-toggle { background: none; border: none; color: var(--rail-text); font-size: 1.2em; cursor: pointer; padding: 5px; margin-bottom: 20px; text-align: left; width: 100%; }

.main-content { padding: 30px; background: var(--paper); overflow-y: auto; flex-grow: 1; }
.main-expanded { width: 100% !important; flex: 1; }

/* Layout helpers (structural — keep) */
nav, .navbar { margin-bottom: 0 !important; }
.container-fluid { padding-left: 0 !important; padding-right: 0 !important; margin-left: 0 !important; margin-right: 0 !important; width: 100% !important; max-width: 100% !important; }
.row.flex-grow { display: flex; flex-wrap: nowrap; align-items: stretch; margin: 0 !important; width: 100% !important; }
html, body, .container-fluid, .row.flex-grow { min-height: 100vh; }

.sidebar-section-label, .sidebar-howto-title { color: var(--rail-text); opacity: .8; font-size: 0.72em; font-weight: 700; text-transform: uppercase; letter-spacing: 1.1px; margin: 12px 0 4px 0; display: block; }
.sidebar-divider { height: 1px; background: rgba(255, 255, 255, 0.12); margin: 14px 0; }
.sidebar-howto { margin-top: 8px; }
.sidebar-howto p, .sidebar-howto li { color: var(--rail-text) !important; opacity: .75; font-size: 0.78em !important; line-height: 1.5; margin-bottom: 6px !important; }
.sidebar-howto ol { padding-left: 18px; margin-bottom: 0; }

.sidebar-select-all-btn { display: inline-block; width: 100%; margin: 6px 0 10px 0; padding: 8px 12px; border: 1px solid rgba(231,222,201,.22); border-radius: var(--r-xs); background: rgba(231,222,201,.08); color: var(--rail-text); font-size: 0.78em; font-weight: 600; line-height: 1.2; text-align: center; white-space: normal; transition: background 0.2s ease, border-color 0.2s ease; cursor: pointer; }
.sidebar-select-all-btn:hover, .sidebar-select-all-btn:focus { background: rgba(79,138,76,.22); border-color: var(--leaf); color: #fff; text-decoration: none; }
.sidebar-select-all-btn.active { background: rgba(79,138,76,.30); border-color: var(--leaf); color: #fff; }

/* Shared buttons — re-themed to leaf */
.btn-green-download { background-color: var(--leaf) !important; color: #fff !important; border: none !important; font-weight: 500; transition: background 0.2s ease; padding: 8px 16px; border-radius: var(--r-xs); font-size: 0.88em; text-align: center; cursor: pointer; white-space: nowrap; display: inline-block; }
.btn-green-download:hover { background-color: var(--pine) !important; }
a.btn-green-download { text-decoration: none; color: #fff !important; }
a.btn-green-download:hover { text-decoration: none; }

.btn-fullscreen { background: none; border: 1px solid var(--line); border-radius: var(--r-xs); color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 600; line-height: 1; padding: 5px 10px; transition: background 0.2s, border-color 0.2s, color 0.2s; white-space: nowrap; flex-shrink: 0; }
.btn-fullscreen:hover { background: var(--good-bg); border-color: var(--leaf); color: var(--canopy); }
.section-card:fullscreen, .viz-card:fullscreen, .download-card:fullscreen { background: var(--card); overflow: auto; padding: 24px; border-radius: 0; }
.viz-card:fullscreen #spg_chart_host { height: calc(100vh - 110px) !important; }

/* DataTable selected-row highlight -> leaf */
table.dataTable.display > tbody > tr:has(.selected) > * { box-shadow: inset 0 0 0 999em var(--leaf) !important; color: #fff; }

/* Variable description card */
.variable-description-card { margin-top: 10px; padding: 15px; background-color: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.description-header { margin-bottom: 8px; font-weight: bold; color: var(--ink); }
.description-text { font-size: 14px; color: var(--ink-2); line-height: 1.4; }
.variable-description-card .description-text { margin-bottom: 10px; color: var(--ink) !important; font-size: 0.92em; line-height: 1.4; }

/* Homepage (legacy hero — restyled in Phase 1 smoke test) */
.homepage-body { display: flex; align-items: center; }
.homepage-body-h1 { color: var(--canopy); font-size: 48px; font-weight: 500; letter-spacing: 3px; font-family: var(--serif); }
.bold-text { font-weight: bolder; }
.homepage-content { padding-top: 75px; display: flex; flex-direction: column; }
.homepage-head { display: flex; justify-content: center; }
.text-sc { font-variant-caps: small-caps; }
.homepage-background { background-color: var(--paper); min-height: calc(100vh - 50px); margin: -24px; }
.homepage-lead-text-block { max-width: 100%; text-align: justify; }
.light h1, .light h2, .light h3, .light h4 { color: var(--ink); font-family: var(--serif); font-weight: 500; }
.light .lead, .light { color: var(--ink-2); }
@media (min-width: 768px) { .homepage-lead-text-block { max-width: 85%; } }
.bottom { margin-top: auto; }
.ackn-elt { display: flex; align-items: center; gap: 1rem; }
.ackn-elt:not(:last-child) { margin-bottom: 15px; }
.light a:not(.btn) { text-decoration: underline; color: var(--leaf); }
.light a:not(.btn):hover { text-decoration: underline; color: var(--pine); }
.centered-content { display: flex; justify-content: center; margin: 0 auto; max-width: 1500px; }
.custom-scroll-main { overflow-y: auto; }
.landscape { padding: 10px 40px; display: flex; flex-direction: column; }
.download-button { padding: 5px 40px; display: flex; flex-direction: column; text-align: center; }
.card_title { font-weight: bold; text-align: center; }
.number { text-align: center; }
.total_farms { align-items: center; text-align: center; }
.world_map { object-position: center; }

/* Narrow screens: let the rail and content stack rather than clip */
@media (max-width: 820px) {
  body { padding-left: 0; }
  .lf-rail { position: static; width: 100%; height: auto; bottom: auto; flex-direction: column; }
}

/* ====================== GHG · Cool Farm (bespoke) ======================
   The GHG assessment modal renders into <body> (outside .fa-page), so its
   chrome needs real classes in the shared sheet. Tokenized restyle of the
   Cool Farm modal + the .cfp-summary result block. */

.cool-farm-modal { font-family: var(--sans); color: var(--ink); }
.cool-farm-modal .tab-content { padding: 22px 4px; min-height: 360px; }
.cool-farm-modal h4 {
  font-family: var(--serif); font-weight: 500; font-size: 17px; color: var(--ink);
  border-bottom: 1px solid var(--line); padding-bottom: 8px; margin: 26px 0 16px;
}
.cool-farm-modal h4:first-child { margin-top: 0; }
.cool-farm-modal label, .cool-farm-modal .control-label, .cool-farm-modal .shiny-input-container label {
  font-family: var(--mono); font-size: 10px; font-weight: 400; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3) !important; margin-bottom: 6px;
}
.cool-farm-modal .form-control, .cool-farm-modal .form-select,
.cool-farm-modal .selectize-input {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xs);
  color: var(--ink); padding: 9px 12px;
}
.cool-farm-modal .form-control:focus, .cool-farm-modal .form-select:focus,
.cool-farm-modal .selectize-input.focus {
  border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .14); outline: none;
}

/* Modal tab strip */
.cool-farm-modal .nav-tabs { border-bottom: 1px solid var(--line); margin-bottom: 0; }
.cool-farm-modal .nav-tabs .nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  border: none; color: var(--ink-2); font-family: var(--sans); font-weight: 600;
  font-size: 13.5px; padding: 11px 18px;
}
.cool-farm-modal .nav-tabs .nav-link:hover:not(.active) { color: var(--ink); background: var(--card-2); }
.cool-farm-modal .nav-tabs .nav-link.active {
  color: var(--canopy); background: transparent; border-bottom: 2px solid var(--leaf);
}

/* Auto-populated status + helper notes */
.cool-farm-modal .auto-populate-status { padding: 0; background: transparent; border: 0; }
.cool-farm-modal .auto-populate-status p { margin: 0; }
.cool-farm-modal .auto-populate-status p:empty { display: none; }
.cool-farm-modal .auto-populate-status p:not(:empty) {
  background: var(--good-bg); border-left: 3px solid var(--leaf); color: var(--canopy);
  padding: 12px 15px; border-radius: var(--r-xs);
}
.cool-farm-modal .auto-populate-status .recalculating::before { content: none !important; }
.cool-farm-modal .auto-populate-status .recalculating { opacity: 1 !important; }
.cool-farm-modal .auto-fill-note {
  background: var(--good-bg); color: var(--canopy); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: var(--r-xs); font-size: 12.5px; margin-bottom: 15px;
}
.cool-farm-modal .help-text { color: var(--ink-3); font-size: 12.5px; margin: 0; }
.cool-farm-modal .fertilizer-section {
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px; margin-bottom: 18px;
}
.cool-farm-modal .calculation-info, .cool-farm-modal .info-box {
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-xs);
  padding: 14px; margin-top: 18px;
}
.cool-farm-modal .info-box p { margin: 0; color: var(--ink-2); font-size: 12.5px; }

/* Result block rendered inside the emissions card */
.cfp-summary {
  text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px 20px; color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.45;
}
.cfp-header {
  display: flex; align-items: center; gap: 10px; font-family: var(--serif);
  font-weight: 500; font-size: 17px; color: var(--ink); margin-bottom: 6px;
}
.cfp-header .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--leaf); box-shadow: 0 0 0 3px rgba(79, 138, 76, .18); }
.cfp-sub { color: var(--ink-3); margin-bottom: 12px; }
.cfp-metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 10px 0 4px; }
.cfp-metric { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-xs); padding: 10px 12px; }
.cfp-metric .label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); margin-bottom: 4px; }
.cfp-metric .value { font-family: var(--serif); font-weight: 600; font-size: 19px; color: var(--ink); font-variant-numeric: tabular-nums; }
.cfp-rule { border-top: 1px dashed var(--line); margin: 14px 0; }
.cfp-breakdown h5 { font-family: var(--serif); font-size: 15px; font-weight: 500; margin: 0 0 8px; color: var(--ink); }
.cfp-breakdown ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.cfp-breakdown li { display: flex; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xs); padding: 8px 10px; }
.cfp-breakdown .model { font-weight: 600; color: var(--ink); }
.cfp-breakdown .nums { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ====================== Soil Insights (bespoke) ========================
   The soil result cards (farm header, field cards, metric bars, texture
   triangle, legend, downloads) are rendered server-side with these class
   names. Retokenized from the old dark inline stylesheet to the Field Atlas
   light surfaces. Triangle SVG building stays in the page's inline <script>. */

/* Farm header banner */
.farm-header {
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--ink); padding: 20px 24px; display: flex; flex-wrap: wrap;
  gap: 30px; align-items: center; margin-bottom: 18px;
}
.farm-header h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 22px; letter-spacing: -.01em; }
.farm-header-meta { display: flex; gap: 30px; flex-wrap: wrap; }
.meta-pill { display: flex; flex-direction: column; }
.meta-pill .label { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 3px; }
.meta-pill .value { font-size: 14px; font-weight: 500; color: var(--ink); }

/* Fields section + cards */
.fields-section { padding: 6px 0 0; }
.fields-section h3, .farm-map-section h3 {
  font-family: var(--serif); font-weight: 500; font-size: 19px; color: var(--ink);
  letter-spacing: -.01em; text-transform: none; margin-bottom: 16px;
}
.field-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; margin-bottom: 18px; box-shadow: var(--sh-1);
}
.field-card-header {
  background: var(--card-2); border-bottom: 1px solid var(--line);
  padding: 12px 18px; display: flex; justify-content: space-between; align-items: center;
}
.field-card-header .field-title { font-weight: 600; color: #fff; font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.35); }
.field-card-header .field-coords { font-size: 11px; color: rgba(255,255,255,.85); font-family: var(--mono); text-shadow: 0 1px 2px rgba(0,0,0,.3); }
.soil-source-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); padding: 14px 20px 4px; }

/* Metric rows + bars */
.soil-metrics { display: flex; flex-direction: column; gap: 18px; padding: 12px 20px 20px; border-bottom: 1px solid var(--line); }
.soil-metric-row { display: flex; flex-direction: column; gap: 5px; }
.metric-header { display: flex; justify-content: space-between; align-items: center; }
.metric-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.metric-right { display: flex; align-items: center; gap: 8px; }
.metric-value { font-size: 16px; font-weight: 700; color: var(--ink); font-family: var(--mono); min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.metric-bar-track { height: 8px; background: var(--paper-2); border-radius: 4px; overflow: hidden; }
.metric-scale { display: flex; justify-content: space-between; font-size: 11px; }
.scale-edge { color: var(--ink-4); }
.scale-hint { color: var(--canopy); font-weight: 500; }

/* Status badges */
.status-badge { display: inline-block; font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.status-optimal, .status-healthy, .status-clay-loam { background: var(--good-bg); color: var(--good-tx); }
.status-acceptable, .status-low, .status-sandy, .status-clay { background: var(--warn-bg); color: var(--warn-tx); }
.status-poor, .status-very-low, .status-heavy-clay { background: var(--bad-bg); color: var(--bad-tx); }
.status-unknown { background: var(--card-2); color: var(--ink-3); }

/* Map + states */
.farm-map-section { padding: 6px 0 8px; }
.farm-map-compact { max-width: 100%; min-width: 360px; }
.soil-error { background: var(--bad-bg); border: 1px solid var(--bad-tx); border-radius: var(--r-xs); padding: 16px 20px; color: var(--bad-tx); font-size: 13px; margin: 18px 0; }
.soil-empty { padding: 60px 30px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* Texture-triangle info + expand controls + legend */
.tri-info-btn { background: rgba(255,255,255,.15); border: 1.5px solid rgba(255,255,255,.4); border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; padding: 0; }
.tri-info-btn:hover { background: rgba(255,255,255,.3); }
.tri-info-popover { position: absolute; right: 0; top: 30px; width: 280px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px 16px; box-shadow: var(--sh-3); z-index: 1000; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.tri-info-popover strong { display: block; margin-bottom: 6px; color: var(--canopy); }
.tri-expand-btn { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-xs); color: var(--ink-2); font-size: 15px; cursor: pointer; padding: 3px 8px; line-height: 1; flex-shrink: 0; }
.tri-expand-btn:hover { background: var(--paper-2); border-color: var(--moss); }
.tri-legend { display: flex; flex-wrap: wrap; gap: 7px; padding: 6px 20px 16px; }
.tri-legend-item { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border: 1.5px solid var(--line); border-radius: 20px; background: var(--card); cursor: pointer; user-select: none; font-size: 12px; color: var(--ink-2); transition: background .15s, border-color .15s, opacity .15s; }
.tri-legend-item:hover { border-color: var(--moss); background: var(--card-2); }
.tri-legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.tri-legend-off { opacity: .42; background: var(--card-2); }
.tri-legend-off .tri-legend-label { text-decoration: line-through; }
.tri-legend-off .tri-legend-dot { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--ink-4); }

/* Source coverage/resolution info tooltip */
.src-info-wrap { position: relative; display: inline-flex; align-items: center; }
.src-info-btn { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); background: var(--card-2); color: var(--ink-3); font-size: 10px; font-weight: 700; line-height: 1; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; }
.src-info-btn:hover { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.src-info-pop { display: none; position: absolute; top: 22px; left: 0; z-index: 9000; width: 232px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 11px 13px; box-shadow: var(--sh-3); font-size: 11px; line-height: 1.35; color: var(--ink-2); }
.src-info-wrap:hover .src-info-pop, .src-info-btn:focus + .src-info-pop { display: block; }

/* Download buttons */
.btn-dl { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-xs); padding: 8px 16px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s; }
.btn-dl:hover { background: var(--card-2); border-color: var(--moss); }
.btn-dl-excel { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn-dl-excel:hover { background: var(--pine); border-color: var(--pine); }
.btn-dl-pdf { background: var(--clay); border-color: var(--clay); color: #fff; }
.btn-dl-pdf:hover { background: var(--soil); border-color: var(--soil); }

/* Data-source override: checkbox toggle buttons inside the scope popover */
#soil_source_override .shiny-options-group,
#soil_source_override_user .shiny-options-group { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
#soil_source_override .checkbox, #soil_source_override_user .checkbox { margin: 0; padding: 0; }
#soil_source_override input[type=checkbox], #soil_source_override_user input[type=checkbox] { display: none; }
#soil_source_override .checkbox label, #soil_source_override_user .checkbox label {
  display: flex; align-items: center; width: 100%; min-height: 34px; padding: 6px 10px; box-sizing: border-box;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-xs); cursor: pointer;
  font-size: 11.5px; font-weight: 500; color: var(--ink-2); letter-spacing: .03em; user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
#soil_source_override .checkbox label:hover, #soil_source_override_user .checkbox label:hover { background: var(--card-2); border-color: var(--moss); color: var(--ink); }
#soil_source_override label:has(input[type=checkbox]:checked), #soil_source_override_user label:has(input[type=checkbox]:checked) { background: var(--good-bg); border-color: var(--leaf); color: var(--canopy); font-weight: 600; }
#soil_source_override label:has(input[type=checkbox]:disabled), #soil_source_override_user label:has(input[type=checkbox]:disabled) { background: var(--card-2); border-color: var(--line); color: var(--ink-4); cursor: not-allowed; pointer-events: none; }

/* Topbar language switcher (EN/ES/PT) — keep the segmented options on one
   line regardless of how little room the heading leaves. */
.lf-lang-seg .shiny-options-group { flex-wrap: nowrap !important; white-space: nowrap; }

/* ====================== Reportes Generales (SPG tables) ================
   Field Atlas data-grid theming for the SPG (Construyendo Caminos) report
   tables — replaces the old per-page inline <style> wall. Scoped to .spg-card
   so it only touches these two cards. */

/* Let the data grid size to its content (no inner scroll box). */
.spg-card .shiny-data-frame,
.spg-card .html-fill-container,
.spg-card .html-fill-item {
  height: auto !important; max-height: none !important; min-height: 0 !important;
  width: 100% !important; max-width: 100% !important;
}
.spg-card .table-scroll { width: 100%; overflow-x: auto; }

/* Header — mono uppercase on a warm strip (matches .lf-tbl). */
.spg-card .shiny-data-grid-table thead th,
.spg-card .shiny-data-frame table thead th {
  background: var(--card-2) !important; color: var(--ink-3) !important;
  font-family: var(--mono); font-weight: 600; font-size: 10px;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 11px 14px !important; border-bottom: 1.5px solid var(--line) !important;
  text-align: center !important; white-space: normal !important;
  vertical-align: bottom !important; min-width: 110px;
}
.spg-card .shiny-data-grid-table thead th:first-child,
.spg-card .shiny-data-frame table thead th:first-child {
  text-align: left !important; min-width: 175px;
}

/* Body rows — tokenized cells, soft dividers, warm hover + zebra. */
.spg-card .shiny-data-grid-table tbody td,
.spg-card .shiny-data-frame table tbody td {
  padding: 10px 14px !important; font-size: 13px !important; color: var(--ink) !important;
  vertical-align: middle !important; text-align: center !important;
  border-bottom: 1px solid var(--line-soft) !important;
}
.spg-card .shiny-data-grid-table tbody td:first-child,
.spg-card .shiny-data-frame table tbody td:first-child {
  text-align: left !important; font-weight: 600 !important; color: var(--ink) !important;
}
.spg-card .shiny-data-grid-table tbody tr:nth-child(even),
.spg-card .shiny-data-frame table tbody tr:nth-child(even) { background: var(--card-2); }
.spg-card .shiny-data-grid-table tbody tr:hover,
.spg-card .shiny-data-frame table tbody tr:hover { background: var(--good-bg) !important; }
.spg-card .shiny-data-grid-table tbody tr:last-child td,
.spg-card .shiny-data-frame table tbody tr:last-child td { border-bottom: none !important; }

/* No-data message inside an SPG card. */
.spg-card .no-data-msg { padding: 28px; text-align: center; color: var(--ink-3); font-size: 13.5px; font-style: italic; }

/* ====================== Docs (Data Cleaning) ==========================
   Static documentation page — tokenized callouts, numbered steps, and the
   impact banner (replaces the old inline <style> wall + dark sidebar). */

/* Objective / lead callout — card-2 fill with a leaf accent rule. */
.docs-objective {
  background: var(--card-2); border: 1px solid var(--line);
  border-left: 3px solid var(--leaf); border-radius: var(--r-xs);
  padding: 18px 20px; color: var(--ink-2); line-height: 1.6; font-size: 14.5px;
}

/* Numbered cleaning steps. */
.docs-steps { display: flex; flex-direction: column; gap: 12px; }
.docs-step {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xs);
  padding: 16px 18px; transition: border-color .15s ease, box-shadow .15s ease;
}
.docs-step:hover { border-color: var(--moss); box-shadow: var(--sh-1); }
.docs-step-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--leaf); color: #fff; display: grid; place-items: center;
  font-family: var(--mono); font-size: 13px; font-weight: 600;
}
.docs-step-title { font-weight: 600; color: var(--ink); font-size: 14.5px; margin-bottom: 3px; }
.docs-step-desc { color: var(--ink-2); font-size: 13.5px; line-height: 1.5; }

/* Impact banner — deep-green gradient (replaces the off-palette purple). */
.docs-impact {
  background: linear-gradient(135deg, var(--canopy), var(--pine));
  color: var(--card); border-radius: var(--r); padding: 22px 24px;
  box-shadow: var(--sh-1);
}
.docs-impact .lf-panel-title { color: var(--rail-head); }
.docs-impact .lf-ic { color: var(--rail-head); }
.docs-impact p { opacity: .92; line-height: 1.6; margin: 0; }

.docs-doclink { display: flex; justify-content: center; padding-top: 4px; }
.docs-updated {
  text-align: center; color: var(--ink-4); font-style: italic; font-size: 13px;
  margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line);
}

/* ====================== Download Data (residual page-unique bits) =======
   The dark sidebar, cards, stats, info tooltip and buttons now reuse shared
   components (scope bar, .lf-card, .lf-metric, info_popover, .lf-btn). Only the
   genuinely download-specific controls remain here, tokenized: the aggregation
   panel + Statistics chips, the pager, and a couple of layout wrappers. */

/* Aggregation / group-by panel. */
.dl-agg {
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 14px 16px; margin-bottom: 14px;
}
.dl-agg .control-label, .dl-agg > .shiny-input-container > label {
  font-family: var(--mono); font-size: 10px !important; font-weight: 400 !important;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3) !important;
}
.dl-agg .shiny-options-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.dl-agg .checkbox, .dl-agg .checkbox-inline { margin: 0; padding: 0; }
.dl-agg input[type=checkbox] { display: none; }
/* Statistics = multi-select toggle chips (mean / sum / …). */
.dl-agg .shiny-options-group label {
  display: inline-flex; align-items: center; justify-content: center; min-width: 60px;
  margin: 0; padding: 6px 15px !important; border-radius: 20px;
  border: 1.5px solid var(--leaf); background: transparent;
  font-family: var(--sans); font-size: 12.5px; font-weight: 600;
  color: var(--canopy) !important; text-transform: none !important; letter-spacing: 0;
  cursor: pointer; user-select: none; transition: background .15s ease, color .15s ease;
}
.dl-agg .shiny-options-group label:hover { background: var(--good-bg); }
.dl-agg .shiny-options-group label:has(input[type=checkbox]:checked) {
  background: var(--leaf); border-color: var(--leaf); color: #fff !important;
}
/* Raw rows (no group-by) → Statistics don't apply: grey out + disable. */
.dl-agg.dl-no-agg .shiny-input-container:has(.shiny-options-group) {
  opacity: 0.4; pointer-events: none;
}

/* Pager (buttons use .lf-btn-ghost). */
.dl-pager { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; }
.dl-page-info { font-size: 13px; color: var(--ink-3); font-weight: 500; }
.dl-pagesize { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.dl-pagesize-label { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.dl-pagesize .shiny-input-container { width: auto; margin-bottom: 0; }
.dl-pagesize .shiny-input-container > label { display: none; }
.dl-pagesize select.form-control { width: auto; min-width: 84px; }

/* Preview table wrapper (the .spg-card class on it themes the data grid). */
.dl-table-wrap { width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.dl-table-wrap th, .dl-table-wrap td { white-space: nowrap; }

/* Download button groups. */
.dl-dl-group { margin-top: 18px; }
.dl-dl-group .lf-label { display: block; margin-bottom: 8px; }
.dl-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ====================== Explorador de Visualizaciones (SPG explorer) ====
   Chart host inside the viz-card (the Vega/Altair widget). Card + fullscreen
   reuse .lf-card / .btn-fullscreen / .viz-card:fullscreen (already tokenized). */
#spg_chart_host { min-height: 460px; width: 100%; }
#spg_chart_host .vega-embed, #spg_chart_host .html-widget { width: 100% !important; }

/* ====================== Descargar Conjunto de Datos (SPG download) ======
   Card reuses .lf-card; only the selection summary callout + date-range error
   are page-specific (tokenized). */
.dl2-summary {
  background: var(--card-2); border: 1px solid var(--line);
  border-left: 3px solid var(--leaf); border-radius: var(--r-xs);
  padding: 14px 16px; margin: 4px 0 14px;
}
.dl2-summary p { margin: 0 0 6px; color: var(--ink-2); font-size: 13.5px; }
.dl2-summary p:last-child { margin-bottom: 0; }
.dl2-summary strong { color: var(--ink); }
.dl2-error {
  background: var(--bad-bg); color: var(--bad-tx);
  border: 1px solid var(--clay-soft); border-left: 3px solid var(--bad);
  border-radius: var(--r-xs); padding: 10px 12px; margin: 4px 0 12px;
  font-size: 13px; font-weight: 500;
}

/* ====================== Registro de Actividades (activity tracker) ======
   Server-rendered main content (cards/buttons/alerts reuse .fa-page theming).
   Only these page-specific blocks are tokenized here. */
.activity-metrics {
  background: linear-gradient(135deg, var(--canopy), var(--pine));
  color: var(--card); border-radius: var(--r); padding: 20px; margin-bottom: 24px;
}
.activity-metrics h4 { color: var(--rail-head); }
.activity-metrics p { opacity: .92; margin: 0; }
.activity-metrics-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); color: var(--rail-head); }
.activity-metrics-head .lf-ic { flex-shrink: 0; }

.section-divider { border-top: 1px solid var(--line); margin: 30px 0; padding-top: 20px; }

/* Key Insights — KPI grid built on the shared .lf-metric component. Each card
   sets its own --accent inline (a token), driving the corner wash + chip/badge. */
.at-insights { margin-bottom: var(--sp-11); }   /* 30px gap before the summary table */
.at-insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(264px, 1fr));
  gap: var(--sp-8);
}
.at-insight { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px; }
.at-insight::after { display: none; }   /* drop the .lf-metric decorative corner circle */
.at-insight-head { display: flex; align-items: center; gap: var(--sp-4); }
.at-insight-ic {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--r-xs);
  background: var(--card-2); color: var(--accent, var(--leaf)); flex-shrink: 0;
}
.at-insight-value {
  font-family: var(--serif); font-size: 21px; font-weight: 500;
  line-height: 1.2; letter-spacing: -.01em; color: var(--ink);
}
.at-insight-badge {
  align-self: flex-start;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px;
  background: var(--card-2); color: var(--accent, var(--leaf)); border: 1px solid var(--line);
}

/* Detailed-report launcher buttons — consistent ghost buttons in a 2-up grid. */
.at-report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); margin-bottom: var(--sp-6); }
.at-report-grid .at-report-btn { width: 100%; justify-content: center; }
/* Stronger hover than the default ghost wash, which blends into the paper. */
.at-report-grid .at-report-btn:hover { background: var(--good-bg); border-color: var(--leaf); color: var(--canopy); }

.data-table-container {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 22px 24px; box-shadow: var(--sh-1); margin-bottom: 18px;
}
.data-table-container .shiny-data-frame { border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.data-table-container .shiny-data-frame table th {
  background: var(--card-2) !important; font-family: var(--mono); font-weight: 600;
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3) !important;
  border-bottom: 1.5px solid var(--line) !important; padding: 11px 14px !important; text-align: left;
}
.data-table-container .shiny-data-frame table td {
  padding: 10px 14px !important; border-bottom: 1px solid var(--line-soft) !important;
  color: var(--ink); vertical-align: middle;
}
.data-table-container .shiny-data-frame table tbody tr:hover { background: var(--good-bg) !important; }
.data-table-container .shiny-data-frame table tbody tr:nth-child(even) { background: var(--card-2); }

/* Status pills + metric highlight */
.status-badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
}
.status-active   { background: var(--good-bg); color: var(--good-tx); }
.status-inactive { background: var(--bad-bg);  color: var(--bad-tx); }
.status-moderate { background: var(--warn-bg); color: var(--warn-tx); }
.metric-highlight {
  background: var(--good-bg); color: var(--canopy); padding: 15px;
  border-radius: var(--r-xs); text-align: center; margin: 10px 0;
}
.fa-page .alert-info { background: var(--card-2); color: var(--ink-2); border-left: 4px solid var(--sky); }
