/* ---------- tokens ---------- */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --context: #898781;      /* de-emphasis series (previous period) */
  --good: #006300;
  --bad: #d03b3b;
  --focus: #2a78d6;
}

:root[data-theme="dark"] {
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #d03b3b;
  --focus: #3987e5;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

main, .app-header, .app-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

main { display: flex; flex-direction: column; gap: 14px; }

#dashboard { display: flex; flex-direction: column; gap: 14px; }

h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }

button { font: inherit; cursor: pointer; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 22px;
  padding-bottom: 8px;
}

.wordmark { font-size: 19px; letter-spacing: -0.02em; }
.wordmark span { color: var(--muted); font-weight: 400; margin-left: 2px; }

.head-actions { display: flex; align-items: center; gap: 8px; }
.head-actions .ghost { display: inline-flex; align-items: center; font-size: 13px; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.head-right { display: flex; align-items: center; gap: 12px; }

.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- entry form ---------- */

.entry-card { padding: 14px 18px; }

#entryForm {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1 1 220px; }
.field.actions { flex-direction: row; gap: 8px; }

.field label { font-size: 12px; color: var(--muted); }
.field .opt { font-size: 11px; color: var(--muted); opacity: 0.75; }

.field input {
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  min-width: 0;
}
.field input:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
#inDate { width: 160px; }
#inKm { width: 110px; }
#inTime { width: 120px; }

button.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }

.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  text-decoration: none;
  cursor: pointer;
  font-size: inherit;
}
.ghost:hover { color: var(--ink); background: var(--page); }
.ghost.small { padding: 3px 10px; font-size: 12px; border-radius: 6px; }
.ghost.small[aria-pressed="true"] { background: var(--page); color: var(--ink); }

/* ---------- empty state ---------- */

.empty-card { text-align: center; padding: 44px 20px; }
.empty-card h2 { font-size: 17px; }
.empty-card p { color: var(--ink-2); margin: 8px 0 18px; }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.tile .delta { font-size: 12px; color: var(--muted); }
.tile .delta b { font-weight: 600; }
.tile .delta .up { color: var(--good); }
.tile .delta .down { color: var(--bad); }
.tile .spark { margin-top: 8px; }

.mini-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.mini-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
}
.mini-tile .label { font-size: 11px; color: var(--muted); }
.mini-tile .value { font-size: 17px; font-weight: 600; }
.mini-tile .value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.mini-tile .hint { font-size: 11px; color: var(--muted); }

/* ---------- range filter ---------- */

.filters {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
}

.filters button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
}
.filters button:hover { color: var(--ink); }
.filters button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
}

/* ---------- charts ---------- */

.chart-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
}

.chart { position: relative; min-height: 200px; }
.chart svg { display: block; }

.chart .no-data {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend .key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* tooltip */
.viz-tip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}
.viz-tip .tip-title { color: var(--muted); margin-bottom: 2px; }
.viz-tip .tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip .tip-row .key { width: 10px; height: 3px; border-radius: 2px; flex: none; }
.viz-tip .tip-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.viz-tip .tip-row span { color: var(--ink-2); }

/* svg pieces (colors via CSS vars so theme switches need no re-render) */
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.tick-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.x-label { fill: var(--muted); font-size: 11px; }
.dlabel { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.bar { fill: var(--accent); }
.bar.hovered { filter: brightness(1.18); }
.hit { fill: transparent; }
.crosshair { stroke: var(--axis); stroke-width: 1; }

/* chart table twin */
.chart-table { max-height: 300px; overflow-y: auto; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.chart-table th, .chart-table td {
  text-align: left;
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid var(--grid);
}
.chart-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.chart-table td.num, .chart-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- entries table ---------- */

.entries-card { padding-bottom: 8px; }

#entriesTable table { width: 100%; border-collapse: collapse; font-size: 14px; }
#entriesTable th, #entriesTable td {
  text-align: left;
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--grid);
}
#entriesTable tr:last-child td { border-bottom: 0; }
#entriesTable th { color: var(--muted); font-weight: 500; font-size: 12px; }
#entriesTable td.num, #entriesTable th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#entriesTable td.dim { color: var(--ink-2); }
#entriesTable td.note { color: var(--ink-2); overflow-wrap: anywhere; }
#entriesTable td.rowactions { text-align: right; white-space: nowrap; width: 70px; }

.row-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1.3;
}
.row-btn:hover { color: var(--ink); background: var(--page); }
.row-btn.del:hover { color: var(--bad); }

.more-note { color: var(--muted); font-size: 12px; padding: 8px 0; margin: 0; }

/* ---------- footer ---------- */

.app-footer { padding-top: 6px; padding-bottom: 32px; }

.footer-actions { display: flex; gap: 18px; flex-wrap: wrap; }

.link-btn {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink-2);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
}
.link-btn:hover { color: var(--ink); }
.link-btn.danger { color: var(--bad); opacity: 0.85; }
.link-btn.danger:hover { opacity: 1; color: var(--bad); }

.status { font-size: 13px; color: var(--good); min-height: 1.2em; margin: 10px 0 0; }
.note { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

.pending-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px;
  color: var(--muted);
  vertical-align: middle;
}

/* ---------- quick-add page ---------- */

.qa-main {
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 32px;
}

.qa-card { display: flex; flex-direction: column; gap: 14px; padding: 22px 20px; }

.qa-label { font-size: 12px; color: var(--muted); text-align: center; }

.qa-km-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
.qa-km-wrap input {
  width: 180px;
  border: 0;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 44px;
  font-weight: 600;
  text-align: center;
  padding: 0 0 4px;
  letter-spacing: -0.01em;
}
.qa-km-wrap input:focus { outline: none; border-bottom-color: var(--accent); }
.qa-km-wrap input::placeholder { color: var(--grid); }
.qa-km-wrap span { font-size: 18px; color: var(--muted); }

.qa-row { display: flex; gap: 10px; }
.qa-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
}
.qa-row input:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
.qa-row #qaDate { flex: 0 0 150px; }

.qa-save { padding: 13px 16px; font-size: 16px; border-radius: 10px; }

.qa-status { text-align: center; margin: 0; }

.qa-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 16px;
}
.qa-stat { text-align: center; }
.qa-stat .label { font-size: 11px; color: var(--muted); }
.qa-stat .value { font-size: 18px; font-weight: 600; }
.qa-stat .value small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 2px; }

.qa-recent h2 { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.qa-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 14px;
}
.qa-entry:last-child { border-bottom: 0; }
.qa-date { color: var(--ink-2); flex: 0 0 auto; }
.qa-dist { font-variant-numeric: tabular-nums; margin-left: auto; order: 3; white-space: nowrap; }
.qa-enote { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qa-entry .row-btn { order: 4; }

.qa-note { font-size: 12px; color: var(--muted); text-align: center; margin: 0; }

/* ---------- responsive ---------- */

@media (max-width: 800px) {
  .chart-row { grid-template-columns: 1fr; }
  .tile .value { font-size: 22px; }
  .card-head { flex-wrap: wrap; }
  .head-right { flex-wrap: wrap; row-gap: 6px; }
}

@media (max-width: 560px) {
  #entriesTable .col-speed { display: none; }
}
