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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --night: #6366f1;
  --offpeak: #3b82f6;
  --peak: #f59e0b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

#app {
  width: 100%;
  max-width: 480px;
  padding: 0 1rem;
}

/* ── Header ─────────────────────────────────────────────── */
header, .app-header {
  text-align: center;
  padding: 1.2rem 0 0.5rem;
}
header h1, .app-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.bolt { font-size: 1.5rem; }
.subtitle { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem;
  margin-top: 0.75rem;
}
.card h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

/* ── Hero cost card ─────────────────────────────────────── */
.cost-hero { text-align: center; }
.hero-date { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }
.hero-row { display: flex; justify-content: center; gap: 2rem; margin: 0.5rem 0; }
.hero-stat { text-align: center; }
.hero-value { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.hero-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

.summary-compare { font-size: 0.9rem; color: var(--muted); margin-top: 0.4rem; text-align: center; }
.summary-compare .up { color: var(--red); font-weight: 600; }
.summary-compare .down { color: var(--green); font-weight: 600; }
.summary-compare .flat { color: var(--yellow); font-weight: 600; }
.data-lag { font-size: 0.75rem; opacity: 0.6; }

/* ── Bill card ──────────────────────────────────────────── */
.bill-row { display: flex; justify-content: space-between; padding: 0.35rem 0; font-size: 0.9rem; color: var(--muted); }
.bill-value { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.bill-predicted { color: var(--primary); }
.bill-row.muted { font-size: 0.8rem; opacity: 0.6; }

/* ── Breakdown rows ─────────────────────────────────────── */
.breakdown { margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.35rem; }
.breakdown-row { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.breakdown-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.breakdown-dot.night { background: var(--night); }
.breakdown-dot.offpeak { background: var(--offpeak); }
.breakdown-dot.peak { background: var(--peak); }
.breakdown-label { flex: 1; color: var(--muted); }
.breakdown-value { font-weight: 600; font-size: 0.85rem; }

/* ── Chart ──────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; width: 100%; }
.chart-controls { display: flex; justify-content: space-between; gap: 0.4rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.chart-toggle { display: flex; gap: 0.15rem; }
.toggle-btn {
  padding: 0.25rem 0.5rem; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--muted); font-size: 0.7rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.toggle-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Stats grid ─────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.stat { background: var(--bg); border-radius: 8px; padding: 0.65rem; text-align: center; }
.stat-value { font-size: 1.15rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 0.1rem; }

/* ── Heatmap ────────────────────────────────────────────── */
.heatmap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap { display: grid; gap: 2px; min-width: 600px; }
.heatmap-header { font-size: 0.6rem; color: var(--muted); text-align: center; padding: 2px 0; }
.heatmap-label { font-size: 0.6rem; color: var(--muted); display: flex; align-items: center; white-space: nowrap; padding-right: 4px; }
.heatmap-cell {
  border-radius: 2px; min-height: 14px; cursor: default;
  transition: opacity 0.15s;
}
.heatmap-cell:hover { opacity: 0.8; }
.heat-0 { background: #1e293b; }
.heat-1 { background: #1e3a5f; }
.heat-2 { background: #1d4ed8; }
.heat-3 { background: #3b82f6; }
.heat-4 { background: #f59e0b; }
.heat-5 { background: #ef4444; }

/* ── Patterns ───────────────────────────────────────────── */
.pattern-bars { margin-bottom: 0.75rem; }
.pattern-bar-group { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; font-size: 0.8rem; }
.pattern-label { width: 80px; color: var(--muted); flex-shrink: 0; }
.pattern-bar-track { flex: 1; height: 18px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.pattern-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.4s ease; }
.pattern-bar.weekend { background: var(--peak); }
.pattern-val { width: 55px; text-align: right; font-weight: 600; font-size: 0.8rem; }

.pattern-stats { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pattern-stat {
  flex: 1; min-width: 100px; background: var(--bg); border-radius: 8px; padding: 0.5rem 0.6rem;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.pattern-stat-label { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; }
.pattern-stat-value { font-size: 0.95rem; font-weight: 700; }

/* ── Tips & Anomalies ───────────────────────────────────── */
.tip-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; color: var(--muted); line-height: 1.4; }
.tip-item:last-child { border-bottom: none; }
.anomaly-item { display: flex; justify-content: space-between; padding: 0.35rem 0; font-size: 0.8rem; color: var(--red); }

/* ── Settings ───────────────────────────────────────────── */
.rate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.75rem; }
.rate-item label { display: block; font-size: 0.7rem; color: var(--muted); margin-bottom: 0.15rem; }
.rate-item input {
  width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 0.85rem; text-align: right;
}
.rate-item input:focus { outline: none; border-color: var(--primary); }

.form-select {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 0.9rem; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.6rem center;
}

.account-info { margin-bottom: 0.5rem; }
.account-row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.85rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 0.9rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.form-group input {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 0.95rem;
}
.form-group input:focus { outline: none; border-color: var(--primary); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  width: 100%; padding: 0.6rem; border: none; border-radius: 8px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; transition: background 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { width: auto; padding: 0.4rem 0.9rem; font-size: 0.8rem; }

.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.85rem; }
.muted-text { color: var(--muted); font-size: 0.85rem; }
.help-text { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.6rem; }

.actions { display: flex; gap: 0.5rem; }
.actions .btn { flex: 1; }

.error { color: var(--red); font-size: 0.8rem; margin-top: 0.4rem; }
.success { color: var(--green); font-size: 0.8rem; margin-top: 0.4rem; }

.install-text { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; text-align: center; }
#install-banner { text-align: center; border-color: var(--primary); border-style: dashed; }

/* ── Tab bar ────────────────────────────────────────────── */
#tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding: 0.4rem 0 calc(0.4rem + env(safe-area-inset-bottom, 0px));
  z-index: 100;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.6rem; padding: 0.25rem 0; transition: color 0.15s;
}
.tab svg { width: 20px; height: 20px; }
.tab.active { color: var(--primary); }

/* Page container needs bottom padding for tab bar */
.page { padding-bottom: 70px; }

/* ── Utilities ──────────────────────────────────────────── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 0.3rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
