/*
 * Solar — parent-friendly PV dashboard. Phone first (iPhone + Android), no build step.
 * Chart colors follow the validated reference palette (dataviz skill): production is the
 * orange slot, last year the blue slot; both pass CVD/contrast checks on these surfaces.
 */

:root {
  color-scheme: light;
  --page: #f6f4ee;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.08);
  --sun: #eb6834;            /* production series */
  --sun-wash: rgba(235, 104, 52, 0.12);
  --blue: #2a78d6;           /* comparison series (last year) */
  --accent: #c2481a;         /* buttons: white text clears 4.5:1 */
  --accent-ink: #ffffff;
  --good: #006300;
  --good-dot: #0ca30c;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 18px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.08);
    --sun: #d95926;
    --sun-wash: rgba(217, 89, 38, 0.18);
    --blue: #3987e5;
    --accent: #d95926;
    --accent-ink: #ffffff;
    --good: #0ca30c;
    --good-dot: #0ca30c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

h1 { font-size: 1.6rem; margin: 4px 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
p { margin: 0; }

.subtitle { color: var(--ink-2); font-size: 0.92rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

/* ---------- hero: current output ---------- */

.hero-label { color: var(--ink-2); font-size: 0.95rem; }
.hero-value {
  font-size: 3.4rem;
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
}
.hero-value .unit { font-size: 1.4rem; font-weight: 500; color: var(--ink-2); margin-left: 4px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: var(--page);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--ink-2);
}
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--axis); }
.pill.live .dot { background: var(--good-dot); box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18); }

.big-number { font-size: 2rem; font-weight: 650; letter-spacing: -0.01em; line-height: 1.1; }
.big-number .unit { font-size: 1rem; font-weight: 500; color: var(--ink-2); margin-left: 3px; }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.tile-icon { display: block; width: 26px; height: 26px; margin-bottom: 8px; color: var(--accent); }
.tile-icon svg { width: 100%; height: 100%; }
.tile-label { color: var(--ink-2); font-size: 0.85rem; }
.tile-value { font-size: 1.45rem; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.tile-value .unit { font-size: 0.9rem; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile-detail { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

/* ---------- list rows ---------- */

.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}
.rows li:first-child { border-top: 0; padding-top: 2px; }
.rows .label { color: var(--ink-2); }
.rows .value { font-weight: 600; text-align: right; white-space: nowrap; }
.rows .value small { font-weight: 400; color: var(--muted); }

.note {
  background: var(--sun-wash);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

/* ---------- segmented control ---------- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 14px;
}
.segmented button {
  font: inherit;
  font-size: 0.95rem;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 9px 6px;
  border-radius: 9px;
  cursor: pointer;
}
.segmented button[aria-selected="true"] {
  background: var(--page);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}

/* ---------- charts ---------- */

.chart { position: relative; margin: 6px 0 2px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.value-label { fill: var(--ink-2); font-size: 11.5px; font-weight: 600; }
.chart .area { fill: var(--sun-wash); }
.chart .line { fill: none; stroke: var(--sun); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s-blue { stroke: var(--blue); }
.chart .bar { fill: var(--sun); transition: opacity 0.15s; }
.chart .bars.has-selection .bar { opacity: 0.45; }
.chart .bars.has-selection .bar.selected { opacity: 1; }
.chart .bar.hover { opacity: 0.8; }
.chart .marker { fill: var(--sun); stroke: var(--surface); stroke-width: 2; }
.chart .marker.s-blue { fill: var(--blue); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }

.tooltip {
  position: absolute;
  top: 2px;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.82rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 2;
}
.tooltip.show { opacity: 1; }
.tooltip .t-title { color: var(--muted); font-size: 0.78rem; }
.tooltip .t-row { display: flex; align-items: center; gap: 7px; }
.tooltip .t-row strong { font-size: 0.95rem; }
.tooltip .key { width: 12px; height: 2px; border-radius: 1px; background: var(--sun); }
.tooltip .key.s-blue { background: var(--blue); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); margin: 2px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .key { width: 14px; height: 2px; border-radius: 1px; background: var(--sun); }
.legend .key.s-blue { background: var(--blue); }

details.table-view { margin-top: 10px; font-size: 0.9rem; }
details.table-view summary { color: var(--ink-2); cursor: pointer; padding: 4px 0; }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: right; padding: 6px 4px; border-top: 1px solid var(--grid); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view th { color: var(--muted); font-weight: 500; }

.empty-chart { color: var(--muted); font-size: 0.9rem; padding: 24px 0; text-align: center; }

/* ---------- buttons & forms ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 15px 18px;
  border-radius: 14px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.secondary { background: var(--page); color: var(--ink); border: 1px solid var(--border); }
.btn + .btn { margin-top: 10px; }
.btn svg { width: 20px; height: 20px; flex: none; }

label.field { display: block; margin-bottom: 14px; font-size: 0.92rem; color: var(--ink-2); }
label.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 16px;                 /* below 16px iOS zooms into the field */
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--axis);
  border-radius: 12px;
  padding: 13px 14px;
}
label.field input:focus { outline: 2px solid var(--sun); outline-offset: 1px; border-color: transparent; }
.form-error { color: #d03b3b; min-height: 1.3em; font-size: 0.9rem; margin-top: 10px; }

/* ---------- status banner ---------- */

.banner {
  display: none;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-2);
}
.banner.show { display: block; }

/* ---------- tabs ---------- */

.view { display: none; }
.view.active { display: block; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar nav { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 560px; height: var(--tabbar-h); }
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding-bottom: 10vh; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; }

@media (min-width: 600px) {
  .hero-value { font-size: 4rem; }
}

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