:root {
  --bg: #0a0e17;
  --bar: #111827;
  --card: #162032;
  --border: #293548;
  --pill: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --cyan: #38bdf8;
  --blue-night: #38bdf8;
  --green: #22c55e;
  --green-dk: #14532d;
  --gold: #facc15;
  --orange: #fb923c;
  --coral: #fb7185;
  --red: #f87171;
  --red-dk: #450a0a;
  --blue-bar: #5588ff;
}

* { box-sizing: border-box; user-select: none; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }
.cyan { color: var(--cyan); }
.gold { color: var(--gold); }
.orange { color: var(--orange); }
.coral { color: var(--coral); }
.green { color: var(--green); }
.red { color: var(--red); }
.muted { color: var(--muted); }

.app-shell {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(6px, 1vw, 12px);
  gap: clamp(6px, 1vw, 12px);
}

/* Top Bar */
.topbar {
  background: var(--bar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 14px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}

.brand {
  font-size: clamp(1rem, 1.6vw, 1.35rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--cyan);
}

.ver-badge {
  background: var(--pill);
  border: 1px solid var(--border);
  color: var(--cyan);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 700;
}
.conn-pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}
.conn-live { color: var(--green); }
.conn-warn { color: var(--gold); }
.conn-err  { color: var(--red); }

.top-meta {
  color: var(--muted);
  font-size: clamp(0.8rem, 1.1vw, 0.98rem);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pill-btn {
  background: var(--pill);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pill-btn:hover { background: #293548; }
.pill-gold { color: var(--gold); }
.pill-cyan { color: var(--cyan); border-color: var(--cyan); }
.pill-green { background: var(--green-dk); color: var(--green); border-color: var(--green); }
.pill-green:hover { background: #166534; }
.pill-red { background: var(--red-dk); color: var(--coral); border-color: var(--coral); }

.topbar-full {
  position: relative;
}
.full-title {
  font-size: clamp(0.95rem, 1.4vw, 1.2rem);
  font-weight: 800;
  color: var(--cyan);
}
.full-center-dt {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(0.95rem, 1.4vw, 1.2rem);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}

/* 4-Panel Grid */
.grid-4 {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: clamp(8px, 1.1vw, 14px);
}

.card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: clamp(10px, 1.3vw, 18px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: #3b4f6e; }

.card-hdr {
  font-size: clamp(0.78rem, 1.05vw, 0.96rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--cyan);
  margin-bottom: clamp(6px, 0.8vw, 10px);
  flex-shrink: 0;
}

.h-rule { height: 1px; background: var(--border); margin: 8px 0; flex-shrink: 0; }
.h-rule.tight { margin: 5px 0; }
.v-rule { width: 1px; background: var(--border); align-self: stretch; flex-shrink: 0; }

/* Clock Card */
.clock-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.8vh, 10px);
}
.clock-time-wrap { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.clock-time {
  font-size: clamp(2.6rem, 6.2vw, 5.2rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clock-time.night { color: var(--blue-night); }
.clock-ampm { font-size: clamp(1.2rem, 2.3vw, 2.1rem); font-weight: 800; color: var(--cyan); }
.clock-day  { font-size: clamp(1.3rem, 2.5vw, 2.3rem); font-weight: 800; color: var(--green); }
.clock-date { font-size: clamp(1rem, 1.8vw, 1.55rem); font-weight: 700; color: var(--coral); }
.clock-sun  { font-size: clamp(0.82rem, 1.25vw, 1.08rem); color: var(--muted); }

/* Weather Card */
.wx-top { display: flex; align-items: center; gap: clamp(10px, 1.4vw, 18px); flex: 1; min-height: 0; }
.wx-icon-box { width: clamp(54px, 6.5vw, 84px); height: clamp(54px, 6.5vw, 84px); flex-shrink: 0; }
.wx-now { flex: 1; min-width: 0; }
.wx-temp-line { display: flex; align-items: baseline; gap: 14px; }
.wx-temp { font-size: clamp(2rem, 4.4vw, 3.8rem); font-weight: 800; line-height: 1; }
.wx-hum { font-size: clamp(1.25rem, 2.4vw, 2.1rem); font-weight: 800; }
.wx-cond { font-size: clamp(0.9rem, 1.35vw, 1.2rem); color: var(--text); margin-top: 4px; }
.wx-sub  { font-size: clamp(0.8rem, 1.15vw, 1rem); color: var(--muted); margin-top: 2px; }

.fc-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 2px;
}
.fc-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  padding: 2px 6px;
}
.fc-mini:last-child { border-right: none; }
.fc-day { font-size: clamp(0.82rem, 1.15vw, 1rem); font-weight: 700; margin-bottom: 4px; }
.fc-mini-row { display: flex; align-items: center; gap: 8px; }
.fc-mini-icon { width: clamp(26px, 2.8vw, 38px); height: clamp(26px, 2.8vw, 38px); }
.fc-temps { display: flex; flex-direction: column; font-size: clamp(0.82rem, 1.1vw, 0.98rem); font-weight: 700; }

/* Solar Card */
.solar-split {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: clamp(10px, 1.3vw, 18px);
}
.solar-left {
  flex: 1.55;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.solar-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  text-align: center;
}
.mini-hdr { font-size: clamp(0.75rem, 1vw, 0.92rem); font-weight: 800; text-align: center; letter-spacing: 0.03em; }
.mini-lbl { font-size: clamp(0.72rem, 0.95vw, 0.88rem); font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }
.mini-sub { font-size: clamp(0.72rem, 0.95vw, 0.86rem); color: var(--muted); }
.big-watts { font-size: clamp(1.35rem, 2.7vw, 2.35rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.giant-watts { font-size: clamp(1.9rem, 4vw, 3.4rem); font-weight: 800; font-variant-numeric: tabular-nums; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-lbl { width: 48px; font-size: clamp(0.75rem, 1vw, 0.92rem); font-weight: 700; color: var(--muted); flex-shrink: 0; }
.bar-val { width: 92px; text-align: right; font-size: clamp(0.74rem, 1vw, 0.92rem); font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.solar-left.full .bar-lbl { width: 64px; font-size: clamp(0.85rem, 1.15vw, 1.05rem); }
.solar-left.full .bar-val { width: 128px; font-size: clamp(0.85rem, 1.15vw, 1.05rem); }

.bal-track {
  position: relative;
  flex: 1;
  height: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: visible;
}
.bal-track.tall { height: 18px; }
.bal-fill {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 3px;
}
.bal-center {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: #ffffff;
  transform: translateX(-50%);
}

.day-net {
  font-size: clamp(0.84rem, 1.15vw, 1.04rem);
  font-weight: 800;
  text-align: center;
}
.day-net.full { font-size: clamp(1.02rem, 1.5vw, 1.38rem); margin-bottom: 4px; }

.pace-rows { display: flex; flex-direction: column; gap: clamp(5px, 0.8vh, 10px); }
.pace-rows.full { gap: clamp(8px, 1.3vh, 14px); }
.pace-row { display: flex; align-items: center; gap: 8px; }
.pace-track {
  position: relative;
  flex: 1;
  height: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.solar-left.full .pace-track { height: 18px; }
.pace-dim {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  border-radius: 3px;
}
.pace-hatch {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 0 3px 3px 0;
  pointer-events: none;
}
.pace-bright {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  border-radius: 3px;
}
.pace-tick {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: #ffffff;
  transform: translateX(-50%);
}
.pace-legend {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}

.solar-footer {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  font-size: clamp(0.8rem, 1.05vw, 0.96rem);
  font-weight: 700;
}

.empty-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  font-size: 1rem;
}

/* Carport Card */
.cp-top { display: flex; justify-content: space-between; align-items: flex-start; }
.cp-soc { font-size: clamp(2rem, 4.3vw, 3.8rem); font-weight: 800; line-height: 1; }
.cp-mppt-right { text-align: right; }
.cp-state { font-size: clamp(1rem, 1.7vw, 1.45rem); font-weight: 800; color: var(--gold); }
.cp-pv    { font-size: clamp(0.8rem, 1.1vw, 0.98rem); font-weight: 700; color: var(--orange); margin-top: 4px; }
.soc-track {
  height: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  margin: 6px 0;
}
.soc-fill { height: 100%; border-radius: 4px; width: 0%; transition: width 0.3s ease; }
.cp-grid { flex: 1; display: flex; align-items: center; gap: 14px; min-height: 0; }
.cp-col { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.cp-line { font-size: clamp(0.84rem, 1.25vw, 1.1rem); font-weight: 700; }
.cp-sub  { font-size: clamp(0.78rem, 1.05vw, 0.95rem); color: var(--muted); }

/* Full-Screen Views */
.full-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.2vw, 16px);
}
.full-black { background: #000000; border-radius: 14px; padding: 14px; }
.card-blk { background: #000000; border-color: var(--border); flex: 1; }

.giant-clock-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.giant-time-row { display: flex; align-items: baseline; gap: 20px; }
.giant-time { font-size: clamp(4rem, 13vw, 11rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.giant-time.night { color: var(--blue-night); }
.giant-ampm { font-size: clamp(2rem, 4.5vw, 4rem); font-weight: 800; color: var(--cyan); }
.giant-date { font-size: clamp(1.6rem, 3.6vw, 3.1rem); font-weight: 800; color: var(--green); }
.giant-summary { text-align: center; gap: 6px; }
.giant-sum-top { display: flex; justify-content: space-around; font-size: clamp(1rem, 1.7vw, 1.5rem); font-weight: 800; }
.giant-sum-sub { font-size: clamp(0.88rem, 1.2vw, 1.05rem); color: var(--muted); }

.cp-full-soc-wrap { text-align: center; padding: 6px 0; }
.cp-full-soc { font-size: clamp(3.5rem, 9.5vw, 7.5rem); font-weight: 800; line-height: 1; }
.cp-full-cards { flex: 1; display: flex; gap: clamp(10px, 1.5vw, 18px); min-height: 0; }
.cp-full-big { font-size: clamp(1.6rem, 3vw, 2.6rem); font-weight: 800; text-align: center; margin: 6px 0; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; flex: 1; align-items: center; }
.kv-val { font-size: clamp(1.1rem, 2vw, 1.7rem); font-weight: 800; margin-top: 3px; }
.cells-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.cell-v { font-size: clamp(0.88rem, 1.3vw, 1.15rem); font-weight: 700; margin-top: 2px; }

.wx-full-top { flex-direction: row; align-items: center; gap: 24px; flex: 1; }
.wx-full-hero { flex: 1.2; display: flex; align-items: center; gap: 20px; }
.wx-full-icon { width: clamp(80px, 9vw, 130px); height: clamp(80px, 9vw, 130px); flex-shrink: 0; }
.wx-full-temp { font-size: clamp(3rem, 7vw, 5.8rem); font-weight: 800; line-height: 1; }
.wx-full-cond { font-size: clamp(1.1rem, 2vw, 1.7rem); color: var(--cyan); margin-top: 6px; font-weight: 700; }
.wx-full-metrics { flex: 1; }
.fc-full-cards { flex: 1.15; display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 1.4vw, 18px); min-height: 0; }
.fc-full-card { align-items: center; justify-content: space-evenly; text-align: center; }
.fc-full-day { font-size: clamp(1.2rem, 2vw, 1.7rem); font-weight: 800; color: var(--cyan); }
.fc-full-icon { width: clamp(54px, 6vw, 86px); height: clamp(54px, 6vw, 86px); }
.fc-full-hi { font-size: clamp(1.6rem, 3vw, 2.5rem); font-weight: 800; color: var(--gold); }
.fc-full-lo { font-size: clamp(1.05rem, 1.7vw, 1.45rem); font-weight: 700; color: var(--cyan); }

.solar-full-top { flex: 1.35; flex-direction: row; align-items: stretch; gap: 22px; }
.solar-full-cards { flex: 0.9; display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 1.4vw, 18px); min-height: 0; }
.kwh-card { align-items: center; justify-content: space-evenly; text-align: center; }
.kwh-big { font-size: clamp(1.8rem, 3.8vw, 3.2rem); font-weight: 800; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  border: 2px solid var(--cyan);
  border-radius: 14px;
  padding: 20px 22px;
  width: 100%;
  max-width: 500px;
}
.modal-title { font-size: 1.15rem; font-weight: 800; color: var(--cyan); margin-bottom: 8px; }
.modal-note { font-size: 0.82rem; color: var(--muted); margin: 6px 0 12px; }
.modal-card label { display: block; font-size: 0.82rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.modal-card input, .modal-card select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.form-row-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }
.badge-saved { color: var(--green); font-weight: 700; margin-left: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.upd-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.upd-row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); padding: 5px 0; font-size: 0.92rem; }
.upd-row span { color: var(--muted); }

/* Brightness Overlay */
#dim-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.25s ease;
}
