/* ============================================================
   Stroomplanner — donker thema (mobile-first PWA)
   ============================================================ */
:root {
  --bg: #000000;
  --card: #16161b;
  --card-2: #1e1e25;
  --card-3: #26262f;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f2f5;
  --muted: #9a9aa5;
  --faint: #6b6b76;
  --green: #34e374;
  --green-dim: rgba(52, 227, 116, 0.14);
  --red: #ff5252;
  --red-dim: rgba(255, 82, 82, 0.13);
  --amber: #ffb03a;
  --blue: #4da3ff;
  --blue-dim: rgba(77, 163, 255, 0.14);
  --radius: 22px;
  --radius-sm: 14px;
  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

/* ---------- Top ---------- */
.toprow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.region-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px 9px 12px;
  font-weight: 600;
  font-size: 15px;
}
.region-chip .flag {
  width: 22px; height: 15px;
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
}
.region-chip svg { display: block; }

.refresh-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform .3s ease;
}
.refresh-btn:active { transform: rotate(120deg); }
.refresh-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Grote prijs ---------- */
.price-hero { text-align: center; padding: 26px 0 8px; }
.price-hero .label {
  font-size: 13px;
  letter-spacing: 0.22em;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.price-hero .big {
  font-size: clamp(84px, 26vw, 128px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.price-hero .big .eur { font-size: 0.32em; font-weight: 700; vertical-align: 0.42em; margin-right: 2px; opacity: .85; }
.price-hero .unit { color: var(--muted); font-size: 17px; margin-top: -2px; }
.price-hero .slot { color: var(--faint); font-size: 13.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }

.c-green { color: var(--green); }
.c-amber { color: var(--amber); }
.c-red { color: var(--red); }
.c-blue { color: var(--blue); }

/* ---------- Schaal ---------- */
.scale { margin: 18px 4px 6px; position: relative; }
.scale .now-tag {
  position: absolute;
  top: -15px;
  transform: translateX(-50%);
  background: var(--green);
  color: #04160b;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .06em;
  padding: 3px 10px;
  border-radius: 999px;
  z-index: 2;
}
.scale .bar {
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    #2ed573 0 10%,
    #9bcd4d 10% 30%,
    #e8e8e3 30% 70%,
    #eb9540 70% 90%,
    #e04b4b 90% 100%);
  position: relative;
}
.scale .bar .tick {
  position: absolute;
  top: -5px; bottom: -5px;
  width: 3px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 0 2px rgba(0,0,0,.55);
}
.scale .ends {
  display: flex; justify-content: space-between;
  margin-top: 8px;
  gap: 6px;
  font-size: 12px;
}
.scale .ends > div { flex: 1 1 0; }
.scale .ends b { display: block; font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.scale .ends span { color: var(--faint); font-size: 10px; display: block; }
.scale .ends .mid { text-align: center; }
.scale .ends .right { text-align: right; }
.band-extreme-cheap { color: #2ed573; }
.band-cheap { color: #9bcd4d; }
.band-average { color: #e8e8e3; }
.band-expensive { color: #eb9540; }
.band-extreme-expensive { color: #e04b4b; }

/* ---------- Kaarten ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 18px;
}
.card h2 {
  margin: 0 0 2px;
  font-size: 19px;
  font-weight: 700;
}
.card .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; }
.card .head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.card .head .ok { color: var(--green); font-weight: 600; font-size: 14px; }
.card .head .pending { color: var(--faint); font-size: 13px; }

/* ---------- Grafiek ---------- */
.chart-wrap { position: relative; margin: 6px -4px 0; }
canvas#chart { width: 100%; height: 300px; display: block; touch-action: pan-y; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: #23c964;
  color: #04160b;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.25;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .12s ease;
  z-index: 3;
}
.chart-tip.on { opacity: 1; }
.chart-tip .p { font-size: 16px; font-weight: 800; }
.chart-tip.neg { background: #3d7bff; color: #fff; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center;
  color: var(--faint); font-size: 12px; margin-top: 8px;
}
.chart-legend i {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  margin-right: 5px; vertical-align: -1px;
}

/* ---------- Day-nav ---------- */
.daynav {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 20px;
}
.daynav .label { font-size: 22px; font-weight: 700; }
.daynav .label small { display: block; font-size: 12.5px; color: var(--faint); font-weight: 500; }
.daynav button {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
}
.daynav button:disabled { opacity: .3; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 16px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 12px;
}
.stat .t { color: var(--faint); font-size: 12px; display: flex; justify-content: space-between; gap: 4px; }
.stat .t b { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .v { font-size: 19px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Goedkope uren ---------- */
.pills {
  display: flex; gap: 4px;
  background: var(--card-2);
  border-radius: 999px;
  padding: 5px;
}
.pills button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  padding: 9px 0;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font);
}
.pills button.on {
  background: #f5f1e6;
  color: #111;
}
.pills.dark button.on { background: var(--green); color: #04160b; }
.cheap-result {
  margin-top: 13px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.cheap-result b { color: var(--text); }

/* ---------- Aanbeveling ---------- */
.advice {
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(52,227,116,.16), rgba(52,227,116,.05) 55%), var(--card);
}
.advice.warn { background: linear-gradient(160deg, rgba(255,82,82,.16), rgba(255,82,82,.05) 55%), var(--card); }
.advice.neutral { background: linear-gradient(160deg, rgba(255,176,58,.14), rgba(255,176,58,.04) 55%), var(--card); }
.advice .k { font-size: 12px; letter-spacing: .2em; color: var(--muted); font-weight: 700; }
.advice .h { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }
.advice .d { color: var(--muted); font-size: 14.5px; }
.advice .row {
  display: flex; margin-top: 14px;
}
.advice .row div { flex: 1; display: flex; flex-direction: column; }
.advice .row div + div { padding-left: 14px; }
.advice .row .t { font-size: 10.5px; color: var(--faint); letter-spacing: .07em; font-weight: 700; margin-bottom: 4px; }
.advice .row .v { font-size: 19px; font-weight: 800; margin-top: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Plannen ---------- */
.device {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.device .dhead { display: flex; align-items: center; gap: 12px; }
.device .icon {
  width: 46px; height: 46px; flex: 0 0 46px;
  border-radius: 14px;
  background: var(--blue-dim);
  color: var(--blue);
  display: grid; place-items: center;
}
.device .dhead .name { font-weight: 700; font-size: 17px; }
.device .dhead .meta { color: var(--faint); font-size: 12.5px; margin-top: 1px; }
.device .dhead .grow { flex: 1; min-width: 0; }
.device .dhead .name, .device .dhead .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  border: 0; background: transparent; color: var(--faint);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
}
.iconbtn:active { background: var(--card-3); }

.best {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 12px; gap: 8px;
}
.best .when { min-width: 0; }
.best .cd { font-size: 21px; font-weight: 800; color: var(--blue); font-variant-numeric: tabular-nums; }
.best .cd.now { color: var(--green); }
.best .when small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 1px; font-variant-numeric: tabular-nums; }
.cost .amt { display: inline-block; min-width: 4.6ch; text-align: right; }
.cost .cur { margin-right: 3px; }
.best .avg { text-align: right; flex: 0 0 auto; }
.best .avg b { font-size: 21px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.best .avg span { display: block; font-size: 12px; color: var(--faint); }
.cost {
  margin-top: 8px; font-size: 13.5px; color: var(--muted);
  display: flex; justify-content: space-between;
  font-variant-numeric: tabular-nums;
}
.cost b { color: var(--green); }
.device .countdown { color: var(--blue); font-weight: 600; }

.device .settings { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; display: none; }
.device.open .settings { display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field .in {
  display: flex; align-items: center;
  background: var(--card-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.field .in input, .field .in select {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  padding: 12px 12px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.field .in .suf { padding-right: 12px; color: var(--faint); font-size: 13px; white-space: nowrap; }
.field .in select { appearance: none; }

.seg {
  display: flex; background: var(--card-3); border-radius: var(--radius-sm); padding: 4px; gap: 4px;
}
.seg button {
  flex: 1; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 14px; padding: 9px 4px;
  cursor: pointer; font-family: var(--font);
}
.seg button.on { background: #f5f1e6; color: #111; }

.btn {
  display: block; width: 100%;
  border: 0; border-radius: 16px;
  background: var(--green); color: #04160b;
  font-size: 16px; font-weight: 800;
  padding: 15px; margin-top: 14px;
  cursor: pointer; font-family: var(--font);
}
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn[hidden] { display: none; }
.btn.danger { background: var(--red-dim); color: var(--red); }

.addcard {
  margin-top: 14px;
  border: 1.5px dashed rgba(255,255,255,.18);
  background: transparent;
  border-radius: var(--radius);
  color: var(--green);
  font-size: 16px; font-weight: 700;
  padding: 16px;
  width: 100%;
  cursor: pointer; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.empty {
  text-align: center; color: var(--faint); padding: 30px 20px 10px; font-size: 14.5px;
}
.empty svg { opacity: .5; margin-bottom: 10px; }

/* ---------- Instellingen ---------- */
.note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; line-height: 1.5; }
.note.blue { color: #8fb9e8; }

.checkrow {
  display: flex; align-items: flex-start; gap: 12px;
  margin-top: 14px; cursor: pointer; user-select: none;
}
.checkrow .box {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 8px;
  background: #f5f1e6;
  display: grid; place-items: center;
  margin-top: 1px;
}
.checkrow .box svg { opacity: 0; }
.checkrow.on .box svg { opacity: 1; }
.checkrow span { font-size: 14.5px; color: var(--text); }

.selectwrap {
  position: relative;
  background: var(--card-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.selectwrap select {
  width: 100%; appearance: none;
  background: transparent; border: 0;
  color: var(--text); font-size: 16px; font-family: var(--font);
  padding: 14px 40px 14px 14px; outline: none;
}
.selectwrap::after {
  content: "";
  position: absolute; right: 16px; top: 50%;
  width: 9px; height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.selectwrap select option { background: #1c1c22; color: var(--text); }

.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.linkrow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 2px; font-size: 15px;
}
.linkrow + .linkrow { border-top: 1px solid var(--line); }
.linkrow .r { color: var(--faint); font-size: 13.5px; text-align: right; }
.card a { color: var(--blue); text-decoration: none; }

/* ---------- Embed-generator ---------- */
.em-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}
.em-preview iframe { width: 100%; border: 0; display: block; }

/* ---------- Changelog ---------- */
.chlog { margin-top: 10px; }
.chlog .v {
  display: flex; gap: 12px;
  padding: 10px 2px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.45;
}
.chlog .v b { flex: 0 0 30px; color: var(--green); font-variant-numeric: tabular-nums; }
.chlog .v .d { color: var(--faint); font-size: 12px; }

/* ---------- Status / toast ---------- */
.statusbar {
  display: none;
  margin-top: 14px;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13.5px;
  background: var(--blue-dim);
  color: #9cc6f5;
}
.statusbar.on { display: block; }
.statusbar.err { background: var(--red-dim); color: #f3a3a3; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  background: rgba(10, 10, 12, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar .inner {
  max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: var(--tabbar-h);
}
.tabbar button {
  border: 0; background: transparent;
  color: var(--faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  font-size: 11.5px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
}
.tabbar button.on { color: var(--green); }
.tabbar button .ic {
  width: 44px; height: 30px;
  display: grid; place-items: center;
  border-radius: 999px;
  transition: background .15s ease;
}
.tabbar button.on .ic { background: var(--green-dim); }

/* ---------- Views ---------- */
.view { display: none; animation: fade .18s ease; }
.view.on { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { margin: 18px 2px 4px; }
.view-head h1 { font-size: 26px; margin: 0; font-weight: 800; }
.view-head p { color: var(--muted); margin: 3px 0 0; font-size: 14px; }

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 40%, var(--card-2) 50%, var(--card) 60%);
  background-size: 200% 100%;
  animation: sk 1.3s linear infinite;
}
@keyframes sk { to { background-position: -200% 0; } }

.footer-note {
  text-align: center; color: var(--faint); font-size: 12px;
  margin: 26px 10px 0; line-height: 1.6;
}
.footer-note a { color: var(--muted); }

/* ---------- Apparaat-detailpagina (deep link) ---------- */
.devpage {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fade .18s ease;
}
.devpage[hidden] { display: none; }
.devpage-inner {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px calc(env(safe-area-inset-bottom, 0px) + 40px);
}
.dp-head {
  display: flex; align-items: center; gap: 14px;
  margin: 20px 2px 4px;
}
.dp-head h1 { font-size: 26px; margin: 0; font-weight: 800; }
.dp-head p { color: var(--muted); margin: 3px 0 0; font-size: 13.5px; }
.dp-icon {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 16px;
  background: var(--blue-dim);
  color: var(--blue);
  display: grid; place-items: center;
}
.devpage .best { margin-top: 0; }
#dp-link { font-size: 12.5px; color: var(--muted); }
.device .dhead { cursor: pointer; }

@media (min-width: 560px) {
  body { background: radial-gradient(1200px 600px at 50% -10%, #0b0f0d, #000); }
}

/* ---------- Brede schermen ---------- */
@media (min-width: 760px) {
  #app,
  .devpage-inner {
    max-width: 1120px;
    padding-left: 28px;
    padding-right: 28px;
  }

  #app { padding-top: 28px; padding-bottom: 104px; }
  .devpage-inner { padding-top: 28px; padding-bottom: 56px; }
  .price-hero { padding-top: 34px; }
  .price-hero .big { font-size: clamp(104px, 14vw, 156px); }
  canvas#chart { height: 360px; }

  .tabbar {
    left: 50%;
    right: auto;
    bottom: 20px;
    width: min(680px, calc(100% - 40px));
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 14px 42px rgba(0, 0, 0, .35);
  }
  .tabbar .inner { max-width: none; }
}

@media (min-width: 960px) {
  #view-dashboard .stats { margin-top: 18px; }
  #view-dashboard .chart-card,
  #view-dashboard .cheap-card { width: 100%; }
  #view-dashboard .footer-note { margin-top: 28px; }

  #view-plan.on,
  #view-settings.on {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
  }
  #view-plan > .view-head,
  #view-plan > .advice,
  #view-plan > #device-list,
  #view-plan > .empty,
  #view-plan > .addcard,
  #view-plan > #add-form,
  #view-plan > .footer-note,
  #view-settings > .view-head,
  #view-settings > .footer-note { grid-column: 1 / -1; }
  #view-plan > .advice,
  #view-plan > .empty,
  #view-plan > .addcard,
  #view-plan > #add-form,
  #view-settings > .card { margin-top: 0; }
  #device-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  #device-list .device { margin-top: 0; }
}

@media (max-width: 359px) {
  .grid2 { grid-template-columns: 1fr; }
  .stats { gap: 6px; }
  .stat { padding: 11px 8px; }
  .stat .v { font-size: 17px; }
}
