/* FireFly web — light marine-instrument theme to match the FireFly LVGL UI.
   White background, bold black numerics, blue accents. Optimised for iPhone
   portrait but the visual language matches the 800×480 landscape FireFly
   displays. */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Marine instrument palette — pulled from FireFly EEZ design */
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-card-alt: #f5f7fa;
  --border: #d8dde5;
  --border-strong: #1a2230;
  --fg: #0a0e14;
  --fg-dim: #5a6878;
  --fg-label: #1a2230;
  --accent: #3d6fb8;       /* FireFly blue (home icon, buttons, selected) */
  --accent-dark: #2d5a96;
  --accent-bg: #e3edf8;
  --good: #4caf50;         /* starboard green */
  --good-light: #a5d6a7;
  --port: #d04848;         /* port red */
  --port-light: #ef9a9a;
  --warn: #ffa726;
  --alarm: #e53935;
  --header-h: 52px;
  --tab-h: 64px;

  /* Marine display fonts: clean sans-serif, very heavy weights for numbers */
  --font-base: -apple-system, BlinkMacSystemFont, "SF Pro Display",
               "Helvetica Neue", "Segoe UI", Arial, sans-serif;
}

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-base);
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ─────────────────────────────────────────────────────── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 14px;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}
.app-header .home-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--accent);
  font-size: 28px;
  padding: 0 8px 0 0;
  display: flex; align-items: center;
}
.app-header .screen-title {
  font-size: 18px; font-weight: 600; color: var(--fg);
  margin-left: 4px;
}
.app-header .gear-btn {
  margin-left: auto;
  background: transparent; border: 0; cursor: pointer;
  color: var(--accent);
  font-size: 22px;
  padding: 0 4px;
}
.conn-status {
  margin-left: 8px;
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.conn-ok      { background: #e8f5e9; color: var(--good); }
.conn-stale   { background: #fff3e0; color: var(--warn); }
.conn-down    { background: #ffebee; color: var(--alarm); }
.conn-unknown { background: #eceff1; color: var(--fg-dim); }

/* ── Screen container ──────────────────────────────────────────── */
#screen-container {
  position: fixed;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  left: 0; right: 0;
  bottom: env(safe-area-inset-bottom);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  background: var(--bg);
}
/* Generous spacing between sections, mimicking the FireFly's airy layout */
.screen { display: flex; flex-direction: column; gap: 18px; }

/* ── Home tile grid ────────────────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.tile {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 14px;
  padding: 28px 14px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  transition: transform 0.1s ease, background 0.15s ease;
}
.tile:active { transform: scale(0.97); background: var(--accent-dark); }
.tile-revision {
  text-align: right;
  font-size: 12px;
  color: var(--fg-dim);
  padding-right: 4px;
  margin-top: 8px;
}

/* ── Metric blocks (the big numeric displays) ──────────────────── */
/* The FireFly numerics are EXTREMELY heavy — closer to weight 900.
   Labels are noticeably lighter weight (400-500) and smaller. */
.metric-label {
  font-size: 22px;
  font-weight: 400;
  color: var(--fg);
  text-align: center;
  margin-bottom: 2px;
  line-height: 1.1;
}
.metric-value {
  /* Responsive: scales with viewport width but caps at a max.
     This prevents 4-char strings (e.g. "0000", "-0.0") from
     overflowing their column on narrow phones. */
  font-size: clamp(36px, 16vw, 80px);
  font-weight: 900;
  color: var(--fg);
  text-align: center;
  line-height: 1;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
}
/* xl = full-width dominant metric. clamp keeps it readable on phones. */
.metric-value.xl { font-size: clamp(56px, 22vw, 120px); }
/* lg = paired column big number. Must fit in ~165px on iPhone SE. */
.metric-value.lg { font-size: clamp(42px, 15vw, 90px); }
.metric-value.md { font-size: clamp(28px, 10vw, 56px); }
.metric-value.sm { font-size: clamp(20px,  7vw, 40px); }
.metric-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-dim);
  margin-top: 2px;
  text-align: center;
}

/* Two-column metric layout (Sustained Wind | Gusts, Port | Stbd, etc.) */
.metric-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  align-items: start;
  margin-bottom: 8px;
}

/* ── Wind angle arc widget ──────────────────────────────────────── */
.wind-arc {
  position: relative;
  width: 160px;
  height: 200px;
  margin: 0 auto;
}
.wind-arc svg { width: 100%; height: 100%; }
.wind-arc-port  { stroke: var(--port-light); stroke-width: 12; fill: none; }
.wind-arc-stbd  { stroke: var(--good-light); stroke-width: 12; fill: none; }
.wind-arc-indicator {
  stroke: var(--border-strong);
  stroke-width: 4;
  fill: white;
}
.wind-arc-label {
  text-align: center;
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 8px;
}

/* ── Round semi-circle gauge (engine coolant, oil pressure) ─── */
.gauge-round {
  width: 100%;
  max-width: 160px;
  margin: 0 auto;
}
.gauge-round svg { width: 100%; height: auto; display: block; }
.gauge-round-bg     { fill: none; stroke: #d8dde5; stroke-width: 10; }
.gauge-round-danger { fill: none; stroke: #d04848; stroke-width: 10; }
.gauge-round-needle { stroke: #1a2230; stroke-width: 2.5; stroke-linecap: round; }
.gauge-round-hub    { fill: #1a2230; }
.gauge-round-tick   { stroke: #1a2230; stroke-width: 1.5; }
.gauge-round-label  { font-size: 14px; font-weight: 500; fill: #1a2230;
                      text-anchor: middle; font-family: var(--font-base); }
.gauge-round-value  { font-size: 22px; font-weight: 700; fill: #0a0e14;
                      text-anchor: middle; font-family: var(--font-base);
                      font-variant-numeric: tabular-nums; }

/* ── Vertical fill bar (engine Load, Boost) ──────────────────── */
.vbar {
  display: flex; flex-direction: column; align-items: center;
}
.vbar-label { font-size: 13px; color: var(--fg); margin-bottom: 4px; }
.vbar-body {
  width: 28px; height: 120px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: white;
  position: relative;
  overflow: hidden;
}
.vbar-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #1a2230;
  transition: height 0.3s ease;
}
.vbar-pct { font-size: 12px; color: var(--fg-dim); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ── Engine instrument cluster (Coolant | Oil | Boost) ────── */
.instrument-cluster {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

/* ── Power source mini-card (Shore/Gen/Solar) ────────────── */
.power-source {
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  background: white;
}
.power-source .label { font-size: 14px; font-weight: 600; color: var(--fg); margin-bottom: 2px; }
.power-source .value { font-size: 28px; font-weight: 800; color: var(--fg); line-height: 1;
                       font-variant-numeric: tabular-nums; }
.power-source .unit  { font-size: 11px; color: var(--fg-dim); margin-top: 1px; font-weight: 600; }
.power-source .meta  { font-size: 10px; color: var(--fg-dim); margin-top: 4px;
                       font-variant-numeric: tabular-nums; }

.power-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.power-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Inverter/Charger mode pills */
.mode-pills {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.mode-pill {
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: white;
}
.mode-pill.active {
  background: var(--accent);
  color: white;
}

/* ── Toggle (Knots/MPH) ──────────────────────────────────── */
.toggle-2 {
  display: inline-flex;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
}
.toggle-2 .opt {
  padding: 6px 12px;
  cursor: pointer;
  color: var(--accent);
  background: white;
}
.toggle-2 .opt.active {
  background: var(--accent);
  color: white;
}

/* ── Tank bar gauges ───────────────────────────────────────────── */
.tank-bar {
  position: relative;
  width: 64px;
  height: 200px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-bg);
  overflow: hidden;
}
.tank-bar-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--accent);
  transition: height 0.3s ease;
}
.tank-label-top { text-align: center; font-size: 18px; font-weight: 500; margin-bottom: 8px; }
.tank-label-pct { text-align: center; font-size: 22px; font-weight: 700; margin-top: 8px; }

/* ── Chart box (SVG line charts render inside) ────────────────── */
.chart-box {
  border: 0;
  background: transparent;
  min-height: 160px;
  position: relative;
  padding: 0;
  font-size: 11px;
  color: var(--fg-dim);
  overflow: hidden;
}
.chart-y-tick {
  font-size: 11px;
  fill: var(--fg-dim);
  font-family: var(--font-base);
  font-weight: 500;
  dominant-baseline: middle;
}
.chart-y-label {
  position: absolute;
  left: -38px;
  font-size: 12px;
  color: var(--fg-dim);
  font-weight: 500;
}

/* ── Key/value rows ─────────────────────────────────────────────── */
.kv-list { display: flex; flex-direction: column; }
.kv { display: flex; justify-content: space-between;
      padding: 8px 0;
      border-bottom: 1px solid var(--border);
      font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--fg-dim); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 500; }

/* ── Card defaults — minimal, matches FireFly's chrome-free style ─ */
/* On FireFly screens (Engines/Wind/Anchoring/Motoring/Tanks) there are
   NO card borders or backgrounds. Elements just float on white. Reserve
   the `.card-framed` class for the few places where the FireFly does
   draw an explicit border (Victron sub-boxes, the chart frames). */
.card {
  background: transparent;
  border: 0;
  padding: 8px 0;
}
.card-framed {
  background: white;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 12px 10px;
}
.card h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  text-align: center;
  margin-bottom: 8px;
}

/* ── Section title (like "Fresh Water Tanks" big top label) ───── */
.section-title {
  font-size: 26px;
  font-weight: 600;
  color: var(--fg);
  text-align: center;
  margin-bottom: 16px;
}

/* ── Empty/loading states ──────────────────────────────────────── */
.placeholder {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg-dim);
  font-size: 14px;
}
.placeholder-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
  color: var(--accent);
}
