:root {
  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #1c2340;
  --text: #f5f7fb;
  --text-dim: #9aa3bd;
  --green-deep: #10b981;
  --green: #84cc16;
  --amber: #f59e0b;
  --red: #ef4444;
  --border: rgba(255,255,255,0.08);
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,0.3);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bot) + 24px);
  min-height: 100vh;
}

/* HERO ------------------------------------------------- */
.hero {
  border-radius: var(--radius);
  padding: 28px 20px 32px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  background: linear-gradient(160deg, #1c2340 0%, #141a2e 100%);
  transition: background 0.6s ease;
  overflow: hidden;
  position: relative;
}
.hero.h-super { background: linear-gradient(160deg, #065f46 0%, #10b981 100%); }
.hero.h-green { background: linear-gradient(160deg, #365314 0%, #84cc16 100%); }
.hero.h-amber { background: linear-gradient(160deg, #78350f 0%, #f59e0b 100%); }
.hero.h-red   { background: linear-gradient(160deg, #7f1d1d 0%, #ef4444 100%); }
.hero.h-night { background: linear-gradient(160deg, #1e1b4b 0%, #312e81 100%); }

.hero-inner {
  text-align: center;
  position: relative;
  z-index: 1;
}

.now-emoji {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
}

.now-label {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.now-sub {
  font-size: 17px;
  opacity: 0.92;
  font-weight: 500;
}

/* SECTIONS --------------------------------------------- */
.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 4px 12px;
}

.advice {
  margin-bottom: 24px;
}

.appliances {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.appliance {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 8px 14px;
  text-align: center;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.15s ease;
}

.appliance .icon {
  font-size: 36px;
  line-height: 1;
  margin-bottom: 8px;
}

.appliance .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.appliance .status {
  font-size: 14px;
  font-weight: 800;
  padding: 7px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.appliance.s-super { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.4); }
.appliance.s-super .status { background: var(--green-deep); color: #042f21; }
.appliance.s-green { background: rgba(132,204,22,0.12); border-color: rgba(132,204,22,0.4); }
.appliance.s-green .status { background: var(--green); color: #1a2e05; }
.appliance.s-amber { background: rgba(245,158,11,0.1);  border-color: rgba(245,158,11,0.35); }
.appliance.s-amber .status { background: var(--amber); color: #3b1f02; }
.appliance.s-red   { background: rgba(239,68,68,0.1);   border-color: rgba(239,68,68,0.35); }
.appliance.s-red   .status { background: var(--red); color: #fff; }

.combo-tip {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
}
.combo-tip.warn { border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.08); }
.combo-tip.good { border-color: rgba(16,185,129,0.4); background: rgba(16,185,129,0.08); }

/* TIMELINE --------------------------------------------- */
.timeline-section, .tomorrow {
  margin-bottom: 24px;
}

.timeline {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 8px 10px;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  position: relative;
  overflow: hidden;
}

.hour {
  aspect-ratio: 1 / 2.4;
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
  font-size: 9px;
  font-weight: 700;
  color: rgba(0,0,0,0.55);
  min-height: 56px;
  overflow: hidden;
}

.hour.now {
  outline: 2px solid #fff;
  outline-offset: 1px;
  z-index: 2;
}

.hour .hourlbl {
  position: absolute;
  top: 4px;
  left: 0; right: 0;
  font-size: 10px;
  font-weight: 700;
  color: rgba(0,0,0,0.72);
  text-align: center;
  text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}

.hour.past { opacity: 0.35; }

.hour.cat-super  { background: var(--green-deep); }
.hour.cat-green  { background: var(--green); }
.hour.cat-amber  { background: var(--amber); }
.hour.cat-red    { background: var(--red); }
.hour.cat-night  { background: #2a3154; color: rgba(255,255,255,0.4); }
.hour.cat-night .hourlbl { color: rgba(255,255,255,0.35); }

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-top: 10px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i {
  display: inline-block;
  width: 10px; height: 10px; border-radius: 3px;
}

/* BEST WINDOWS ----------------------------------------- */
.windows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.window-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.window-row .dot {
  width: 14px; height: 14px; border-radius: 50%;
  flex-shrink: 0;
}
.window-row .dot.super { background: var(--green-deep); }
.window-row .dot.green { background: var(--green); }
.window-row .dot.amber { background: var(--amber); }
.window-row .title { font-weight: 700; font-size: 16px; }
.window-row .time { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.window-row .meta { margin-left: auto; font-size: 13px; color: var(--text-dim); text-align: right; }

/* FOOT ------------------------------------------------- */
.foot {
  margin-top: 28px;
  padding: 18px 0 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.refresh {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.refresh:active { transform: scale(0.97); }

.foot-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.settings:active { transform: scale(0.95); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
}
.badge-solcast {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.badge-knmi {
  background: rgba(245, 158, 11, 0.10);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fbbf24;
}

.foot .meta { font-size: 11px; opacity: 0.7; }

/* MODAL ----------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 16, 32, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 16px;
  overflow-y: auto;
}
.modal[hidden] { display: none; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.5);
  color: var(--text);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.modal-close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 10px;
  line-height: 1;
  border-radius: 8px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 18px 20px 22px;
}

.setting-group {
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.setting-group:last-of-type { border-bottom: 0; }
.setting-group h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.setting-group .hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 12px;
  line-height: 1.5;
}
.setting-group .hint a { color: #60a5fa; text-decoration: underline; }
.setting-group label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  font-weight: 500;
}
.setting-group input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  box-sizing: border-box;
}
.setting-group input[type="text"]:focus {
  outline: none;
  border-color: #60a5fa;
}

.setting-status {
  margin-top: 10px;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
}
.setting-status.muted { background: var(--surface-2); color: var(--text-dim); }
.setting-status.ok { background: rgba(16, 185, 129, 0.10); color: #34d399; }
.setting-status.warn { background: rgba(245, 158, 11, 0.10); color: #fbbf24; }

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.setting-row .setting-status { margin-top: 0; flex: 1; min-width: 160px; }
.setting-row .secondary {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.setting-row .secondary:hover { background: rgba(255,255,255,0.06); }

.setting-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.setting-actions button {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--border);
  flex: 1;
  min-width: 130px;
}
.setting-actions .primary {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}
.setting-actions .primary:active { transform: scale(0.98); }
.setting-actions .danger-light {
  background: var(--surface-2);
  color: #fca5a5;
}

/* Loading state */
.loading .now-label::after {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .now-emoji { font-size: 60px; }
  .now-label { font-size: 26px; }
  .appliance .icon { font-size: 32px; }
}

/* LIVE P1 --------------------------------------------------- */
.live-p1 {
  margin-bottom: 16px;
  border-radius: var(--radius);
  padding: 14px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: background 0.4s ease, border-color 0.4s ease;
}
.live-p1.export  { background: linear-gradient(160deg, #064e3b 0%, #141a2e 110%); border-color: rgba(16,185,129,0.35); }
.live-p1.import  { background: linear-gradient(160deg, #7f1d1d 0%, #141a2e 110%); border-color: rgba(239,68,68,0.35); }
.live-p1.ok      { background: linear-gradient(160deg, #1c2340 0%, #141a2e 100%); }
.live-p1.offline { opacity: 0.55; }

.p1-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}
.p1-cell { text-align: center; }
.p1-lbl {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.p1-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

/* APPLIANCE EUR-NU --------------------------------------------------- */
.appliance .eur-now {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-height: 14px;
}
.appliance.s-super .eur-now { color: rgba(255,255,255,0.85); }
.appliance.s-green .eur-now { color: rgba(255,255,255,0.85); }
.appliance.s-red   .eur-now { color: rgba(255,255,255,0.75); }

/* BEST PER APPLIANCE ------------------------------------------------- */
.best-per-app { margin-top: 28px; }
.best-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.app-best {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.app-best-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.app-best-icon { font-size: 20px; }
.app-best-name { font-weight: 700; font-size: 15px; }
.app-best-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
}
.app-best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
  border-top: 1px dashed rgba(255,255,255,0.06);
}
.app-best-row:first-of-type { border-top: none; }
.app-best-row.best {
  font-weight: 700;
}
.app-best-time { font-variant-numeric: tabular-nums; }
.app-best-time .day {
  margin-left: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: lowercase;
}
.app-best-cost {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.best-tag {
  background: var(--green-deep);
  color: #062e26;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.app-best-cost .diff {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}
.app-best-empty {
  color: var(--text-dim);
  font-size: 13px;
}

/* BATTERY ------------------------------------------------------------ */
.battery-section { margin-top: 28px; }

.soc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.soc-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.soc-emoji { font-size: 22px; flex-shrink: 0; }
.soc-track {
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
}
.soc-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #84cc16, #10b981);
  border-radius: 999px;
  transition: width 0.6s ease;
}
.soc-label {
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}
.soc-detail {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.batt-advice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.batt-advice.good { border-color: rgba(16,185,129,0.35); background: linear-gradient(160deg, #053427 0%, #141a2e 120%); }
.batt-advice.warn { border-color: rgba(245,158,11,0.4); background: linear-gradient(160deg, #3a2a08 0%, #141a2e 120%); }
.batt-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.batt-detail { font-size: 13px; color: var(--text-dim); line-height: 1.4; }

.peak-info {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 6px 0;
}
.peak-info .peak-lbl {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  margin-right: 4px;
}
.peak-info strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Best per app - small screen polish */
.app-best-row { flex-wrap: wrap; gap: 4px; }
.app-best-row .app-best-time { flex: 1 1 auto; min-width: 0; }
.app-best-row .app-best-cost { flex: 0 0 auto; }
@media (max-width: 360px) {
  .app-best-time { font-size: 13px; }
  .best-tag { font-size: 9px; padding: 1px 5px; }
}

/* ==== Live advies ("Hoeveel apparaten tegelijk?") ==== */
.live-advice { margin: 14px 0 22px; }
.live-advice-card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  overflow: hidden;
}
.advice-head {
  padding: 22px 20px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.advice-head.tone-super {
  background: linear-gradient(135deg, #1ec78a 0%, #15a87f 100%);
  color: #fff;
}
.advice-head.tone-good {
  background: linear-gradient(135deg, #1ec78a 0%, #2bb37a 100%);
  color: #fff;
}
.advice-head.tone-ok {
  background: linear-gradient(135deg, #f4b248 0%, #e89824 100%);
  color: #1a1a2e;
}
.advice-head.tone-wait {
  background: var(--surface-2);
  color: var(--text);
}
.advice-emoji { font-size: 38px; line-height: 1; margin-bottom: 4px; }
.advice-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.advice-sub {
  font-size: 13px;
  opacity: 0.92;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.hint-live { color: #1ec78a; font-weight: 600; }
.hint-pred { color: var(--text-dim); }
.tone-super .hint-live, .tone-good .hint-live { color: rgba(255,255,255,0.95); }
.tone-super .hint-pred, .tone-good .hint-pred { color: rgba(255,255,255,0.7); }
.tone-ok .hint-live { color: #1a1a2e; }
.tone-ok .hint-pred { color: rgba(26,26,46,0.65); }

.dev-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px;
  background: var(--surface);
}
.dev-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  text-align: center;
  background: var(--surface-2);
}
.dev-chip.on {
  background: rgba(30, 199, 138, 0.12);
  border-color: rgba(30, 199, 138, 0.4);
}
.dev-chip.off { opacity: 0.7; }
.dev-icon { font-size: 26px; line-height: 1; }
.dev-name { font-weight: 600; color: var(--text); }
.dev-state {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.dev-chip.on .dev-state { color: #1ec78a; }
.dev-chip.off .dev-state { color: var(--text-dim); }
.chip-later {
  font-size: 11px;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 500;
}
.chip-later.muted { color: var(--text-dim); }
