/* Disseny: quadre d'instruments sobri. Fons gris fred, xifres en Barlow Semi
   Condensed (tipus quadre de comandament), color d'accent petroli, i la
   bateria representada amb una barra de 0-100 %. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #141a21;
  --muted: #5b6672;
  --line: #d6dce3;
  --accent: #0b6f6a;
  --accent-ink: #ffffff;
  --accent-soft: #d8eeec;
  --good: #2f8f55;
  --warn: #b7791f;
  --bad: #c0392b;
  --track: #e2e7ec;
  --used: #8fa3b5;
  --font-num: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1216;
    --surface: #171d23;
    --ink: #e8edf2;
    --muted: #93a0ad;
    --line: #26303a;
    --accent: #3fbfb6;
    --accent-ink: #062523;
    --accent-soft: #143331;
    --good: #4cc27a;
    --warn: #e0a645;
    --bad: #ef6b5d;
    --track: #232c35;
    --used: #4d5f70;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-body);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
h1, h2 { font-family: var(--font-num); font-weight: 600; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: 0.01em; }
h2 { font-size: 1.15rem; }
code { font-size: 0.9em; }
a { color: var(--accent); }
.muted { color: var(--muted); }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding-block: 12px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---- capçalera ---- */
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  background: var(--bg); z-index: 10;
}
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 12px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand {
  font: 700 1.25rem var(--font-num); color: var(--ink); text-decoration: none;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.topbar .icon-btn { margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 0.8rem var(--font-body); padding: 3px 10px; border-radius: 99px;
  background: var(--track); color: var(--muted);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.on { background: var(--accent-soft); color: var(--accent); }
.chip.driving { background: var(--accent); color: var(--accent-ink); }

/* ---- botons ---- */
.icon-btn {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink);
  font-size: 1.5rem; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--track); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 600 0.95rem var(--font-body); cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.danger.confirm { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: progress; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}

/* ---- inici de sessió ---- */
.login { max-width: 380px; margin: 12vh auto 0; padding: 24px; display: grid; gap: 10px; }
label { font-weight: 500; font-size: 0.9rem; }
input[type="text"], input[type="password"], textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit;
}
.error { color: var(--bad); margin: 0; }

/* ---- viatge en curs ---- */
.live-banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-weight: 500;
}
.pulse { width: 10px; height: 10px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* ---- mes i resum ---- */
.month-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.month-bar h1 { text-align: center; flex: 1; }
.summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 0 0 20px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.summary div { background: var(--surface); padding: 12px 12px 10px; min-width: 0; }
.summary dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.summary dd { margin: 2px 0 0; font: 600 1.6rem/1.1 var(--font-num); font-variant-numeric: tabular-nums; }
.summary small { font: 500 0.8rem var(--font-body); color: var(--muted); margin-left: 3px; }
@media (max-width: 520px) { .summary { grid-template-columns: repeat(2, 1fr); } }

/* ---- llistat ---- */
.day { margin-bottom: 18px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 0 4px 6px; color: var(--muted); font-size: 0.85rem;
}
.day-head strong { color: var(--ink); font-weight: 600; }
.day-head span { font-variant-numeric: tabular-nums; }
.trip {
  display: grid; gap: 10px; width: 100%; text-align: left; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font: inherit; cursor: pointer; border-radius: 0; margin-top: -1px;
}
.day .trip:first-of-type { border-radius: var(--radius) var(--radius) 0 0; margin-top: 0; }
.day .trip:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.day .trip:only-of-type { border-radius: var(--radius); }
.trip:hover { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); }
.trip-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.trip-time { font: 600 1.05rem var(--font-num); font-variant-numeric: tabular-nums; }
.trip-dur { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.route { display: grid; grid-template-columns: 12px 1fr; column-gap: 8px; row-gap: 2px; min-width: 0; }
.route span { min-width: 0; overflow-wrap: anywhere; }
.route i { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--muted); align-self: center; margin-left: 2px; }
.route i.end { background: var(--muted); }
.metrics { display: flex; flex-wrap: wrap; gap: 4px 16px; font-variant-numeric: tabular-nums; }
.metrics b { font: 600 1.05rem var(--font-num); }
.metrics em { font-style: normal; color: var(--muted); font-size: 0.85rem; margin-left: 2px; }
.est { color: var(--warn); font-size: 0.75rem; }

/* bateria: barra 0-100 %, la part gastada en gris i el que queda en color */
.battery { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.battery-label { font: 600 0.95rem var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.battery-label span { color: var(--muted); font-weight: 500; }
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar .left { position: absolute; inset: 0 auto 0 0; background: var(--good); border-radius: 4px 0 0 4px; }
.bar .left.mid { background: var(--warn); }
.bar .left.low { background: var(--bad); }
.bar .spent { position: absolute; top: 0; bottom: 0; background: var(--used); }

.empty { padding: 22px; display: grid; gap: 10px; justify-items: start; }
.empty p { margin: 0; }
.offline-note { text-align: center; font-size: 0.85rem; }

/* ---- full de detall ---- */
.sheet {
  width: min(560px, 100%); max-height: 92vh; border: 0; padding: 0;
  border-radius: 18px 18px 0 0; margin: auto auto 0; background: var(--surface); color: var(--ink);
  overflow-x: hidden;
}
@media (min-width: 640px) { .sheet { border-radius: 18px; margin: auto; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet form {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 16px max(16px, env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 8px; }
.facts div { background: var(--bg); padding: 8px 10px; min-width: 0; }
.facts dt { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.facts dd { margin: 0; font: 600 1.1rem var(--font-num); font-variant-numeric: tabular-nums; }
.check span { min-width: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; }
.map-link { font-size: 0.9rem; }

/* ---- configuració ---- */
.back { text-decoration: none; display: inline-block; margin-bottom: 6px; }
.section-title { margin: 22px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-family: var(--font-body); font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  counter-increment: step; display: grid; grid-template-columns: 30px 1fr; gap: 4px 10px;
  padding: 14px; background: var(--surface); border: 1px solid var(--line); margin-top: -1px;
}
.steps li:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.steps li:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.steps li::before {
  content: counter(step); grid-row: span 3; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font: 600 0.85rem var(--font-num);
  border: 2px solid var(--line); color: var(--muted);
}
.steps li.done::before { content: "✓"; background: var(--good); border-color: var(--good); color: #fff; }
.steps h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.steps p { margin: 0; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.steps .btn { justify-self: start; margin-top: 6px; }
.cost { padding: 16px; display: grid; gap: 12px; }
.cost-big { font: 600 2rem/1 var(--font-num); font-variant-numeric: tabular-nums; }
.cost-big small { font: 500 0.9rem var(--font-body); color: var(--muted); margin-left: 6px; }
.meter { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--good); }
.meter span.mid { background: var(--warn); }
.meter span.high { background: var(--bad); }
.cost p { margin: 0; font-size: 0.9rem; color: var(--muted); }
.cost .alert { color: var(--bad); font-weight: 600; }
.log { list-style: none; margin: 0; padding: 4px 14px; max-height: 320px; overflow: auto; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; display: grid; gap: 2px; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.log li.error span { color: var(--bad); }
.settings-actions { margin-top: 24px; }
