/*
  Eaves: home energy dashboard (Screenery template)
  1. Tokens: warm almanac paper, one ink, one sun yellow used only for the sun (generation, the sun mark,
     the current range), and a brick red kept for errors. Radio Canada for words, M PLUS 1 Code for figures.
  2. Layout: a ruled sidebar masthead and a main column of almanac sections (sun table, figures, charts,
     ledgers, calendar, planner, tariff). Hairlines and double rules do the work cards would do elsewhere.
  3. Phones: the sidebar folds into the header, a bottom bar takes the sections, drawers become full sheets.
*/

/* ---------- Tokens ---------- */
:root {
  --paper: #f2ead8;
  --paper-2: #ece2cc;      /* a shade darker, for wells */
  --paper-3: #e4d8bc;      /* skeletons, hover */
  --ink: #2a251d;
  --ink-2: #554c3f;        /* secondary text, 7:1 on paper */
  --ink-3: #6b604f;        /* tertiary text, 5:1 on paper */
  --rule: #cbbd9c;         /* hairlines */
  --rule-ink: #2a251d;     /* heavy and double rules */
  --sun: #f0b62a;          /* the one accent: the sun and what it makes */
  --sun-wash: #f6d77e;
  --sun-pale: #f7e6b4;
  --night: #e0d6c0;        /* night-rate hours */
  --bad: #9c2f1b;
  --bad-wash: #f3d9cc;

  --f-word: "Radio Canada", "Helvetica Neue", Arial, sans-serif;
  --f-fig: "M PLUS 1 Code", ui-monospace, Menlo, monospace;

  --t-xs: 0.75rem;   /* 12px: ticks, table heads */
  --t-s: 0.875rem;   /* 14px: body of the app */
  --t-m: 1.0625rem;  /* 17px: panel headings */
  --t-l: 1.5rem;     /* 24px: section heads */
  --t-xl: clamp(1.6rem, 1.1rem + 1.6vw, 2.4rem);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --r: 3px;
  --side: 236px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 10px 30px -12px rgba(42, 37, 29, 0.35), 0 2px 6px rgba(42, 37, 29, 0.12);
}

/* ---------- Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 16px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--t-s)/1.5 var(--f-word);
  font-variant-numeric: tabular-nums;
  caret-color: var(--ink); accent-color: var(--ink);
  scrollbar-color: var(--rule) var(--paper);
}
::selection { background: var(--sun-wash); color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
kbd { font: 500 var(--t-xs) var(--f-fig); border: 1px solid var(--ink-3); border-radius: 3px; padding: 0 4px; background: var(--paper); }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 50; }
.skip:focus { top: 12px; }
.muted { color: var(--ink-3); }
.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow: auto;
  border-right: 3px double var(--rule-ink);
  padding: var(--s5) var(--s5) var(--s4);
  display: flex; flex-direction: column; gap: var(--s5);
  padding-bottom: 56px; /* room for the gallery badge */
}
.mast { border-bottom: 1px solid var(--rule-ink); padding-bottom: var(--s4); }
.mast-mark { width: 56px; height: 38px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.mast-mark .mm-sun { fill: var(--sun); stroke: none; }
.mast-name { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; margin-top: var(--s2); }
.mast-house { color: var(--ink-2); margin-top: var(--s1); }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: var(--s3); padding: 8px 10px; margin: 0 -10px; text-decoration: none; border-radius: var(--r); font-weight: 500; color: var(--ink-2); }
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a.is-on { color: var(--ink); background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--rule); }
.nav a.is-on .i { color: var(--ink); fill: none; }
.nav a.is-on .i path:first-child { stroke: var(--ink); }
.kit { margin: 0; display: grid; gap: var(--s3); border-top: 1px solid var(--rule); padding-top: var(--s4); }
.kit dt { font: 500 var(--t-xs) var(--f-word); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }
.kit dd { margin: 2px 0 0; color: var(--ink); }
.sync { margin-top: auto; display: flex; align-items: center; gap: var(--s2); color: var(--ink-2); font-size: var(--t-xs); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.sync[data-s="ready"] .dot { background: var(--sun); box-shadow: 0 0 0 1px var(--ink); }
.sync[data-s="error"] .dot, .sync[data-s="offline"] .dot { background: var(--bad); }
.sync[data-s="loading"] .dot { background: var(--paper-3); box-shadow: 0 0 0 1px var(--ink-3); }
.keys { font-size: var(--t-xs); color: var(--ink-3); }

.main { min-width: 0; padding: var(--s5) clamp(16px, 3vw, 48px) var(--s8); max-width: 1240px; width: 100%; }

/* ---------- Header ---------- */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4) var(--s5); flex-wrap: wrap; padding-bottom: var(--s4); border-bottom: 3px double var(--rule-ink); }
.top h1 { font-size: var(--t-xl); font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.folio { color: var(--ink-2); margin-top: var(--s2); }
.range { display: inline-flex; border: 1px solid var(--rule-ink); border-radius: var(--r); background: var(--paper); }
.range button { border: 0; background: none; padding: 7px 14px; min-height: 36px; cursor: pointer; font-weight: 500; color: var(--ink-2); border-right: 1px solid var(--rule); }
.range button:last-child { border-right: 0; }
.range button:hover { color: var(--ink); background: var(--paper-2); }
.range button[aria-pressed="true"] { background: var(--sun); color: var(--ink); font-weight: 600; }

/* ---------- Banner (error, offline, empty) ---------- */
.banner { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s4); padding: var(--s3) var(--s4); border: 1px solid var(--rule-ink); border-radius: var(--r); background: var(--paper-2); }
.banner[hidden] { display: none; }
.banner p { flex: 1; }
[data-state="error"] .banner, [data-state="offline"] .banner { border-color: var(--bad); background: var(--bad-wash); }
[data-state="error"] .banner .i, [data-state="offline"] .banner .i { color: var(--bad); }
.banner.static { display: block; }

/* ---------- Sections ---------- */
.sec { padding-top: var(--s7); }
.sec + .sec { margin-top: var(--s5); border-top: 1px solid var(--rule-ink); padding-top: var(--s6); }
#today { padding-top: var(--s5); }
.sec-head { display: flex; align-items: baseline; gap: var(--s2) var(--s4); flex-wrap: wrap; margin-bottom: var(--s4); }
.sec-head h2 { font-size: var(--t-l); letter-spacing: -0.02em; }
.sec-sub { color: var(--ink-2); flex: 1 1 260px; }
.sec-head .btn { margin-left: auto; align-self: center; }

/* ---------- Sun table ---------- */
.sun { display: grid; grid-template-columns: minmax(0, 1fr) 260px; grid-template-rows: auto 1fr; column-gap: var(--s6); align-items: start; border-top: 1px solid var(--rule-ink); border-bottom: 1px solid var(--rule-ink); padding: var(--s3) 0; }
.sun-table { border-collapse: collapse; width: 100%; }
.sun-table th { font: 500 var(--t-xs) var(--f-word); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); text-align: left; padding: 0 var(--s3) var(--s1) 0; border-bottom: 1px solid var(--rule); }
.sun-table td { font: 500 1.375rem var(--f-fig); padding: var(--s2) var(--s3) 0 0; letter-spacing: -0.02em; white-space: nowrap; }
.sun-note { grid-column: 1; margin-top: var(--s3); color: var(--ink-2); }
.sun-note i { color: var(--ink); font-style: italic; }
.sunpath { grid-column: 2; grid-row: 1 / span 2; width: 100%; height: auto; overflow: visible; }
.sp-summer { fill: none; stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }
.sp-today { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.sp-ground { stroke: var(--ink); stroke-width: 1.4; }
.sp-house { fill: var(--paper); stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round; }
.sp-panel { stroke: var(--ink); stroke-width: 3; }
.sp-sun { fill: var(--sun); stroke: var(--ink); stroke-width: 1.2; }
.sp-t { font: 400 10.5px var(--f-fig); fill: var(--ink-2); }

/* ---------- Figures row ---------- */
.figs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: var(--s5) 0; border-bottom: 1px solid var(--rule); }
.figs > div { padding: 0 var(--s4) var(--s4); border-left: 1px solid var(--rule); min-width: 0; }
.figs > div:first-child { border-left: 0; padding-left: 0; }
.figs dt { font: 500 var(--t-xs) var(--f-word); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.figs dd { margin: var(--s1) 0 0; font: 500 1.75rem/1.15 var(--f-fig); letter-spacing: -0.03em; white-space: nowrap; }
.figs dd small { font: 400 var(--t-s) var(--f-word); color: var(--ink-2); letter-spacing: 0; }
.fig-note { color: var(--ink-2); font-size: var(--t-xs); margin-top: 2px; min-height: 1.5em; }
.fig-net dd span { background: linear-gradient(transparent 62%, var(--sun-wash) 62%); padding: 0 2px; }

/* ---------- Panels and charts ---------- */
.panel { margin: 0; min-width: 0; }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2) var(--s4); flex-wrap: wrap; margin-bottom: var(--s3); }
.panel-h h3, .sub-h { font-size: var(--t-m); }
.sub-h { margin-top: var(--s5); margin-bottom: var(--s2); }
.legend { display: flex; gap: var(--s4); flex-wrap: wrap; color: var(--ink-2); font-size: var(--t-xs); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.k { display: inline-block; width: 14px; height: 10px; flex: none; }
.gen-k { background: var(--sun); box-shadow: inset 0 0 0 1px rgba(42, 37, 29, 0.35); }
.use-k { height: 2px; background: var(--ink); }
.fc-k { background: repeating-linear-gradient(135deg, var(--sun) 0 2px, var(--paper) 2px 4px); box-shadow: inset 0 0 0 1px rgba(42, 37, 29, 0.35); }
.soc-k { height: 2px; background: var(--ink); }
.night-k { background: var(--night); }
.chart { position: relative; min-width: 0; outline-offset: 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .axis { stroke: var(--ink); stroke-width: 1; }
.chart .tick { font: 400 11px var(--f-fig); fill: var(--ink-2); }
.chart .tick.unit { fill: var(--ink-3); }
.chart .tick.note { font-family: var(--f-word); font-style: italic; fill: var(--ink-2); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; stroke-linejoin: round; }
.chart .daylight { fill: var(--sun-pale); opacity: 0.55; }
.chart .gen { fill: var(--sun); stroke: rgba(42, 37, 29, 0.55); stroke-width: 0.8; }
.chart .gen.fc { fill: url(#hatch); fill: var(--sun-wash); stroke-dasharray: 3 2; }
.chart .gen.fc-solid { fill: var(--sun); }
.chart .use { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.chart .use.fc { stroke-dasharray: 4 3; stroke-width: 1.2; }
.chart .tick-use { stroke-width: 2; }
.chart .clip { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.chart .now { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 1 2; }
.chart .now-t { fill: var(--ink); font-weight: 600; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; }
.chart .soc { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.chart .soc.fc { stroke-dasharray: 4 3; stroke-width: 1.2; }
.chart .night { fill: var(--night); }
.chart .reserve { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .socbar { fill: var(--ink); }
.chart .runline { stroke: var(--ink); stroke-width: 4; stroke-linecap: butt; }
.readout {
  position: absolute; top: 4px; z-index: 3; pointer-events: none;
  display: grid; gap: 1px; padding: 8px 10px; min-width: 150px;
  background: var(--paper); border: 1px solid var(--rule-ink); border-radius: var(--r); box-shadow: var(--shadow);
  font: 400 var(--t-xs)/1.45 var(--f-fig); white-space: nowrap;
}
.readout[hidden] { display: none; }
.readout b { font: 600 var(--t-xs) var(--f-word); }
.readout i { font-family: var(--f-word); color: var(--ink-2); }
.readout span { display: flex; align-items: center; gap: 6px; }
.readout .k { width: 10px; }
.hint { color: var(--ink-3); font-size: var(--t-xs); margin-top: var(--s2); }
.chart-panel { padding-top: var(--s2); }
.empty-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-style: italic; }
.empty-msg[hidden] { display: none; }

.duo { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--s6); margin-top: var(--s6); padding-top: var(--s5); border-top: 1px solid var(--rule); }

/* Battery: a drawn cell with its reserve mark */
.batt-now { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s3); }
.cell { position: relative; width: 120px; height: 40px; border: 1.5px solid var(--ink); border-radius: 4px; flex: none; }
.cell::after { content: ""; position: absolute; right: -6px; top: 12px; width: 4px; height: 14px; border: 1.5px solid var(--ink); border-left: 0; border-radius: 0 2px 2px 0; }
.cell-fill { position: absolute; left: 3px; top: 3px; bottom: 3px; width: calc((100% - 6px) * var(--soc, 0)); background: var(--ink); border-radius: 1px; transition: width 0.6s var(--ease); }
.cell-res { position: absolute; left: calc(3px + (100% - 6px) * 0.1); top: -5px; bottom: -5px; border-left: 1px dashed var(--bad); }
.batt-pct { display: block; font: 500 1.75rem/1.1 var(--f-fig); letter-spacing: -0.03em; }
.batt-kwh { display: block; color: var(--ink-2); font-size: var(--t-xs); }
.batt-note { color: var(--ink-2); margin-bottom: var(--s4); max-width: 60ch; min-height: 3em; }
.chart.small { margin-bottom: var(--s2); }

/* Ledgers */
.tscroll { overflow-x: auto; }
.ledger { width: 100%; border-collapse: collapse; }
.ledger th, .ledger td { padding: 7px var(--s3) 7px 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: baseline; }
.ledger thead th { font: 500 var(--t-xs) var(--f-word); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); border-bottom: 1px solid var(--rule-ink); padding-top: 0; }
.ledger tbody th { font-weight: 400; }
.ledger td { font-family: var(--f-fig); white-space: nowrap; }
.ledger td:last-child, .ledger thead th:last-child { text-align: right; padding-right: 0; }
.money td:nth-child(2), .money thead th:nth-child(2), .money td:nth-child(3), .money thead th:nth-child(3) { text-align: right; }
.balance td, .balance thead th:nth-child(2) { text-align: right; }
.bal { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); }
.ledger tr.sum th, .ledger tr.sum td { border-top: 1px solid var(--rule-ink); border-bottom: 3px double var(--rule-ink); font-weight: 600; }
.ledger tr.sum td { font-weight: 600; }
.ledger td small { font-family: var(--f-word); color: var(--ink-2); font-weight: 400; margin-left: 6px; }
.note { color: var(--ink-2); margin-top: var(--s3); max-width: 70ch; }

/* ---------- Month calendar ---------- */
.month { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: var(--s3) var(--s6); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--rule-ink); border-left: 1px solid var(--rule); }
.cal-h { font: 500 var(--t-xs) var(--f-word); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); padding: 6px 8px; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule-ink); }
.cal-pad { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); background: var(--paper-2); }
.cal-day {
  position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr auto; gap: 2px;
  min-height: 78px; padding: 6px 8px 10px; text-align: left; cursor: pointer;
  background: var(--paper); border: 0; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  transition: background-color 0.15s var(--ease);
}
.cal-day:hover:not(:disabled) { background: var(--paper-2); }
.cal-day:disabled { cursor: default; }
.cal-day .cd-n { font: 600 var(--t-s) var(--f-word); }
.cal-day .i { color: var(--ink-2); justify-self: end; }
.cal-day .cd-k { grid-column: 1 / -1; align-self: end; font: 500 var(--t-s) var(--f-fig); }
.cal-day .cd-k small { font: italic 400 var(--t-xs) var(--f-word); color: var(--ink-2); }
.cal-day .cd-bar { grid-column: 1 / -1; height: 5px; background: var(--paper-3); position: relative; overflow: hidden; }
.cal-day .cd-bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: calc(var(--f) * 100%); background: var(--sun); }
.cal-day.is-fc { background: repeating-linear-gradient(135deg, var(--paper) 0 6px, var(--paper-2) 6px 7px); }
.cal-day.is-fc .cd-bar::after { background: var(--sun-wash); }
.cal-day.in-range { box-shadow: inset 0 3px 0 var(--ink); }
.cal-day.is-today .cd-n { background: var(--ink); color: var(--paper); padding: 0 6px; border-radius: 2px; justify-self: start; }
.month-facts { margin: 0; display: grid; align-content: start; border-top: 1px solid var(--rule-ink); }
.month-facts > div { padding: var(--s2) 0; border-bottom: 1px solid var(--rule); }
.month-facts dt { color: var(--ink-3); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
.month-facts dd { margin: 2px 0 0; font: 500 var(--t-m) var(--f-fig); }
.month-verse { grid-column: 1; font-style: italic; color: var(--ink-2); max-width: 70ch; }

/* ---------- Sunny hours ---------- */
.spare { margin-bottom: var(--s3); }
.runs { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule-ink); }
.run { display: grid; grid-template-columns: 76px minmax(0, 1fr) 140px 52px auto; gap: var(--s4); align-items: center; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.run-t { font: 500 var(--t-m) var(--f-fig); display: grid; line-height: 1.2; }
.run-t small, .run-n small { font: 400 var(--t-xs) var(--f-word); color: var(--ink-2); }
.run-n { display: grid; min-width: 0; }
.run-s { display: flex; align-items: center; gap: var(--s2); font: 400 var(--t-xs) var(--f-fig); }
.share { width: 60px; height: 8px; background: var(--paper-3); position: relative; flex: none; box-shadow: inset 0 0 0 1px var(--rule); }
.share::after { content: ""; position: absolute; inset: 0 auto 0 0; width: calc(var(--s) * 100%); background: var(--sun); }
.run-c { font: 500 var(--t-s) var(--f-fig); text-align: right; }
.run-a { display: flex; gap: var(--s3); justify-content: flex-end; }
.runs-empty { padding: var(--s5) 0; color: var(--ink-2); border-bottom: 1px solid var(--rule); }

/* ---------- Tariff ---------- */
.tariff { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: var(--s6); align-items: start; }
.rates { border-top: 1px solid var(--rule-ink); }
.rates td:nth-child(2) { text-align: right; }
.rates td:last-child { font-family: var(--f-word); color: var(--ink-2); }
.t-month { border-top: 1px solid var(--rule-ink); padding-top: var(--s3); }
.t-big { font: 500 2rem/1.1 var(--f-fig); letter-spacing: -0.03em; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 40px; padding: 8px 16px; border: 1px solid var(--ink); border-radius: var(--r); background: var(--ink); color: var(--paper); font-weight: 600; cursor: pointer; transition: background-color 0.15s var(--ease), color 0.15s var(--ease); }
.btn:hover { background: #3d362b; }
.btn[hidden] { display: none; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.small { min-height: 34px; padding: 4px 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn[aria-busy="true"] { opacity: 1; cursor: progress; }
.btn .spin { display: none; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.btn[aria-busy="true"] .spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; padding: 4px 2px; min-height: 28px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; color: var(--ink); }
.link:hover { text-decoration-thickness: 2px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--rule); border-radius: var(--r); background: transparent; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--paper-2); }

/* ---------- Drawers ---------- */
.scrim { position: fixed; inset: 0; background: rgba(42, 37, 29, 0.32); z-index: 30; opacity: 0; transition: opacity 0.25s var(--ease); }
.scrim.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(520px, 100%); overflow: auto;
  background: var(--paper); border-left: 3px double var(--rule-ink); box-shadow: var(--shadow);
  padding: var(--s5); display: grid; align-content: start; gap: var(--s4);
  transform: translateX(24px); opacity: 0; transition: transform 0.35s var(--ease), opacity 0.25s var(--ease);
}
.drawer.open { transform: none; opacity: 1; }
.drawer[hidden], .scrim[hidden] { display: none; }
.drawer form { display: grid; gap: var(--s4); }
.drawer-h { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s4); padding-bottom: var(--s3); border-bottom: 3px double var(--rule-ink); }
.drawer-h h2 { font-size: var(--t-l); }
.drawer-h .sec-sub { margin-top: var(--s1); }
.drawer-f { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; padding-top: var(--s3); border-top: 1px solid var(--rule); }
.drawer-f #day-use-range { margin-left: auto; }
.day-ledger td { text-align: right; }

/* Fields */
.field { display: grid; gap: 6px; margin: 0; min-width: 0; }
.field label, .field legend { font-weight: 500; }
.field input:not([type="radio"]), .field select {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--ink-3); border-radius: var(--r); background: #faf5ea;
  font-family: var(--f-fig); font-size: var(--t-s);
}
.field select { font-family: var(--f-word); }
.field input:focus-visible, .field select:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; border-color: var(--ink); }
.field.has-error input, .field.has-error select { border-color: var(--bad); background: #fbf0ea; }
.err { color: var(--bad); font-size: var(--t-xs); font-weight: 500; }
.help { color: var(--ink-2); font-size: var(--t-xs); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); align-items: start; }
.pair[hidden], .field[hidden] { display: none; }
.seg { border: 0; padding: 0; }
.seg legend { padding: 0; margin-bottom: 6px; }
.seg label { display: flex; align-items: center; gap: var(--s2); min-height: 32px; font-weight: 400; cursor: pointer; }
.seg input { width: 18px; height: 18px; margin: 0; }
.suggest { padding: var(--s3); background: var(--sun-pale); border: 1px solid var(--rule-ink); border-radius: var(--r); min-height: 3.2em; }
.form-msg { color: var(--bad); background: var(--bad-wash); border: 1px solid var(--bad); border-radius: var(--r); padding: var(--s3); }
.form-msg[hidden] { display: none; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); column-gap: var(--s3); border-bottom: 1px solid var(--rule); counter-reset: st; }
.steps li { counter-increment: st; padding: 0 0 var(--s2); color: var(--ink-3); font-size: var(--t-xs); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.steps li span::before { content: counter(st) ". "; font-family: var(--f-fig); }
.steps li.is-on { color: var(--ink); border-bottom-color: var(--sun); font-weight: 600; }
.steps li.is-done { color: var(--ink-2); }
.step[hidden] { display: none; }
.step { display: grid; gap: var(--s4); }
.review td { text-align: right; white-space: normal; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: var(--s4); max-width: min(560px, calc(100% - 32px)); padding: 10px 16px; background: var(--ink); color: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); }
.toast[hidden] { display: none; }
.toast .link { color: var(--sun); }

/* ---------- Footer ---------- */
.foot { margin-top: var(--s7); padding-top: var(--s4); border-top: 3px double var(--rule-ink); color: var(--ink-2); display: grid; gap: var(--s2); font-size: var(--t-xs); }
.foot p { max-width: 80ch; }

/* ---------- States: loading skeletons, empty ---------- */
.skel-chart { display: none; }
[data-state="loading"] .skel-chart { display: block; position: absolute; inset: 0; min-height: 160px; background: linear-gradient(90deg, var(--paper-2), var(--paper-3), var(--paper-2)); background-size: 200% 100%; border-radius: var(--r); animation: shimmer 1.4s linear infinite; }
[data-state="loading"] .chart { min-height: 180px; }
[data-state="loading"] .chart.small { min-height: 150px; }
[data-state="loading"] [data-skel] { color: transparent !important; background: var(--paper-3); border-radius: 2px; animation: shimmer 1.4s linear infinite; background-image: linear-gradient(90deg, var(--paper-2), var(--paper-3), var(--paper-2)); background-size: 200% 100%; }
[data-state="loading"] .fig-note[data-skel] { width: 70%; }
[data-state="loading"] #balance-body, [data-state="loading"] #account-body { opacity: 0.25; }
[data-state="loading"] .cal-day .cd-k { color: transparent; background: var(--paper-3); }
@keyframes shimmer { to { background-position: -200% 0; } }
[data-state="empty"] .chart:not(.spare) svg { visibility: hidden; }
[data-state="empty"] .chart:not(.spare) { min-height: 140px; border: 1px dashed var(--rule); }

/* ---------- Phone bottom bar (hidden on wide screens) ---------- */
.tabbar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .sun { grid-template-columns: minmax(0, 1fr) 220px; column-gap: var(--s5); }
  .figs dd { font-size: 1.45rem; }
  .duo { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1023px) {
  :root { --side: 200px; }
  .side { padding: var(--s4); }
  .kit dd { font-size: var(--t-xs); }
  .month { grid-template-columns: minmax(0, 1fr); }
  .month-facts { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); column-gap: var(--s4); }
  .tariff { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: var(--s4); }
  .figs > div:nth-child(4) { border-left: 0; padding-left: 0; }
  .run { grid-template-columns: 70px minmax(0, 1fr) 120px 44px; }
  .run-a { grid-column: 2 / -1; justify-content: flex-start; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 3px double var(--rule-ink); flex-direction: row; align-items: center; padding: var(--s3) var(--s4); gap: var(--s4); }
  .mast { border: 0; padding: 0; display: flex; align-items: center; gap: var(--s2) var(--s3); }
  .mast-mark { width: 40px; height: 28px; }
  .mast-name { font-size: 1.5rem; margin: 0; }
  .nav, .kit, .keys { display: none; }
  .sync { margin: 0 0 0 auto; }
  .main { padding-bottom: 96px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--paper); border-top: 3px double var(--rule-ink); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 2px; min-height: 48px; font-size: var(--t-xs); font-weight: 500; text-decoration: none; color: var(--ink-2); border-radius: var(--r); }
  .tabbar a .i { width: 20px; height: 20px; }
  .tabbar a.is-on { color: var(--ink); background: var(--paper-2); box-shadow: inset 0 -3px 0 var(--sun); }
  .toast { bottom: 84px; }
}
@media (max-width: 640px) {
  .top { align-items: stretch; }
  .banner { flex-wrap: wrap; }
  .banner p { flex: 1 1 calc(100% - 40px); }
  .banner .btn { margin-left: 28px; }
  .mast-house { display: none; }
  .range { width: 100%; }
  .range button { flex: 1; padding: 7px 4px; }
  .sun { grid-template-columns: minmax(0, 1fr); }
  .sunpath { grid-column: 1; grid-row: auto; max-width: 320px; margin-top: var(--s3); }
  .sun-table thead { display: none; }
  .sun-table, .sun-table tbody, .sun-table tr { display: block; }
  .sun-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2) var(--s3); }
  .sun-table td { font-size: 1.125rem; padding: 0; display: grid; }
  .sun-table td::before { font: 500 var(--t-xs) var(--f-word); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
  .sun-table td:nth-child(1)::before { content: "Rises"; }
  .sun-table td:nth-child(2)::before { content: "South"; }
  .sun-table td:nth-child(3)::before { content: "Sets"; }
  .sun-table td:nth-child(4)::before { content: "Daylight"; }
  .sun-table td:nth-child(5)::before { content: "Noon height"; }
  .figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figs > div { border-left: 0; padding: 0 0 var(--s3); }
  .figs > div:nth-child(even) { border-left: 1px solid var(--rule); padding-left: var(--s3); }
  .figs .fig-net { grid-column: 1 / -1; border-left: 0 !important; padding-left: 0 !important; border-top: 1px solid var(--rule); padding-top: var(--s3); }
  .figs dd { font-size: 1.4rem; }
  .cal-day { min-height: 60px; padding: 4px 4px 7px; }
  .cal-day .i { display: none; }
  .cal-day .cd-k { font-size: 11px; letter-spacing: -0.03em; }
  .cal-day .cd-k small { display: none; }
  .cal-h { padding: 4px; font-size: 11px; letter-spacing: 0.02em; }
  .sec-head .btn { margin-left: 0; }
  .run { grid-template-columns: 62px minmax(0, 1fr) auto; row-gap: 4px; }
  .run-s { grid-column: 2; }
  .run-c { grid-column: 3; grid-row: 1; }
  .run-a { grid-column: 2 / -1; }
  .bal { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .money th, .money td { padding-right: var(--s2); font-size: 13px; }
  .drawer { width: 100%; border-left: 0; padding: var(--s4); }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .drawer-f .btn { flex: 1 1 auto; }
  .drawer-f #day-use-range { margin-left: 0; flex-basis: 100%; }
}

/* ---------- Without JavaScript: the printed figures stay, the instruments go ---------- */
.no-js .chart, .no-js .hint, .no-js .legend, .no-js .range, .no-js #add-run, .no-js #edit-tariff, .no-js .run-a, .no-js .keys { display: none; }

/* Gallery badge (641-860px): give the tab bar a strip below the tabs so the badge never covers one */
@media (min-width: 641px) and (max-width: 860px) {
  .tabbar { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .main { padding-bottom: 140px; }
  .toast { bottom: 128px; }
}
