/* Niloscale dashboard. Layout and colours follow the 2026-08 farmer dashboard prototype
   (niloscale-reservoir/dashboard/). --brand and --brand-2 are set per farm in base.html. */
:root {
  color-scheme: light;
  --bg: #e9eef1; --surface: #ffffff; --surface-2: #f3f6f7;
  --ink: #0f1a22; --ink-2: #48606d; --muted: #6f8794;
  --border: #dde5e9; --border-2: #cdd8dd; --grid: #e6ecef;
  --brand: #356271; --brand-2: #e7b24c;
  --brand-ink: var(--brand);  /* the brand colour for text and chart lines; lighter in dark mode */
  /* One colour per cage on the farm charts (Okabe-Ito, readable with colour blindness). */
  --c1: #0072b2; --c2: #e69f00; --c3: #009e73; --c4: #cc79a7;
  --c5: #d55e00; --c6: #56b4e9; --c7: #7a5195; --c8: #5b6770;
  --good: #0a8f14; --warning: #b7791a; --danger: #b42318;
  --shadow: 0 1px 2px rgba(15,26,34,.05), 0 6px 20px -12px rgba(15,26,34,.22);
  --shadow-lg: 0 24px 60px -20px rgba(15,26,34,.45);
  --r: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e141a; --surface: #161f26; --surface-2: #1b262e;
    --ink: #eef5f8; --ink-2: #a7bcc7; --muted: #7d95a3;
    --border: #253139; --border-2: #33424c; --grid: #212d35;
    --good: #2fb43a; --warning: #e0a63a; --danger: #f97066;
    --c1: #4aa3e0; --c2: #f0b43c; --c3: #2fc19a; --c4: #e39cc4;
    --c5: #f0803c; --c6: #8fd0f5; --c7: #b58bd6; --c8: #c9d1d6;
  }
  @supports (color: color-mix(in srgb, red 50%, blue)) {
    :root { --brand-ink: color-mix(in srgb, var(--brand) 55%, white); }
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased; line-height: 1.45; }
a { color: var(--brand-ink); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---- header ---- */
header.app { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); }
.head-inner { max-width: 1120px; margin: 0 auto; padding: 12px 16px; display: flex;
  align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.logo { width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-weight: 800; font-size: 15px; display: grid; place-items: center; box-shadow: var(--shadow); }
.brandtext { display: flex; flex-direction: column; min-width: 0; }
.brandtext .title { font-size: 19px; font-weight: 750; letter-spacing: -.02em; }
.brandtext .sub { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.usernav { display: flex; align-items: center; gap: 14px; font-size: 13.5px; font-weight: 600; }
.usernav a { color: var(--ink-2); text-decoration: none; }
.usernav a:hover { color: var(--ink); }
.usernav form { margin: 0; }
.usernav button { font: inherit; color: var(--ink-2); background: none; border: 0; padding: 0; cursor: pointer; }
.usernav button:hover { color: var(--ink); }

/* ---- farm page ---- */
.summary { display: flex; gap: 18px; flex-wrap: wrap; margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px; }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 750; }
.staffnote { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 13.5px;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface)); border: 1px solid var(--border); }
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.search { position: relative; flex: 1 1 240px; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 10px 14px 10px 38px; box-shadow: var(--shadow); }
.search input:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.seg { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2); border: 0; background: transparent;
  padding: 7px 12px; border-radius: 999px; cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.seg-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.count { color: var(--muted); font-size: 12.5px; margin: 16px 2px 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 15px 16px 14px; color: inherit; text-decoration: none;
  transition: transform .12s, border-color .15s, box-shadow .15s; }
.card:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: var(--shadow-lg); }
.card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.card[hidden] { display: none; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cname { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.open { font-size: 12px; font-weight: 700; color: var(--brand-ink); white-space: nowrap; }
.abwrow { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 1px; flex-wrap: wrap; }
.abwrow .big { font-size: 29px; font-weight: 760; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.abwrow .big .u { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.delta { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); } .delta.down { color: var(--warning); } .delta.flat { color: var(--muted); }
.asof { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.spark, .minihist { display: block; width: 100%; overflow: visible; }
.spark { height: 52px; }
.minihist { height: 46px; }
.histwrap { position: relative; }
.spread-lab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 10px 0 2px; }
.spread-lab .t { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
.spread-lab .r { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 48px 12px; font-size: 14px; }
.empty[hidden] { display: none; }

/* ---- whole farm ---- */
.section-title { font-size: 18px; font-weight: 750; letter-spacing: -.01em; margin: 26px 0 0; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px;
  background: var(--swatch); vertical-align: 0; }
.c1 { --swatch: var(--c1); } .c2 { --swatch: var(--c2); } .c3 { --swatch: var(--c3); } .c4 { --swatch: var(--c4); }
.c5 { --swatch: var(--c5); } .c6 { --swatch: var(--c6); } .c7 { --swatch: var(--c7); } .c8 { --swatch: var(--c8); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--border-2); }
.chip[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
#farm-growth { display: block; width: 100%; height: 280px; overflow: visible; }
#farm-dist { display: block; width: 100%; height: 240px; overflow: visible; }

/* ---- cage page ---- */
.crumbs { margin: 4px 0 6px; font-size: 13.5px; font-weight: 600; }
.crumbs a { text-decoration: none; }
.cage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 760; letter-spacing: -.02em; margin: 0 0 12px; }
.staff-link { font-size: 13px; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1px; }
.stat .k { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 760; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }
.panels { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
@media (min-width: 760px) { .panels { grid-template-columns: 1.5fr 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.ph { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.chartbox { position: relative; width: 100%; }
#growth { display: block; width: 100%; height: 280px; overflow: visible; }
#dist { display: block; width: 100%; height: 240px; overflow: visible; }
.legend { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.dates { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; -webkit-overflow-scrolling: touch; }
.dates button { flex: 0 0 auto; font: inherit; font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px;
  cursor: pointer; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dates button:hover { color: var(--ink); border-color: var(--border-2); }
.dates button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.dates button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.table-panel { margin-top: 14px; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.table-scroll { overflow-x: auto; }
table.readings { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.readings th { text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.readings td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.readings td.n, .readings th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.readings tbody tr { cursor: pointer; }
.readings tbody tr:hover { background: var(--surface-2); }
.readings tbody tr.active { background: color-mix(in srgb, var(--brand-ink) 16%, transparent); }
@media (max-width: 560px) { .readings .wide { display: none; } }  /* all columns are in the CSV */

/* ---- tooltips ---- */
.tt { position: absolute; pointer-events: none; z-index: 30; opacity: 0; transform: translate(-50%, calc(-100% - 8px));
  transition: opacity .1s; background: var(--ink); color: var(--bg); border-radius: 8px; padding: 7px 9px;
  font-size: 12px; box-shadow: 0 8px 24px -8px rgba(0,0,0,.5); white-space: nowrap; }
.tt .h { font-weight: 700; margin-bottom: 3px; opacity: .85; font-size: 11px; }
.tt .row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }

/* ---- forms, buttons, lists ---- */
.auth-card { max-width: 380px; margin: 40px auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow); padding: 24px; }
.form { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.form label { font-size: 13px; font-weight: 650; margin-top: 8px; }
.form input { font: inherit; font-size: 15px; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--border-2); border-radius: 10px; padding: 10px 12px; }
.form input:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.form .button { margin-top: 16px; }
.form-error { color: var(--danger); font-size: 13.5px; }
.form-error p { margin: 4px 0; }
.button { display: inline-block; font: inherit; font-size: 13.5px; font-weight: 650; text-decoration: none;
  color: var(--ink); background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; }
.button.primary { color: #fff; background: var(--brand); border-color: var(--brand); padding: 11px 14px; }
.button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.farm-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.farm-list a { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.farm-list span { color: var(--muted); font-size: 13px; margin-left: 6px; }
footer.note { color: var(--muted); font-size: 12px; margin: 0 0 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
