/* Agrivoltaic Living Lab Monitor
   Calm and legible: white ground, one accent per treatment (the same colours as the
   site plans), generous whitespace, no gradients, no drop shadows.
   Committed light design -- this is shown on an office projector. */

:root {
  --ink:        #12160f;
  --ink2:       #565c4c;
  --ink3:       #868b78;
  --rule:       #e4e6df;
  --rule2:      #f0f1ec;
  --surface:    #fcfcfb;
  --panel:      #ffffff;

  /* Treatments -- identical to 04_Models/build_master_plans.py */
  --under:      #1baf7a;
  --beside:     #eb6834;
  --open:       #2a78d6;

  /* Status -- reserved, never reused as a series colour */
  --ok:         #1a7f4b;
  --warn:       #b45309;
  --serious:    #b3261e;

  /* Sequential ramp for the map: one hue, light to dark. */
  --seq0: #eef0f7; --seq1: #c9cfe6; --seq2: #9aa5d0;
  --seq3: #6472b0; --seq4: #3a4788; --seq5: #232d5c;

  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--surface); color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---- header ------------------------------------------------------------ */
header {
  border-bottom: 1px solid var(--rule); background: var(--panel);
  padding: 11px 22px 0;
}
.hrow { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
h1 { font-size: 17px; letter-spacing: -0.01em; }
.badge {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.09em; padding: 3px 8px; border-radius: 3px;
  background: #fff4e5; color: var(--warn); border: 1px solid #f0d3a8;
}
.clock { font-family: var(--mono); font-size: 12.5px; color: var(--ink2); margin-left: auto; }
.subnote { font-size: 12px; color: var(--ink3); margin: 3px 0 0; max-width: 76ch; }

.verdict {
  display: flex; align-items: center; gap: 10px;
  margin: 10px -22px 0; padding: 9px 22px;
  border-top: 1px solid var(--rule2); font-weight: 600; font-size: 14.5px;
}
.verdict .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.verdict.ok      { background: #f2f9f4; color: var(--ok); }
.verdict.warn    { background: #fdf6ec; color: var(--warn); }
.verdict.fault   { background: #fdf1f0; color: var(--serious); }
.verdict.ok .dot     { background: var(--ok); }
.verdict.warn .dot   { background: var(--warn); }
.verdict.fault .dot  { background: var(--serious); }
.verdict .more { font-weight: 400; font-size: 12.5px; color: var(--ink2); margin-left: 6px; }

/* ---- layout ------------------------------------------------------------ */
/* minmax(0, 1fr), not the implicit auto column: an auto track grows to its widest
   content (the 640 px data table), which dragged every panel past a phone's edge. */
main { padding: 18px 22px 44px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
/* Two columns that end level. Each column stacks its panels and the last one takes
   up any difference in height, so neither column leaves a gap beneath it. Everything
   below the top pair runs full width, so no other row can end unevenly. */
.grid-top { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 16px; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col > .grow { flex: 1 1 auto; }
@media (max-width: 1080px) {
  .grid-top { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--panel); border: 1px solid var(--rule); border-radius: 6px;
  padding: 14px 16px 16px;
}
.panel h2 {
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink3); font-weight: 600; margin-bottom: 12px;
}
/* Units and model names inside an uppercase title keep their real case. */
.panel h2 .nt, .legend h3 .nt { text-transform: none; letter-spacing: 0.02em; }
.panel .hint { font-size: 11.5px; color: var(--ink3); margin-top: 9px; line-height: 1.4; }

/* ---- metric selector --------------------------------------------------- */
.metrics { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.metrics button {
  font: inherit; font-size: 12px; font-weight: 500; line-height: 18px;
  padding: 4px 10px; border: 1px solid var(--rule); border-radius: 4px;
  background: var(--panel); color: var(--ink2); cursor: pointer;
}
.metrics button:hover { border-color: var(--ink3); color: var(--ink); }
.metrics button[aria-pressed="true"] {
  background: var(--ink); color: #fff; border-color: var(--ink);
}

/* ---- map --------------------------------------------------------------- */
.maprow { display: flex; gap: 16px; align-items: flex-start; }
#map { flex: 1 1 auto; min-width: 0; }
#map text { font-family: var(--mono); }
.plotcell { cursor: pointer; }
.plotcell:hover .cellbg { stroke: var(--ink); stroke-width: 1.8; }
.legend { flex: none; width: 132px; }
.legend h3 { font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
             color: var(--ink3); margin-bottom: 6px; }
.legend .swatches { display: flex; height: 11px; border-radius: 2px; overflow: hidden;
                    border: 1px solid var(--rule); }
.legend .swatches i { flex: 1; }
.legend .ends { display: flex; justify-content: space-between;
                font-family: var(--mono); font-size: 10.5px; color: var(--ink2); margin-top: 4px; }
.legend .key { margin-top: 12px; font-size: 11.5px; color: var(--ink2); line-height: 1.6; }
.legend .key div { display: flex; align-items: center; gap: 7px; }
.legend .key svg { flex: none; }

/* ---- selected plot ----------------------------------------------------- */
.selhead { display: flex; align-items: baseline; gap: 9px; margin-bottom: 2px; }
.selhead .name { font-size: 16px; font-weight: 600; }
/* One pill for every status label on the page -- measured / inferred, irrigation
   action, crop adequacy, expected range, kit health. Same size, shape and palette,
   so a green pill means the same thing wherever it appears. */
.tag, .act, .ctag, .stpill {
  display: inline-block; font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: 0.05em; line-height: 16px; padding: 0 7px; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--rule2); color: var(--ink2);
  white-space: nowrap; vertical-align: 1px;
}
.tag, .act, .stpill, .crow .ctag { text-transform: uppercase; }
.tag.measured, .act.hold, .ctag.ok, .stpill.ok {
  background: #eef7f1; border-color: #cbe6d5; color: var(--ok); }
.act.irrigate, .ctag.warn, .stpill.warn {
  background: #fdf6ec; border-color: #f0d3a8; color: var(--warn); }
.ctag.bad { background: #fdf1f0; border-color: #eccac7; color: var(--serious); }
.tag.inferred { background: #f4f5fa; border-color: #d7dbeb; color: #3a4788; }
.selstats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; margin-top: 12px; }
.stat .k { font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink3); }
.stat .v { font-family: var(--mono); font-size: 20px; font-weight: 500; line-height: 1.2; }
.stat .u { font-size: 11.5px; color: var(--ink3); font-family: var(--sans); }
.stat .ci { font-family: var(--mono); font-size: 11px; color: var(--ink3); }

/* ---- treatment contrast ------------------------------------------------ */
.contrast { display: grid; gap: 9px; }
.crow { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; }
.crow .lbl { font-size: 12.5px; color: var(--ink2); }
.crow .bar { height: 12px; background: var(--rule2); border-radius: 3px; overflow: hidden; }
.crow .bar i { display: block; height: 100%; border-radius: 3px; }
.crow .val { font-family: var(--mono); font-size: 12.5px; min-width: 62px; text-align: right; }

/* ---- charts ------------------------------------------------------------ */
.chartwrap { position: relative; }
svg.chart { display: block; width: 100%; height: auto; }
svg.chart text { font-family: var(--mono); font-size: 10.5px; fill: var(--ink3); }
svg.chart .axlabel { fill: var(--ink2); }
.grid line { stroke: var(--rule2); stroke-width: 1; }
.axis line, .axis path { stroke: var(--rule); stroke-width: 1; }
.tooltip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .09s;
  background: var(--ink); color: #fff; border-radius: 4px; padding: 7px 9px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5; white-space: nowrap; z-index: 6;
}
.tooltip b { font-weight: 600; }
.chartlegend { display: flex; gap: 15px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); margin-bottom: 8px; }
.chartlegend span { display: inline-flex; align-items: center; gap: 6px; }
.chartlegend i { width: 13px; height: 3px; border-radius: 2px; }
.chartlegend .fc { width: 13px; height: 9px; border-radius: 2px; opacity: .3; background: var(--ink3); }

/* ---- irrigation -------------------------------------------------------- */
.zones { display: grid; gap: 7px; }
.zone { display: grid; grid-template-columns: 34px 1fr auto; gap: 9px; align-items: center;
        font-size: 12.5px; padding-bottom: 7px; border-bottom: 1px solid var(--rule2); }
.zone:last-child { border-bottom: 0; }
.zone .zid { font-family: var(--mono); color: var(--ink3); font-size: 11.5px; }
.zone .why { font-size: 11.5px; color: var(--ink3); }
.irrgrid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 0 20px;
           align-items: start; }
.events { padding-left: 20px; border-left: 1px solid var(--rule);
          font-family: var(--mono); font-size: 11.5px; color: var(--ink2); }
.events .evhead { color: var(--ink3); padding-bottom: 3px; }
@media (max-width: 900px) {
  .irrgrid { grid-template-columns: minmax(0, 1fr); }
  .events { padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--rule); margin-top: 10px; }
}
.events div { display: flex; justify-content: space-between; padding: 2px 0; }

/* ---- network ----------------------------------------------------------- */
.buses { display: flex; flex-wrap: wrap; gap: 10px 32px; }
.bus { display: grid; grid-template-columns: 30px auto; gap: 8px; align-items: center; }
.bus .bid { font-family: var(--mono); font-size: 11px; color: var(--ink3); }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono); font-size: 10.5px; padding: 3px 6px; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink2);
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.chip .st { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.chip.off { background: #fdf1f0; color: var(--serious); border-color: #eccac7; }
.chip.off .st { background: var(--serious); }
.chip.degraded { background: #fdf6ec; color: var(--warn); border-color: #f0d3a8; }
.chip.degraded .st { background: var(--warn); }
.netfoot { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
           margin-top: 12px; border-top: 1px solid var(--rule); padding-top: 10px;
           font-size: 11.5px; color: var(--ink3); }
.netfoot #netsummary { color: var(--ink2); }
.netfoot button {
  font: inherit; font-size: 12px; font-weight: 500; line-height: 18px; padding: 4px 10px;
  border: 1px solid var(--rule); border-radius: 4px; background: var(--panel);
  color: var(--ink2); cursor: pointer;
}
.netfoot button:hover { border-color: var(--ink3); color: var(--ink); }

/* ---- h7 + diagnostics -------------------------------------------------- */
table.diag { width: 100%; border-collapse: collapse; font-size: 12px; }
table.diag th { text-align: left; font-weight: 500; color: var(--ink3); font-size: 10px;
                letter-spacing: 0.07em; text-transform: uppercase;
                padding-bottom: 5px; border-bottom: 1px solid var(--rule); }
table.diag td { padding: 5px 0; border-bottom: 1px solid var(--rule2); font-family: var(--mono); }
table.diag td:first-child { font-family: var(--sans); }
table.diag td.num, table.diag th.num { text-align: right; padding-right: 20px; }
table.diag td:last-child, table.diag th:last-child { padding-left: 8px; }
.err { color: var(--serious); font-size: 12.5px; }

/* ============================================================ added sections
   Stations, fixed mast, solar array, data table, treatment contrast.
   Same rules as above: white ground, treatment colour as the only accent,
   no gradients, no shadows. */

/* Section bar: heading on the left, controls on the right. */
.secbar { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
          margin-bottom: 12px; }
.secbar > h2 { margin: 0; }
.secbar > .hint { margin: 0 0 0 auto; }
.secbar > .seg, .secbar > .tablebar { margin-left: auto; }

/* Segmented control, shared by the history window and the table view. */
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 4px;
       overflow: hidden; }
.seg button { appearance: none; border: 0; background: var(--panel); cursor: pointer;
              font-family: var(--sans); font-size: 12px; font-weight: 500; line-height: 18px;
              color: var(--ink2); padding: 4px 10px; border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--rule2); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:focus-visible { outline: 2px solid var(--open); outline-offset: -2px; }

/* ---------------------------------------------------------------- stations */
.stations { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .stations { grid-template-columns: minmax(0, 1fr); } }

.station { border: 1px solid var(--rule); border-radius: 6px; padding: 0;
           border-top: 3px solid var(--tc); overflow: hidden; }
.station.degraded { border-color: var(--warn); }
.sthead { display: flex; align-items: flex-start; gap: 10px;
          padding: 10px 13px; border-bottom: 1px solid var(--rule2); }
.stname { font-weight: 600; font-size: 13.5px; color: var(--tc); }
.stsub  { font-family: var(--mono); font-size: 10.5px; color: var(--ink3); margin-top: 2px; }
.stpill { margin-left: auto; }

.stgrid { display: grid; grid-template-columns: 1fr 1fr; }
.stcell { padding: 8px 13px; border-bottom: 1px solid var(--rule2); }
.stcell:nth-child(odd) { border-right: 1px solid var(--rule2); }
.stcell .k { font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
             color: var(--ink3); }
.stcell .v { font-family: var(--mono); font-size: 16px; margin-top: 1px;
             font-variant-numeric: tabular-nums; }
.stcell .v small { font-size: 10px; color: var(--ink3); margin-left: 3px;
                   font-family: var(--sans); }
.stcell.missing .v { color: var(--ink3); }
.stfoot { padding: 7px 13px; font-family: var(--mono); font-size: 10.5px;
          color: var(--ink3); background: var(--rule2); }


/* ------------------------------------------------------------- solar array */
.badge.modelled { background: #fbf0e2; color: var(--warn); border-color: #e8d3ac;
                  margin-left: auto; }
.pvgrid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px;
          align-items: start; }
@media (max-width: 860px) { .pvgrid { grid-template-columns: minmax(0, 1fr); } }
.pvstats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
           background: var(--rule); border: 1px solid var(--rule); border-radius: 6px;
           overflow: hidden; }
.pvstat { background: var(--panel); padding: 8px 11px; }
.pvstat .k { font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
             color: var(--ink3); }
.pvstat .v { font-family: var(--mono); font-size: 16px; margin-top: 1px;
             font-variant-numeric: tabular-nums; }
.pvstat .v small { font-size: 10px; color: var(--ink3); margin-left: 3px;
                   font-family: var(--sans); }
.pvchartwrap { border: 1px solid var(--rule); border-radius: 6px; padding: 6px 4px 0; }

/* -------------------------------------------------------------- data table */
.tablebar { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.dl { font-family: var(--sans); font-size: 12px; font-weight: 500; line-height: 18px;
      text-decoration: none; color: var(--ink); border: 1px solid var(--rule);
      border-radius: 4px; padding: 4px 10px; background: var(--panel); white-space: nowrap; }
.dl:hover { background: var(--ink); color: #fff; border-color: var(--ink); }
.dl:focus-visible { outline: 2px solid var(--open); outline-offset: 1px; }

.tablescroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px;
               max-height: 420px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 640px; }
table.data th { position: sticky; top: 0; background: var(--rule2); text-align: left;
                font-weight: 500; color: var(--ink3); font-size: 10px; letter-spacing: .07em;
                text-transform: uppercase; padding: 8px 11px; white-space: nowrap;
                border-bottom: 1px solid var(--rule); }
table.data td { padding: 6px 11px; border-bottom: 1px solid var(--rule2);
                font-family: var(--mono); white-space: nowrap;
                font-variant-numeric: tabular-nums; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:hover td { background: var(--rule2); }
table.data td.measured { color: var(--ok); }
table.data td.inferred { color: var(--ink3); }

/* ---- real clock + data freshness --------------------------------------- */
.clockbox { margin-left: auto; text-align: right; line-height: 1.25; }
.clock { font-family: var(--mono); font-size: 13.5px; color: var(--ink);
         font-variant-numeric: tabular-nums; display: block; }
.datastamp { font-family: var(--mono); font-size: 10.5px; color: var(--ink3); }
.datastamp.lagging { color: var(--warn); font-weight: 600; }

/* ---- sticky header + control bar ---------------------------------------
   The whole top block sticks: the SIMULATED badge must never scroll out of view,
   the verdict has to stay readable while a fault is injected from the network
   panel at the foot of the page, and the controls drive panels far below. */
header { position: sticky; top: 0; z-index: 30; background: var(--surface); }
.controlbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 -22px; padding: 6px 22px;
  border-top: 1px solid var(--rule2); border-bottom: 1px solid var(--rule);
}
.controlbar > .seg { margin-left: auto; }
/* On a short window app.js (pinHeader) sets a negative `top`, so the title row
   scrolls away and the verdict and controls stay pinned. */

/* ---- grouped metric selector ------------------------------------------- */
.metrics { align-items: center; gap: 4px 10px; margin-bottom: 0; }
.mfam { display: inline-flex; align-items: center; gap: 4px;
        padding-right: 10px; margin-right: 2px; border-right: 1px solid var(--rule); }
.mfam:last-child { border-right: 0; padding-right: 0; }
.mfamlab { font-family: var(--mono); font-size: 10px; letter-spacing: .07em;
           text-transform: uppercase; color: var(--ink3); margin-right: 2px; }

/* ---- soil chemistry row: pH + N, P, K, four across ---------------------- */
.stgrid.chem { grid-template-columns: repeat(4, 1fr); }
.stgrid.chem .stcell:nth-child(odd) { border-right: 0; }
.stgrid.chem .stcell:not(:last-child) { border-right: 1px solid var(--rule2); }

/* ---- does the interval resolve the effect under test? ------------------- */
.stat .ci.ok   { color: var(--ok); }
.stat .ci.weak { color: var(--warn); }

/* Fixed mast: the two sensors that belong to no station, one slim line under the cards. */
.maststrip { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px;
             margin-top: 12px; padding: 9px 13px; border: 1px solid var(--rule);
             border-radius: 6px; background: var(--rule2); font-size: 12px; color: var(--ink2); }
.maststrip .mlab { font-family: var(--mono); font-size: 10px; letter-spacing: .07em;
                   text-transform: uppercase; color: var(--ink3); }
.maststrip .mitem b { font-family: var(--mono); font-weight: 500; color: var(--ink);
                      font-variant-numeric: tabular-nums; }
.maststrip .mdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
                   margin-right: 6px; vertical-align: 1px; }
.maststrip .mdot.ok  { background: var(--ok); }
.maststrip .mdot.bad { background: var(--serious); }

/* An odd number of array figures: the last one takes the full row rather than
   leaving half a row empty. */
.pvstats .pvstat:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* Treatment contrast: the crop-need band behind the DLI bars, and the line under
   each metric that states the difference its hypothesis is tested on. */
.crow .bar { position: relative; }
.crow .bar .need { position: absolute; top: 0; bottom: 0; background: #d6ebdd; }
.crow .bar i { position: relative; }
.crow .ctag { margin-left: 6px; }
.clines { display: grid; gap: 10px; margin-top: 12px; }
.cline { border-top: 1px solid var(--rule2); padding-top: 9px; }
.chead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chead .cl { font-size: 12px; font-weight: 600; color: var(--ink2); }
.chead .cv { font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums; }
.chead .cv small { font-size: 10.5px; color: var(--ink3); margin-left: 3px; font-family: var(--sans); }
.chead .ch { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink3); }
.cline .ctag { margin-left: 0; }
.cline .cn { margin: 5px 0 0; font-size: 11.5px; color: var(--ink3); line-height: 1.4; }
.simnote { margin: 0 0 10px; }
.h7line { margin-top: 10px; }   /* same line style as the contrasts above it */

/* Wide tables scroll inside their own box, never the page. */
.hscroll { overflow-x: auto; }
table.diag { min-width: 560px; }

/* ---- phone ---------------------------------------------------------------
   Same content, one column, tighter gutters. The metric buttons become one row
   that scrolls sideways, so the pinned bar stays two rows high instead of four. */
@media (max-width: 640px) {
  header { padding: 10px 14px 0; }
  .verdict, .controlbar { margin-left: -14px; margin-right: -14px;
                          padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 15.5px; }
  main { padding: 12px 10px 32px; gap: 12px; }
  .panel { padding: 12px 12px 14px; }

  .metrics { flex: 1 1 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto;
             scrollbar-width: none; padding-bottom: 1px; }
  .metrics::-webkit-scrollbar { display: none; }
  .mfam { flex: none; }
  .controlbar { gap: 8px; }
  .controlbar > .seg { margin-left: 0; }

  .maprow { flex-direction: column; gap: 10px; }
  .legend { width: 100%; }

  .crow { grid-template-columns: 84px minmax(0, 1fr) auto; gap: 8px; }
  .secbar > .hint { margin-left: 0; }

  .stgrid.chem { grid-template-columns: 1fr 1fr; }
  .stgrid.chem .stcell:not(:last-child) { border-right: 0; }
  .stgrid.chem .stcell:nth-child(odd) { border-right: 1px solid var(--rule2); }

  .zone { grid-template-columns: 34px minmax(0, 1fr) auto; }
}
