/* Palette: asphalt and paper, with amber for the one action that matters on each
   screen. Business green and private violet are the only other colors that carry
   meaning — everything else stays out of the way. */
:root {
  --mi-ink: #223040;
  --mi-slate: #2f3d4a;
  --mi-muted: #6d7783;
  --mi-paper: #f4f2ee;
  --mi-card: #ffffff;
  --mi-line: #ddd8d0;
  --mi-amber: #e0952f;
  --mi-amber-dark: #c07a19;
  --mi-green: #45865c;
  --mi-violet: #7061ab;
  --mi-red: #bd5340;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--mi-ink);
  background: var(--mi-paper);
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1em 0.8em 3em;
}

h1, h2 { color: var(--mi-slate); }
h1 { font-size: 1.25em; margin: 0 0 0.6em; }
h2 { font-size: 1.05em; margin: 0 0 0.5em; }

a { color: var(--mi-amber-dark); }

.hint { color: var(--mi-muted); font-size: 0.85em; margin-top: -0.2em; }
.error { color: var(--mi-red); font-weight: 600; }

/* ---- shared controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  background: var(--mi-amber);
  color: #fff;
  border: none;
  padding: 0.7em 1.3em;
  border-radius: 8px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--mi-amber-dark); }
.btn-secondary { background: var(--mi-slate); }
.btn-secondary:hover { background: #1d2833; }
.btn-danger { background: var(--mi-red); }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--mi-red);
  font-size: 0.9em;
  cursor: pointer;
  text-decoration: underline;
}

input[type=text], input[type=number], input[type=date], input[type=email], select {
  padding: 0.6em;
  border: 1px solid var(--mi-line);
  border-radius: 8px;
  font-size: 1.05em;
  width: 100%;
  background: #fff;
  color: var(--mi-ink);
}
label { display: block; margin-bottom: 0.7em; }
label.inline { display: inline-flex; align-items: center; gap: 0.4em; }

.card {
  background: var(--mi-card);
  border: 1px solid var(--mi-line);
  border-radius: 12px;
  padding: 1.1em;
  margin-bottom: 1em;
}
.setup-card { max-width: 420px; }
.back-link { margin-top: 1.5em; font-size: 0.9em; }

/* ---- landing ---- */

.hero { text-align: center; padding: 1.5em 0 0.5em; }
.hero-mark { color: var(--mi-slate); }
.hero h1 { font-size: 1.8em; margin: 0.2em 0 0.1em; }
.hero-tagline { color: var(--mi-muted); margin: 0 auto 1.2em; max-width: 30em; }
.steps { padding-left: 1.2em; margin: 0; }
.steps li { margin-bottom: 0.6em; }
.card-privacy { border-left: 4px solid var(--mi-green); }
.card-cta { text-align: center; }

/* ---- home: one screen, never scrolls -----------------------------------
   body is the flex column and the j-tools bar is its first child (bar.js inserts
   itself before its own <script>, which sits directly in <body>), so the logging
   area simply takes whatever height is left over — no guessing at the bar's height
   and no re-measuring when it finishes loading. */

body.home {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.home > .jtools-bar { flex: 0 0 auto; }
body.home main {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  padding: 0.6em 0.7em 0.8em;
  display: flex;
}

.home-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.55em;
}

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55em; flex: 0 0 auto; }
.tile {
  background: var(--mi-card);
  border: 1px solid var(--mi-line);
  border-radius: 12px;
  padding: 0.5em 0.7em 0.55em;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.tile-label { font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--mi-muted); }
.tile-value { font-size: 1.6em; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-unit {
  font-size: 0.75em;
  color: var(--mi-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-bar { height: 4px; border-radius: 2px; background: var(--mi-line); margin-top: 0.35em; overflow: hidden; }
.tile-bar-fill { height: 100%; background: var(--mi-violet); }
.tile-warn .tile-bar-fill { background: var(--mi-amber); }
.tile-over .tile-value, .tile-over .tile-unit { color: var(--mi-red); }
.tile-over .tile-bar-fill { background: var(--mi-red); }

.datebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  flex: 0 0 auto;
}
.datebar-date { font-weight: 600; min-width: 8em; text-align: center; }
.datebar-step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: var(--mi-card);
  border: 1px solid var(--mi-line);
  color: var(--mi-slate);
  font-size: 1.2em;
  text-decoration: none;
}
.datebar-step.is-disabled { opacity: 0.3; }

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  flex: 0 0 auto;
  background: #eaf1ec;
  border: 1px solid #c4d9ca;
  border-radius: 10px;
  padding: 0.5em 0.7em;
  font-size: 0.85em;
  color: var(--mi-ink);
  text-decoration: none;
}
.toast-gap { background: #fdf3e2; border-color: #ecd6a8; }
.toast-error { background: #fbeae6; border-color: #e6bdb2; }
.toast-undo {
  background: none;
  border: none;
  padding: 0;
  color: var(--mi-amber-dark);
  font-size: 1em;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: underline;
}

/* The confirm card takes whatever vertical space is left and centers itself in it,
   so the layout stays balanced on a tall phone and simply tightens on a short one.
   Only .suggest-body may scroll: the confirm button is a sibling of it, not a child,
   so on a screen too short to show everything the trip details give way and the one
   action the screen exists for stays put. */
.suggest {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--mi-card);
  border: 1px solid var(--mi-line);
  border-radius: 14px;
  padding: 0.8em;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.7em;
  overflow: hidden;
}
.suggest-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.7em;
}
.suggest-empty { justify-content: center; text-align: center; overflow-y: auto; }
.suggest-empty p { margin: 0.3em 0; color: var(--mi-muted); }

.suggest-route {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  font-weight: 600;
  flex-wrap: wrap;
}
.leg { display: inline-flex; align-items: center; gap: 0.3em; color: var(--mi-slate); }
.leg-arrow { color: var(--mi-muted); display: inline-flex; }

.suggest-km { display: flex; align-items: baseline; justify-content: center; gap: 0.25em; }
.suggest-km input {
  width: 3.6em;
  border: none;
  border-bottom: 2px dashed var(--mi-line);
  border-radius: 0;
  padding: 0 0.1em;
  font-size: 2.6em;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--mi-ink);
}
.suggest-km input:focus { outline: none; border-bottom-color: var(--mi-amber); }
.suggest-km-unit { font-size: 1.1em; color: var(--mi-muted); }

.chips { display: flex; gap: 0.4em; overflow-x: auto; flex: 0 0 auto; padding-bottom: 0.15em; }
.chips-routes { scrollbar-width: none; }
.chips-routes::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--mi-line);
  background: var(--mi-card);
  border-radius: 999px;
  padding: 0.35em 0.75em;
  font-size: 0.85em;
  color: var(--mi-slate);
  text-decoration: none;
  cursor: pointer;
  margin: 0;
  white-space: nowrap;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span { display: inline-flex; align-items: center; gap: 0.3em; }
.chip em { font-style: normal; color: var(--mi-muted); }
.chip.is-selected { background: var(--mi-slate); border-color: var(--mi-slate); color: #fff; }
.chip.is-selected em { color: rgba(255,255,255,0.7); }

.segmented { display: flex; gap: 0; border: 1px solid var(--mi-line); border-radius: 999px; overflow: hidden; flex: 0 0 auto; }
.segmented label { flex: 1 1 0; margin: 0; text-align: center; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 0.5em; font-size: 0.9em; font-weight: 600; color: var(--mi-muted); }
.segmented label.is-selected span { background: var(--mi-green); color: #fff; }
.segmented label.is-selected:last-child span { background: var(--mi-violet); }

.btn-confirm { flex: 0 0 auto; font-size: 1.1em; padding: 0.75em; width: 100%; }

.home-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.4em;
  flex: 0 0 auto;
  font-size: 0.82em;
}
.home-nav a { color: var(--mi-muted); text-decoration: none; }
.home-nav a:hover { color: var(--mi-amber-dark); text-decoration: underline; }

/* A phone on its side, or a browser with the on-screen keyboard open. Everything the
   screen carries has to keep fitting, so the surroundings give up their generosity
   before the trip details do. */
@media (max-height: 600px) {
  body.home main { padding: 0.4em 0.6em 0.5em; }
  .home-grid { gap: 0.35em; }
  .tile { padding: 0.3em 0.6em 0.35em; }
  .tile-value { font-size: 1.15em; }
  .tile-label { font-size: 0.62em; }
  .tile-unit { font-size: 0.68em; }
  .tile-bar { margin-top: 0.2em; }
  .datebar-step { width: 1.8em; height: 1.8em; font-size: 1em; }
  .datebar-date { font-size: 0.9em; }
  .toast { padding: 0.35em 0.6em; font-size: 0.78em; }
  .suggest { padding: 0.5em; gap: 0.45em; }
  .suggest-body { gap: 0.45em; }
  .suggest-km input { font-size: 1.8em; }
  .btn-confirm { font-size: 1em; padding: 0.55em; }
}

/* ---- lists (settings, history) ---- */

.row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.6em 0;
  border-top: 1px solid var(--mi-line);
}
.row:first-of-type { border-top: none; }
.row-icon { color: var(--mi-slate); display: flex; flex: 0 0 auto; }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 0.85em; color: var(--mi-muted); }
.row-actions { display: flex; align-items: center; gap: 0.5em; flex: 0 0 auto; }

.badge {
  display: inline-block;
  font-size: 0.72em;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  background: var(--mi-paper);
  border: 1px solid var(--mi-line);
  color: var(--mi-muted);
}
.badge-active { background: var(--mi-green); border-color: var(--mi-green); color: #fff; }

.icon-picker { display: flex; flex-wrap: wrap; gap: 0.35em; margin-bottom: 0.8em; }
.icon-picker label { margin: 0; }
.icon-picker input { position: absolute; opacity: 0; pointer-events: none; }
.icon-picker span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4em;
  height: 2.4em;
  border: 1px solid var(--mi-line);
  border-radius: 8px;
  background: var(--mi-card);
  color: var(--mi-slate);
  cursor: pointer;
}
.icon-picker label.is-selected span { background: var(--mi-slate); border-color: var(--mi-slate); color: #fff; }

.day-picker { display: flex; gap: 0.3em; margin-bottom: 0.4em; }
.day-picker label { margin: 0; }
.day-picker input { position: absolute; opacity: 0; pointer-events: none; }
.day-picker span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5em;
  height: 2.5em;
  border: 1px solid var(--mi-line);
  border-radius: 8px;
  background: var(--mi-card);
  font-size: 0.85em;
  cursor: pointer;
}
.day-picker label.is-selected span { background: var(--mi-slate); border-color: var(--mi-slate); color: #fff; }

/* ---- tables (history, export summary) ---- */

.table-scroll { overflow-x: auto; }
table.log { width: 100%; border-collapse: collapse; font-size: 0.88em; }
table.log th, table.log td { text-align: left; padding: 0.45em 0.5em; border-top: 1px solid var(--mi-line); white-space: nowrap; }
table.log th { color: var(--mi-muted); font-weight: 600; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em; border-top: none; }
table.log td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.log tr.is-correction td { background: #fdf3e2; }
.type-business { color: var(--mi-green); font-weight: 600; }
.type-private { color: var(--mi-violet); font-weight: 600; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(7em, 1fr)); gap: 0.6em; margin-bottom: 1em; }
.summary div { background: var(--mi-paper); border-radius: 10px; padding: 0.6em; }
.summary dt { font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--mi-muted); }
.summary dd { margin: 0; font-size: 1.25em; font-weight: 700; font-variant-numeric: tabular-nums; }

.filters { display: flex; gap: 0.6em; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1em; }
.filters label { margin: 0; }
.filters select { width: auto; }
