:root {
  /* Tells the browser to paint its own chrome dark too: autofill backgrounds,
     scrollbars, date and number spinners, and the focus ring all follow this. */
  color-scheme: dark;

  --bg: #0f1115;
  --card: #171a21;
  --line: #262b36;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #3ddc84;
  --error: #ff6b6b;
  --warn: #ffb84d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

body.centered { display: grid; place-items: center; min-height: 100vh; }

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
header strong { letter-spacing: 0.02em; }
header form { margin-left: auto; }

main { max-width: 820px; margin: 0 auto; padding: 1.5rem 1.25rem; }
/* main is a fixed max-width block, so the narrow card sits at its left edge
   rather than the viewport's centre. Centre it within main. */
body.centered main { padding: 1.5rem; width: 100%; display: grid; justify-items: center; }

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card:last-child { margin-bottom: 0; }
.card.narrow { width: min(380px, 100%); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
p.muted.small { margin: 0.25rem 0 0; font-weight: 400; }
.nowrap { white-space: nowrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

label { display: block; margin-bottom: 0.75rem; color: var(--muted); font-size: 0.85rem; }
label.inline { display: inline-block; margin-right: 1rem; }
label.grow { flex: 1; margin-bottom: 0; }

input, select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  background: #0d1016;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}
input[type="checkbox"] { width: auto; display: inline-block; margin: 0; accent-color: var(--accent); }
input.tiny { display: inline-block; width: 5rem; margin: 0 0.25rem; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Chrome paints autofilled fields with its own near-white background and
   ignores `background`. The inset shadow is the only way to override it. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #0d1016 inset;
  box-shadow: 0 0 0 1000px #0d1016 inset;
  caret-color: var(--text);
  transition: background-color 9999s;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

button {
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: #08130c;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.small { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 400; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; font-weight: 400; text-decoration: underline; }
button.link.danger { color: var(--error); }
button.outline-danger {
  background: transparent;
  border: 1px solid #5a2a2f;
  color: var(--error);
  font-weight: 500;
}
button.outline-danger:hover { background: rgb(255 107 107 / 0.12); filter: none; }

.row { display: flex; gap: 0.75rem; align-items: flex-end; }
.row.between { align-items: center; justify-content: space-between; }
.row.wrap { flex-wrap: wrap; align-items: center; }

/* The "send one now" caption sat flush against its buttons. */
p.muted.small.test-hint { margin: 0 0 0.75rem; }
p.muted.small.footnote { margin: 0.75rem 0 0; max-width: 46rem; }

.flashes { margin-bottom: 1rem; }
.flash {
  margin: 0 0 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #24513a;
  background: #12251a;
}
.flash.error { border-color: #5a2a2f; background: #2a1518; }

.state { font-size: 1.6rem; font-weight: 600; margin: 0.25rem 0 1rem; }
.state-charging { color: var(--accent); }
.state-fully_charged { color: var(--accent); }
.state-charging_not_started { color: var(--warn); }
.state-charging_interrupted { color: var(--warn); }
.state-error { color: var(--error); }
.state-unknown, .state-cable_disconnected { color: var(--muted); }

/* Label above value, so the columns line up however long a value is -- side by
   side, a long timestamp next to a short "49 km" reads as ragged. */
/* Charge bar. The level class sets --level; everything else reads it, so the
   thresholds live in one place (the template) rather than in every rule. */
.charge { margin: 0 0 1.5rem; }
.charge.low { --level: #ff6b6b; }
.charge.mid { --level: #ffb84d; }
.charge.high { --level: var(--accent); }

.charge-track {
  position: relative;
  height: 0.85rem;
  border-radius: 999px;
  background: #22262f;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.35);
}
.charge-fill {
  height: 100%;
  min-width: 0.85rem;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--level) 72%, #000) 0%, var(--level) 100%);
  transition: width 0.5s ease, background 0.3s ease;
}

/* Where the car stops charging, when it tells us. */
.charge-target {
  position: absolute;
  top: -0.2rem;
  bottom: -0.2rem;
  width: 2px;
  border-radius: 2px;
  background: rgb(255 255 255 / 0.55);
}

/* A charge in progress gets a slow shimmer, so a glance tells it from a pause. */
.charge.live .charge-fill {
  background-image: linear-gradient(90deg,
    color-mix(in srgb, var(--level) 72%, #000) 0%, var(--level) 45%,
    color-mix(in srgb, var(--level) 60%, #fff) 55%, var(--level) 70%,
    color-mix(in srgb, var(--level) 72%, #000) 100%);
  background-size: 220% 100%;
  animation: charge-shimmer 2.4s linear infinite;
}
@keyframes charge-shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .charge.live .charge-fill { animation: none; }
}

.charge-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem 1rem; margin-top: 0.6rem; }
.charge-percent { font-size: 1.15rem; font-weight: 600; color: var(--level); }
.charge-meta .muted { font-size: 0.85rem; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font-size: 0.8rem; }
.facts dd { margin: 0.15rem 0 0; overflow-wrap: anywhere; }

table { width: 100%; border-collapse: collapse; }

/* iOS-style switch: the checkbox stays in the DOM for the form post and for
   keyboard focus, and is painted over by the track. */
.switch { display: inline-flex; align-items: center; gap: 0.6rem; margin: 0; cursor: pointer; }
.switch input {
  position: absolute;
  width: 3rem;
  height: 1.75rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch .track {
  flex: none;
  position: relative;
  width: 3rem;
  height: 1.75rem;
  border-radius: 999px;
  background: #343a48;
  transition: background 0.18s ease;
}
.switch .knob {
  position: absolute;
  top: 0.19rem;
  left: 0.19rem;
  width: 1.37rem;
  height: 1.37rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  transition: transform 0.18s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(1.25rem); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .switch-text { color: var(--text); font-size: 1rem; font-weight: 600; }

/* Caption-sized switch, for the log filter. */
.switch.compact input { width: 2.1rem; height: 1.2rem; }
.switch.compact { gap: 0.45rem; }
.switch.compact .track { width: 2.1rem; height: 1.2rem; }
.switch.compact .knob { top: 0.14rem; left: 0.14rem; width: 0.92rem; height: 0.92rem; }
.switch.compact input:checked + .track .knob { transform: translateX(0.9rem); }
.switch.compact .switch-text { font-size: 0.82rem; font-weight: 400; color: var(--muted); }

/* Head above, URL below at full width -- a webhook URL is long and needs the room. */
.hook { padding: 0.9rem 0; }
.hook + .hook { border-top: 1px solid var(--line); }
.hook-url { margin-top: 0.6rem; }
.hook-url input { font-size: 0.85rem; margin-top: 0; }

/* An off switch has nothing to send, so its URL field goes away with it. */
.hook:has(input[type="checkbox"]:not(:checked)) .hook-url { display: none; }
.hook:has(input[type="checkbox"]:not(:checked)) .hook-head { opacity: 0.5; }

.hook-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; margin-top: 1.25rem; }
.hook-footer label.inline { margin: 0; }

/* Stacked rows rather than a table: a webhook URL in a table cell either
   overflows the card or wraps one character per line on a phone. */
ul.log { list-style: none; margin: 0; padding: 0; font-size: 0.82rem; }
ul.log li { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.log-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.75rem; }
.log-time { font-variant-numeric: tabular-nums; }
.log-detail { margin-top: 0.2rem; overflow-wrap: anywhere; }
.kind-state_change .log-kind { color: var(--accent); }
/* Routine polls are the majority of rows; dimmed so a real event still reads
   as one, and hideable for anyone who does not want them at all. */
.kind-poll { opacity: 0.55; }
ul.log.hide-polls li.kind-poll { display: none; }
/* No border here: the rows carry their own top border, and hiding the poll
   rows leaves a later row first -- so a border on both drew two lines. Let the
   rows own the separator and this is right whatever is hidden. */
p.muted.small.log-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  align-items: center;
  margin: 0 0 0.85rem;
}
.log-filter { margin: 0; }
.kind-poll_error .log-kind, .kind-connect_error .log-kind { color: var(--error); }

@media (max-width: 620px) {
  /* Anything under 16px makes iOS Safari zoom the page when the field takes
     focus, and it ignores user-scalable=no. The desktop sizes stay as they are. */
  input, select, textarea { font-size: 16px; }
  .hook-url input, .hooks input[type="url"] { font-size: 16px; }

  main { padding: 1rem 0.85rem; }
  .card { padding: 1rem; }
  header { gap: 0.6rem; padding: 0.85rem 0.85rem; }
  .hook-footer { gap: 0.75rem 1rem; }
  .facts { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.85rem; }
  .state { font-size: 1.35rem; }
}
