/* AgroRefiner Atlas - the Lux house style on a near-black data surface.
 *
 * The light house palette is ink 1A1A1A on sand F0EEE9 with an E0DDD8 hairline.
 * A control panel is read for hours in low light, so the surface inverts to a
 * near-black neutral and the sand becomes the ink. One saturated accent, amber,
 * is reserved for the plant itself, the live selection and the lead figure, and
 * covers well under five percent of the screen.
 *
 * Georgia carries the display titles, as every Lux document does. Numbers run
 * in a sans family with tabular lining figures so columns align and a true
 * minus sign is used for negatives.
 */

:root {
  --canvas: #14161a;
  --panel: #1a1d22;
  --raised: #22262d;
  --hairline: #2e333b;
  --hairline-soft: #24282f;
  --ink: #f0eee9;
  --muted: #8a8f9a;
  --slate: #4a5568;
  --accent: #e8a33d;
  --accent-dim: #8c6426;

  /* Product classes. Lightness varies across the set, so the series survive
   * grayscale and color-vision deficiency, and each legend row carries a glyph
   * as well as a color. */
  --p-isolate: #e6e1d7;
  --p-distillate: #7fb3d5;
  --p-crude: #c98a4b;
  --p-cbg: #a98bc4;
  --p-ml: #6e8b74;
  --p-biomass: #8a7b5c;
  --p-services: #8a8f9a;

  /* Counterparty roles. */
  --r-internal: #e8a33d;
  --r-customer: #7fb3d5;
  --r-supplier: #c98a4b;
  --r-toll: #a98bc4;
  --r-prospect: #7c828d;
  --r-lab: #6e8b74;
  --r-partner: #e6e1d7;
  --r-logistics: #5f7a8a;

  --sans: "Inter", "Calibri", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: "SF Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 48px;
  --rail: 322px;
  --drawer: 430px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.num, td.num, .kpi-value, .bar-value {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

h1, h2, h3, .display { font-family: var(--serif); font-weight: 400; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--raised); color: var(--ink); padding: var(--s1) var(--s2);
}
.skip:focus { left: var(--s2); top: var(--s2); }

/* ----------------------------------------------------------------- layout */
#app { display: grid; grid-template-columns: var(--rail) 1fr; height: 100vh; }

#rail {
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
}

#stage { position: relative; overflow: hidden; }
#globe { position: absolute; inset: 0; }

/* ---------------------------------------------------------------- masthead */
.masthead {
  padding: var(--s3) var(--s2) var(--s2);
  border-bottom: 1px solid var(--hairline);
}
.eyebrow {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 6px;
}
.masthead h1 { font-size: 21px; margin: 0 0 2px; letter-spacing: 0.01em; }
.masthead .sub {
  font-family: var(--serif); font-style: italic;
  font-size: 13px; color: var(--muted); margin: 0;
}
.masthead .meta {
  margin-top: var(--s2); padding-top: 10px;
  border-top: 1px solid var(--hairline-soft);
  font-size: 11px; color: var(--muted);
  display: flex; justify-content: space-between; gap: var(--s1);
}

/* ---------------------------------------------------------------- sections */
.sect { border-bottom: 1px solid var(--hairline-soft); }
.sect > summary {
  padding: 13px var(--s2); cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted); user-select: none;
}
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary:hover { color: var(--ink); background: var(--raised); }
.sect > summary .chev { transition: transform 180ms ease-out; font-size: 9px; }
.sect[open] > summary .chev { transform: rotate(90deg); }
.sect-body { padding: 0 var(--s2) var(--s2); }

/* ----------------------------------------------------------------- toggles */
.toggle {
  display: grid; grid-template-columns: 32px 1fr auto;
  align-items: center; gap: 10px;
  padding: 5px 0; cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.track {
  width: 30px; height: 17px; border-radius: 9px;
  background: var(--hairline); border: 1px solid var(--hairline);
  position: relative; transition: background 160ms ease-out;
  flex: none;
}
.knob {
  position: absolute; top: 2px; left: 2px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease-out, background 160ms ease-out;
}
.toggle input:checked + .track { background: var(--accent-dim); border-color: var(--accent); }
.toggle input:checked + .track .knob { transform: translateX(13px); background: var(--accent); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle .label { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.toggle .count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toggle .glyph { width: 11px; height: 11px; flex: none; }

.row-actions { display: flex; gap: var(--s1); margin: 6px 0 10px; }
.mini {
  background: none; border: 1px solid var(--hairline); color: var(--muted);
  font-family: var(--sans); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 4px 9px; border-radius: 2px; cursor: pointer;
  transition: color 150ms ease-out, border-color 150ms ease-out;
}
.mini:hover { color: var(--ink); border-color: var(--slate); }

/* ------------------------------------------------------------------ fields */
.field { margin-bottom: var(--s2); }
.field > label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--muted); margin-bottom: 6px;
}
.field .val { color: var(--ink); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 3px;
  background: var(--hairline); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--canvas);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 2px solid var(--canvas);
}

select, input[type="search"], input[type="password"] {
  width: 100%; background: var(--raised); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 2px;
  padding: 7px 9px; font-family: var(--sans); font-size: 13px;
}
select:hover { border-color: var(--slate); }

/* --------------------------------------------------------------- kpi strip */
#kpis {
  position: absolute; top: var(--s2); left: var(--s2); right: var(--s2);
  display: flex; gap: 1px; pointer-events: none; z-index: 5;
  background: var(--hairline); border: 1px solid var(--hairline);
  border-radius: 3px; overflow: hidden;
}
.kpi {
  flex: 1; background: rgba(20, 22, 26, 0.93); padding: 11px var(--s2);
  backdrop-filter: blur(7px);
}
.kpi-label {
  font-size: 9.5px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 3px;
}
.kpi-value { font-size: 19px; line-height: 1.1; }
.kpi-value.lead { color: var(--accent); }
.kpi-note { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

/* ------------------------------------------------------------------ legend */
#legend {
  position: absolute; bottom: var(--s2); left: var(--s2); z-index: 5;
  background: rgba(20, 22, 26, 0.93); backdrop-filter: blur(7px);
  border: 1px solid var(--hairline); border-radius: 3px;
  padding: 13px var(--s2); max-width: 290px;
}
#legend h2 {
  font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 9px; font-family: var(--sans);
}
.legend-group + .legend-group {
  margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--hairline-soft);
}
.legend-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 2px 0; color: var(--ink);
}
.legend-row .sw { width: 13px; height: 13px; flex: none; }
.legend-row .n { color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.legend-note { font-size: 10.5px; color: var(--muted); margin: 9px 0 0; line-height: 1.45; }

/* ------------------------------------------------------------------ drawer */
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--drawer);
  background: var(--panel); border-left: 1px solid var(--hairline);
  transform: translateX(100%); transition: transform 220ms ease-out;
  overflow-y: auto; z-index: 10;
}
#drawer.open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  #drawer { transition: none; }
  .sect > summary .chev { transition: none; }
}
.drawer-head {
  padding: var(--s3) var(--s3) var(--s2);
  border-bottom: 1px solid var(--hairline); position: sticky; top: 0;
  background: var(--panel); z-index: 2;
}
.drawer-head .close {
  position: absolute; top: var(--s2); right: var(--s2);
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 19px; line-height: 1; padding: 4px 7px;
}
.drawer-head .close:hover { color: var(--ink); }
.drawer-head h2 { font-size: 20px; margin: 0 var(--s4) 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.chip {
  font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase;
  border: 1px solid var(--hairline); border-radius: 2px;
  padding: 2px 7px; color: var(--muted);
}
.chip.on { color: var(--canvas); background: var(--accent); border-color: var(--accent); }
.drawer-body { padding: var(--s2) var(--s3) var(--s5); }
.drawer-body h3 {
  font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted); font-family: var(--sans);
  margin: var(--s3) 0 10px; padding-bottom: 7px;
  border-bottom: 1px solid var(--hairline-soft);
}
.drawer-body h3:first-child { margin-top: 0; }
.drawer-body p { margin: 0 0 11px; font-size: 13px; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--hairline-soft); }
.fact { background: var(--panel); padding: 9px 11px; }
.fact .k { font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.fact .v { font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.fact .v.lead { color: var(--accent); }

table.lines { width: 100%; border-collapse: collapse; font-size: 12px; }
table.lines th {
  text-align: left; font-weight: 400; font-size: 9.5px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--hairline); padding: 5px 7px 5px 0;
}
table.lines th.num, table.lines td.num { text-align: right; padding-right: 0; }
table.lines td {
  padding: 5px 7px 5px 0; border-bottom: 1px solid var(--hairline-soft);
  vertical-align: top;
}
table.lines tr:last-child td { border-bottom: none; }
.src { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------------- bars */
.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 78px 1fr 84px; gap: 9px; align-items: center; font-size: 12px; }
.bar-row .bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 13px; background: var(--hairline-soft); position: relative; }
.bar-fill { height: 100%; background: var(--slate); }
.bar-fill.lead { background: var(--accent); }
.bar-value { text-align: right; }

/* ------------------------------------------------------------------ misc */
.unplaced-row {
  display: flex; justify-content: space-between; gap: var(--s1);
  font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--hairline-soft);
  cursor: pointer;
}
.unplaced-row:hover { color: var(--accent); }
.unplaced-row .where { color: var(--muted); font-size: 11px; }

#results { margin-top: 9px; max-height: 232px; overflow-y: auto; }
.result {
  padding: 6px 8px; cursor: pointer; font-size: 13px;
  border-left: 2px solid transparent;
}
.result:hover, .result.sel { background: var(--raised); border-left-color: var(--accent); }
.result .where { font-size: 11px; color: var(--muted); }

.basis {
  font-size: 11px; color: var(--muted); line-height: 1.45;
  border-left: 2px solid var(--hairline); padding-left: 10px; margin: 11px 0;
}

#tip {
  position: absolute; pointer-events: none; z-index: 20;
  background: rgba(26, 29, 34, 0.97); border: 1px solid var(--hairline);
  border-radius: 3px; padding: 8px 11px; font-size: 12px;
  max-width: 254px; opacity: 0; transition: opacity 120ms ease-out;
}
#tip.show { opacity: 1; }
#tip .t { font-family: var(--serif); font-size: 14px; }
#tip .d { color: var(--muted); font-size: 11px; margin-top: 3px; font-variant-numeric: tabular-nums; }

#loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--canvas); z-index: 30; transition: opacity 300ms ease-out;
}
#loading.gone { opacity: 0; pointer-events: none; }
#loading .inner { text-align: center; }
#loading .inner .t { font-family: var(--serif); font-size: 17px; }
#loading .inner .d { color: var(--muted); font-size: 12px; margin-top: 7px; }

.foot {
  margin-top: auto; padding: var(--s2);
  border-top: 1px solid var(--hairline); font-size: 10.5px; color: var(--muted);
}
.foot form { display: inline; }
.foot button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-family: var(--sans); font-size: 10.5px; padding: 0; text-decoration: underline;
}
.foot button:hover { color: var(--ink); }

/* ------------------------------------------------------------------ login */
body.login { display: grid; place-items: center; overflow: auto; }
.login-card {
  width: 358px; background: var(--panel); border: 1px solid var(--hairline);
  border-radius: 3px; padding: var(--s4);
}
.login-card .eyebrow { margin-bottom: 7px; }
.login-card h1 { font-size: 23px; margin: 0 0 4px; }
.login-card .sub { font-family: var(--serif); font-style: italic; color: var(--muted); margin: 0 0 var(--s3); font-size: 13px; }
.login-card label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.login-card button {
  width: 100%; margin-top: var(--s2); padding: 10px;
  background: var(--accent); color: #1a1208; border: none; border-radius: 2px;
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  letter-spacing: 0.05em; cursor: pointer;
}
.login-card button:hover { background: #f0b154; }
.login-card .err { color: #e0885f; font-size: 12px; margin-top: var(--s2); }
.login-card .foot-note {
  margin-top: var(--s3); padding-top: var(--s2);
  border-top: 1px solid var(--hairline-soft); font-size: 10.5px; color: var(--muted);
}

@media (max-width: 1100px) {
  :root { --rail: 286px; --drawer: 360px; }
  #kpis { flex-wrap: wrap; }
}

/* Spacing utility used where a block needs separating from the one above it.
 * The content security policy forbids an inline style attribute, so spacing of
 * this kind lives here. */
.spaced { margin-top: 14px; }

/* ------------------------------------------------------------------ phone
 * On a narrow screen the globe takes the whole surface and the rail becomes a
 * sheet that slides over it. Tap targets grow to 44px, the KPI strip scrolls
 * sideways by the thumb, and the detail panel takes the full width.
 */
#rail-open, #legend-toggle, #rail-close, #scrim { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }

  #rail {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(88vw, 340px); z-index: 40;
    transform: translateX(-100%);
    transition: transform 220ms ease-out;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
  }
  #rail.open { transform: translateX(0); }

  #scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(13, 15, 18, 0.62);
    opacity: 0; pointer-events: none; transition: opacity 220ms ease-out;
  }
  #scrim.on { opacity: 1; pointer-events: auto; }

  #rail-close {
    display: block; position: absolute; top: 12px; right: 12px;
    background: none; border: none; color: var(--muted);
    font-size: 23px; line-height: 1; padding: 8px 10px; cursor: pointer;
  }

  #rail-open, #legend-toggle {
    display: flex; align-items: center; gap: 7px;
    position: absolute; bottom: 16px; z-index: 25;
    background: rgba(26, 29, 34, 0.95); backdrop-filter: blur(7px);
    border: 1px solid var(--hairline); border-radius: 3px;
    color: var(--ink); font-family: var(--sans); font-size: 12px;
    letter-spacing: 0.08em; text-transform: uppercase;
    padding: 0 14px; min-height: 44px; cursor: pointer;
  }
  #rail-open { left: 16px; }
  #legend-toggle { left: 148px; }

  /* The detail panel takes the whole screen on a phone, so the floating
   * buttons step aside while it is open. */
  #stage.detail #rail-open,
  #stage.detail #legend-toggle { display: none; }

  /* The KPI strip scrolls sideways rather than squeezing five figures into a
   * phone's width, and each tile snaps so a thumb lands on a whole number. */
  #kpis {
    left: 8px; right: 8px; top: 8px;
    /* The wider breakpoint lets the tiles wrap. On a phone they stay on one
     * line and the strip scrolls sideways instead, so the globe keeps the
     * screen. */
    flex-wrap: nowrap;
    overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; pointer-events: auto;
  }
  #kpis::-webkit-scrollbar { display: none; }
  .kpi {
    flex: 0 0 62%; scroll-snap-align: start; padding: 9px 13px;
  }
  .kpi-value { font-size: 17px; }

  #legend {
    bottom: 72px; left: 16px; right: 16px; max-width: none;
    max-height: 44vh; overflow-y: auto;
    display: none;
  }
  #legend.on { display: block; }

  #drawer { width: 100%; }
  .drawer-body { padding: var(--s2) var(--s2) var(--s5); }
  .drawer-head { padding: var(--s3) var(--s2) var(--s2); }

  /* A thumb needs a bigger target than a mouse pointer. */
  .toggle { padding: 10px 0; min-height: 44px; }
  .drawer-head .close { font-size: 26px; padding: 10px 13px; min-height: 44px; }
  .mini { min-height: 38px; padding: 8px 12px; }
  .sect > summary { padding: 15px var(--s2); min-height: 48px; }
  .unplaced-row, .result { padding-top: 9px; padding-bottom: 9px; }
  input[type="range"] { height: 22px; }
}

@media (max-width: 420px) {
  .facts { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 66px 1fr 74px; }
  #legend-toggle { left: 142px; }
}
