:root {
  --bg: #f7f6f2;
  --panel: #fff;
  --ink: #22303a;
  --dim: #6b7a86;
  --line: #dfe3e6;
  --accent: #2c6e49;
  --warn: #b45309;
  --err: #b91c1c;
  --flash: #fff3bf;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; /* vertical only — the page never scrolls horizontally */
  top: 0;
  z-index: 6;
}
h1 { font-size: 18px; margin: 0; }
.controls { display: flex; align-items: center; gap: 8px; }
#status { color: var(--dim); font-size: 12px; }
#status.dirty { color: var(--warn); font-weight: 600; }
#status.stale { color: var(--err); }
button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
nav { display: flex; gap: 4px; padding: 8px 18px 0; position: sticky; top: var(--hdr, 49px); z-index: 5; background: var(--bg); }
.tab { border-radius: 8px 8px 0 0; border-bottom: none; color: var(--dim); }
.tab.active { color: var(--ink); font-weight: 600; background: var(--panel); }
main { padding: 16px 18px 60px; max-width: 1200px; }
main:has(.itemsgrid) { max-width: none; }
/* the Items grid scrolls inside its own container; the page never scrolls
   horizontally, so the header/tabs cannot move */
/* the items grid scrolls both axes inside a viewport-sized box, so its header
   row and name column stay frozen while rows scroll */
.scrollx { overflow: auto; max-height: calc(100vh - var(--chrome, 100px) - 150px); }
/* pinned within the scroll container so it opens where you're looking */
.morefields { position: sticky; left: 12px; max-width: calc(100vw - 80px); }
tr.filtered, .dayblock.filtered { display: none; }
.itemsgrid tbody tr[data-search] { cursor: pointer; }
input.filter { width: 360px; font: inherit; padding: 5px 10px; margin: 0 0 8px; border: 1px solid var(--line); border-radius: 6px; }
footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  gap: 16px;
  padding: 6px 18px;
  font-size: 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.pass { color: var(--accent); font-weight: 600; }
.fail { color: var(--err); font-weight: 700; }
.hint { color: var(--dim); font-size: 12.5px; }
.date { color: var(--dim); font-weight: 400; font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.notes { color: var(--dim); font-size: 12px; max-width: 220px; }

table.grid { border-collapse: collapse; width: 100%; margin: 6px 0 18px; background: var(--panel); }
.grid th, .grid td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
/* page-level tables pin under the sticky chrome; container tables pin at 0 */
.grid th { background: #eef1f0; font-size: 12px; position: sticky; top: var(--chrome, 0px); }
.scrollx .grid th { top: 0; }
.grid tr.marker td { background: #e8f0ea; color: var(--accent); font-weight: 600; font-size: 12px; }
.grid tr.reserve td { background: #f2f0fa; }
.grid tr.avg td { font-weight: 700; background: #eef1f0; }
.grid td.part { background: #fff8e6; }
tr.flash td { background: var(--flash) !important; } /* instant on */
tr.flash-out td { transition: background 3s ease; }  /* slow fade back */
select.daysel { font-size: 12px; margin-right: 2px; }
select.mealauto { color: var(--dim); font-style: italic; } /* meal follows the item's default until explicitly chosen */
button.flagbtn { font-size: 10.5px; padding: 0 6px; border-radius: 8px; color: var(--dim); border-style: dashed; margin-right: 3px; }
button.flagbtn.on { color: #fff; background: var(--accent); border-style: solid; border-color: var(--accent); }
.missing { color: var(--err); }
.num { text-align: right; }

.dayhead { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.dayhead h3 { margin: 4px 0; }
.chip { background: #e8f0ea; color: var(--accent); border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.chip.carry { background: #e5ecf5; color: #2c5282; cursor: pointer; }
.chip.deficit { background: #fdf0e0; color: var(--warn); }
.chip.surplus { background: #e8f0ea; color: var(--accent); }
svg.curve .bar.burn { fill: #b45309; opacity: .7; }
.grid td.primary { background: #f0f5f1; }
#trippicker { display: inline-flex; align-items: center; gap: 3px; margin-right: 10px; }
#trippicker select { font: inherit; max-width: 200px; }
.triplabel { font-size: 13px; color: var(--ink); }
.help { max-width: 800px; line-height: 1.55; }
.help h2 { font-size: 18px; margin: 4px 0 8px; }
.help h3 { font-size: 14px; margin: 18px 0 4px; }
.help-p { margin: 4px 0; color: var(--ink); }
.help code { background: #eef1f0; border-radius: 4px; padding: 0 4px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.help ul { margin: 4px 0; padding-left: 20px; }
.help li { margin: 3px 0; }
details.daycarry { display: inline-block; }
details.daycarry > summary { list-style: none; cursor: pointer; }
details.daycarry > summary::-webkit-details-marker { display: none; }
details.daycarry[open] { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 4px 0; }
.breakdown { margin: 4px 0 6px; padding-left: 18px; font-size: 12.5px; color: var(--dim); }
.breakdown li { margin: 1px 0; }
.badge { background: #ece9f7; border-radius: 8px; padding: 0 6px; font-size: 11px; margin-left: 6px; }
.badge.warn { background: #fdf0e0; color: var(--warn); }
input.srv { width: 64px; }
select { font: inherit; }
button.del { border: none; background: none; color: var(--dim); }
button.del:hover { color: var(--err); }
td.actions { white-space: nowrap; }
button.move { border: none; background: none; color: var(--dim); padding: 0 3px; }
button.move:hover:not(:disabled) { color: var(--accent); }
button.move:disabled { opacity: .3; cursor: default; }
button.mini { font-size: 11px; padding: 1px 6px; }
.addrow { margin: -12px 0 16px; display: flex; gap: 6px; align-items: center; color: var(--dim); font-size: 13px; }
/* separate borders: collapsed borders are shared with neighbors and stay
   behind when the sticky column pins, leaking pixels at the seam */
.itemsgrid { border-collapse: separate; border-spacing: 0; border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.itemsgrid th, .itemsgrid td { border-width: 0 1px 1px 0; }
.itemsgrid td.stick, .itemsgrid th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; background-clip: padding-box; }
.itemsgrid th:first-child { z-index: 2; background: #eef1f0; }
/* opaque apron past the left edge: masks the subpixel seam where scrolled
   content peeks out while the column is pinned (clipped away when unscrolled) */
.itemsgrid td.stick::before, .itemsgrid th:first-child::before {
  content: '';
  position: absolute;
  top: -1px; bottom: -1px; left: -8px;
  width: 8px;
  background: inherit;
}
input.cellnum { width: 62px; font: inherit; border: 1px solid transparent; background: transparent; }
input.celltext { width: 90px; font: inherit; border: 1px solid transparent; background: transparent; }
input.cellname { width: 180px; font: inherit; font-weight: 600; border: 1px solid transparent; background: transparent; }
input.celltext.wide { width: 340px; }
input.cellnum:hover, input.celltext:hover, input.cellname:hover,
input.cellnum:focus, input.celltext:focus, input.cellname:focus { border-color: var(--line); background: #fff; }
tr.itemmore td { background: #fbfaf7; }
.morefields { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12px; color: var(--dim); }
.additem { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.additem h4 { width: 100%; margin: 0 0 4px; }
.additem input { font: inherit; padding: 3px 6px; width: 130px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.card h3 { margin: 0 0 6px; font-size: 14px; }
.big { font-size: 24px; font-weight: 700; color: var(--accent); }
.sub { color: var(--dim); font-size: 12px; margin-bottom: 6px; }

details.trace { margin: 4px 0; font-size: 13px; }
details.trace summary { cursor: pointer; }
.traceval { font-weight: 600; color: var(--accent); }
.tracelabel { color: var(--dim); margin-left: 6px; }
.formula { color: var(--dim); font-size: 12px; font-family: ui-monospace, Menlo, monospace; margin: 2px 0 2px 18px; }
.inputs { margin-left: 18px; border-left: 2px solid var(--line); padding-left: 10px; }
.leaf { font-size: 12.5px; padding: 1px 0; }
.leaf.missing { color: var(--err); }
.leafval { display: inline-block; min-width: 64px; font-weight: 600; }
a.ref { color: var(--dim); font-family: ui-monospace, Menlo, monospace; font-size: 11px; text-decoration: none; border-bottom: 1px dotted var(--dim); margin-left: 4px; }
a.ref:hover { color: var(--accent); }

svg.curve { width: 100%; max-width: 760px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
/* the pack curve scales with trip length and scrolls (long/multi-cache trips) */
.curvewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 8px; }
.curvewrap svg.curve { width: auto; max-width: none; }

/* Summary tiles + Trip-tab config fields */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; }
.tile:hover { border-color: var(--accent); }
.tilelabel { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .02em; }
.tile .big { font-size: 22px; }
.tile.deficit .big, .tile.warn .big { color: var(--warn); }
.tile.err .big { color: var(--err); }
.tripsections { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; align-items: start; }
.tripfield { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
.tripfield > span:first-child { color: var(--dim); }
.tripfield input.wide { width: 12em; }
.ptactions { white-space: nowrap; }
.ptactions button.mini[disabled] { opacity: .3; cursor: default; }
svg.curve .bar { fill: var(--accent); opacity: .85; }
svg.curve .bar.extra { fill: #8fb99f; }
svg.curve text { font-size: 11px; fill: var(--ink); }
svg.curve text.axis { fill: var(--dim); }
/* stepped weight-vs-distance carry curve */
svg.curve .curvearea { fill: var(--accent); opacity: .12; }
svg.curve .curveline { fill: none; stroke: var(--accent); stroke-width: 2; }
svg.curve .curvetick { stroke: var(--line); stroke-width: 1; }
svg.curve .curvedot { fill: var(--accent); }
svg.curve .curvedot.extra { fill: #8fb99f; }
svg.curve text.curvept { font-size: 10px; fill: var(--dim); }
.curvehead { display: flex; align-items: center; gap: 12px; }
.atinput { width: 4.5em; padding: 1px 4px; font: inherit; }
.curvelist { margin-top: 8px; }
.curverow { display: flex; gap: 10px; align-items: baseline; }
.curverow.extra .curvelabel { color: var(--dim); }
.curvelabel { min-width: 180px; font-size: 13px; }

.findings { padding-left: 18px; }
.findings li { margin: 3px 0; }
.findings .code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; background: #eef1f0; border-radius: 4px; padding: 0 4px; }
.findings.err li { color: var(--err); }
.findings.warn li { color: var(--warn); }
.findings.info li { color: var(--dim); }

.toolbar { margin-bottom: 8px; }
.lo-warn { color: var(--warn); font-weight: 600; }
.aisle { margin-left: 6px; font-size: 11px; color: var(--dim); background: #eef1f0; border-radius: 8px; padding: 0 6px; }
.buyctl { font-size: 12px; color: var(--dim); white-space: nowrap; }
.buyctl.shortfall { color: var(--err); font-weight: 700; }
.buyctl button.mini { padding: 0 6px; }
.fixpanel { display: block; margin-top: 4px; padding: 6px 8px; background: #fdf0e0; border: 1px solid var(--warn); border-radius: 6px; font-size: 12px; white-space: normal; }
.fixpanel button { display: inline-block; margin: 3px 4px 0 0; }
#toast { position: fixed; bottom: 44px; left: 50%; transform: translate(-50%, 20px); background: #7c2d12; color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 10; max-width: 80%; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
details.ration { margin-top: 3px; font-size: 12px; color: var(--dim); }
details.ration > summary { cursor: pointer; color: var(--accent); }
.rationform { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 4px; }
.rationform input.srv { width: 52px; }
.hidden { display: none; }
tr.nutdetail td { background: #fbfaf7; }

#drop { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(44,110,73,.12); border: 4px dashed var(--accent); font-size: 22px; color: var(--accent); pointer-events: none; }
#drop.on { display: flex; }

/* sign-in dialog */
dialog#authdialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; width: 320px; max-width: 90vw; background: var(--panel); color: var(--ink); box-shadow: 0 8px 32px rgba(0,0,0,.2); }
dialog#authdialog::backdrop { background: rgba(0,0,0,.35); }
#authform h3 { margin: 0 0 4px; font-size: 17px; }
#authform label { display: block; margin: 12px 0 0; font-size: 12.5px; color: var(--dim); }
#authform input { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; padding: 8px 9px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
#authform input:focus { outline: none; border-color: var(--accent); }
#authform #autherr { min-height: 1.1em; font-size: 12.5px; margin: 8px 0 0; }
#authform .authbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#authform #authsubmit { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#authswitch { margin: 12px 0 0; }
#authswitch a { color: var(--accent); text-decoration: none; }
#authswitch a:hover { text-decoration: underline; }

/* meal combobox (native MUI-Autocomplete-style) */
.combo { position: relative; display: inline-block; }
.comboinput { min-width: 16em; }
.combocal { width: 4.5em; margin-left: 3px; }
.comboday { width: 4em; }
.combolist { position: absolute; z-index: 20; left: 0; top: 100%; min-width: 18em; max-height: 260px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.combogroup { padding: 3px 8px; font-size: 11px; color: var(--dim); background: var(--bg); position: sticky; top: 0; }
.comboopt { padding: 4px 8px; cursor: pointer; font-size: 13px; }
.comboopt:hover { background: #e8f0ea; }
.comboopt.quickadd { color: var(--accent); font-weight: 600; }

/* add-row: labeled fields so each box has a header */
.addrow { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; }
.addfield { display: inline-flex; flex-direction: column; gap: 2px; }
.addfield > span { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .02em; }

/* per-day itinerary reads as a leg: <from> → miles/ascent → <camp> */
.daytrail { font-size: 12px; color: var(--dim); display: flex; flex-wrap: wrap; align-items: center; gap: 2px 5px; margin: 2px 0 8px; }
.daytrail .place { font-weight: 600; color: var(--ink); white-space: nowrap; }
.daytrail .leg { color: var(--dim); font-weight: 600; }
.daytrail .unit { margin-right: 4px; }
.daytrail .camppin { margin-left: 2px; }
.daytrail .notesep { color: var(--line); margin-left: 4px; }
.daytrail.rest .place.from { opacity: .8; }
.daynum { padding: 1px 3px; font: inherit; }
/* hide the number spinners so 4-digit values (e.g. 5227) aren't clipped */
.daynum::-webkit-inner-spin-button, .daynum::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.daynum { -moz-appearance: textfield; }
.daytrail input.celltext { padding: 1px 4px; font: inherit; }
.dayhead button.mini.move { padding: 1px 6px; }

/* cache/vehicle "stops" interspersed in the Timeline spine */
.cachestop { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--panel); padding: 8px 12px; margin: 12px 0; }
.cachestop.vehicle { border-left-color: #8fb99f; }
.cachestophead { display: flex; align-items: center; gap: 10px; }
.cachestoptitle { font-weight: 600; }
.cachestopbody { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 6px; font-size: 13px; color: var(--dim); }
.cachestop input.cacheday { width: 3.4em; padding: 1px 4px; font: inherit; }
.cachestop select { margin: 0 2px; }
.cachestop .trashlbl { display: inline-flex; align-items: center; gap: 4px; }

/* timeline toolbar (filter + collapse-all) */
.timelinebar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* per-day collapsible meals */
.daymeals { margin-top: 4px; }
.daymeals > summary { cursor: pointer; color: var(--dim); font-size: 13px; list-style-position: inside; padding: 2px 0; }
.daymeals-sum { margin-left: 4px; }

/* ± error-bar on energy estimates */
.chip .pm { opacity: .7; font-variant-numeric: tabular-nums; }

/* per-day schedule estimate */
.daysched { margin: 2px 0 6px; }
.daysched > summary { cursor: pointer; list-style-position: inside; }
.chip.sched { background: #eef3ff; color: #2a4a7f; }
.schedbody { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 6px 2px 2px; font-size: 12px; color: var(--dim); }
.schedrow { white-space: nowrap; }
.schedfield { display: inline-flex; align-items: center; gap: 4px; }

/* add-day bar on the timeline */
.adddaybar { margin: 10px 0; }
.adddaybar .hint { margin-left: 6px; }
.adhocbox { margin-top: 12px; }
.adhocbox > summary { cursor: pointer; color: var(--dim); font-size: 13px; }

/* caches (supply-point) editor */
.cachegrid th { text-align: left; font-weight: 600; color: var(--dim); font-size: 12px; }
.cachegrid td { vertical-align: middle; }
.cachegrid input.cacheid { width: 7em; font-family: ui-monospace, monospace; }
.cachegrid input.cachelabel { width: 10em; }
.cachegrid input.cacheday { width: 3.4em; }
.cachegrid select { margin: 0 2px; }
.glyphpick { max-width: 12em; }
.daytrail .celltext { padding: 1px 4px; font: inherit; }
.caches h2 { margin: 0 0 4px; }

/* empty state (no trip loaded) */
.empty { text-align: center; padding: 44px 16px; max-width: 560px; margin: 0 auto; }
.empty h2 { margin: 0 0 6px; }
.emptyactions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.emptyactions .big-action { font-size: 15px; padding: 10px 16px; border-color: var(--accent); color: var(--accent); font-weight: 600; }

@media print {
  header, nav, footer, .addrow, .additem, .toolbar, button, input, select { display: none !important; }
  details.trace { display: none; }
  main { padding: 0; max-width: none; }
  body { background: #fff; }
}
