/* ChargeBuddy – farver efter dataviz-referencepaletten: blå = min Tesla, orange = andre biler. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --mine: #2a78d6;
  --other: #eb6834;
  --super: #1baf7a;
  --unknown: #a8a69f;
  --good: #006300;
  --bad: #b3261e;
  --wash: rgba(11, 11, 11, 0.05);
  --accent-wash: rgba(42, 120, 214, 0.10);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --raised: #1f1f1e;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --mine: #3987e5;
    --other: #d95926;
    --super: #199e70;
    --unknown: #6f6e69;
    --good: #0ca30c;
    --bad: #e66767;
    --wash: rgba(255, 255, 255, 0.06);
    --accent-wash: rgba(57, 135, 229, 0.16);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.loading, .empty { color: var(--muted); text-align: center; padding: 48px 0; }

header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 2px 16px; }
header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
header .sub { color: var(--muted); font-size: 13px; text-align: right; }

section, .card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--ring);
  padding: 16px;
  margin: 0 0 14px;
}
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 13px; }

/* Live */
.live { position: relative; overflow: hidden; }
.live .who { font-size: 15px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--mine)); position: relative; flex: none; }
.pulse::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--c, var(--mine)); opacity: 0; animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(0.4); opacity: 0.8; } 100% { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pulse::after { animation: none; } }
.live .big { font-size: 44px; font-weight: 700; letter-spacing: -0.03em; margin: 6px 0 2px; }
.live .row { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-2); font-size: 15px; }
.live .row b { color: var(--ink); font-weight: 600; }
.idle { display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.idle .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--axis); }

/* Periode */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -2px 12px; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 999px;
  background: var(--wash); color: var(--ink-2); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--page); font-weight: 600; }
.dates { display: flex; gap: 8px; align-items: center; margin: -4px 0 12px; flex-wrap: wrap; }
.dates input { font: inherit; font-size: 15px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--ring); background: var(--raised); color: var(--ink); }

/* Tal */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--raised); border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 4px 0 2px; }
.tile .meta { font-size: 13px; color: var(--muted); }
.key { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* Grafer */
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.on { fill: var(--wash); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.seg { display: inline-flex; background: var(--wash); border-radius: 999px; padding: 2px; }
.seg button { border: 0; font: inherit; font-size: 13px; padding: 4px 12px; border-radius: 999px; background: none; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--ring); }
.linkbtn { border: 0; background: none; color: var(--mine); font: inherit; font-size: 13px; cursor: pointer; padding: 4px 0; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 140px;
  background: var(--raised); color: var(--ink); border-radius: 10px; padding: 8px 10px;
  box-shadow: 0 0 0 1px var(--ring), 0 6px 20px rgba(0, 0, 0, 0.18); font-size: 13px;
}
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .r i { width: 12px; height: 3px; border-radius: 2px; background: var(--c); }
.tip .r span { color: var(--ink-2); margin-right: auto; }
.tip .r b { font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 4px; border-bottom: 1px solid var(--grid); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }

/* Afregning */
.bill { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.bill:last-child { border-bottom: 0; }
.bill .m { flex: 1; }
.bill .m b { display: block; font-weight: 600; }
.bill .m small { color: var(--muted); }
.bill .amt { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.pill.paid { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pill.due { background: color-mix(in srgb, var(--other) 16%, transparent); color: var(--other); }
.btn {
  border: 0; font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  background: var(--ink); color: var(--page); font-weight: 600;
}
.btn.ghost { background: var(--wash); color: var(--ink); font-weight: 500; }
.btn[disabled] { opacity: 0.5; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Ladevindue */
.window { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 2px 0; }

/* Ladninger */
.session { border-bottom: 1px solid var(--grid); }
.session:last-child { border-bottom: 0; }
.session > button.head {
  all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 0; cursor: pointer;
}
.session .when { font-weight: 600; }
.session .detail { color: var(--muted); font-size: 13px; }
.session .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.session .num small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.owner { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.owner select {
  font: inherit; font-size: 13px; border: 0; border-radius: 8px; padding: 3px 6px; background: var(--wash); color: var(--ink);
}
.saving { font-size: 12px; font-weight: 600; }
.expand { padding: 0 0 14px; }
.expand .stat { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 10px; }
.expand .stat b { color: var(--ink); }
.subtitle { font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.pending { color: var(--muted); font-size: 12px; font-style: italic; }

footer { color: var(--muted); font-size: 12px; text-align: center; margin-top: 24px; }

/* Nørdetal */
.scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
table.nerd { font-size: 13px; min-width: 760px; }
table.nerd th, table.nerd td { white-space: nowrap; padding: 7px 8px; }
table.nerd th:first-child, table.nerd td:first-child { position: sticky; left: -16px; background: var(--surface); padding-left: 16px; }

/* Faner */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  box-shadow: 0 -1px 0 var(--ring);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs { max-width: 720px; margin: 0 auto; display: flex; }
.tab {
  flex: 1; border: 0; background: none; font: inherit; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--mine); font-weight: 600; }
.tab .ico { position: relative; display: inline-flex; }
.tab .badge { position: absolute; top: -1px; right: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--other); box-shadow: 0 0 0 2px var(--page); }
.livebar {
  all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--surface); box-shadow: 0 0 0 1px var(--ring); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px;
  font-size: 14px; color: var(--ink-2);
}

/* Legende som til/fra-knapper */
.legend.toggles { gap: 6px; }
.toggle {
  border: 0; font: inherit; font-size: 13px; color: var(--ink-2); background: var(--wash);
  border-radius: 999px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
}
.toggle[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.toggle[aria-pressed="false"] .key { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
