:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #171717;
  --muted: #737373;
  --line: #e7e7e3;
  --accent: #171717;
  --success: #166534;
  --error: #b91c1c;
  --radius: 22px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }

.shell {
  width: min(100% - 28px, 620px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
}

h1 {
  margin: 0;
  font-size: clamp(27px, 8vw, 38px);
  letter-spacing: -.04em;
  line-height: 1.05;
}

.text-link {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .035);
}

.field-grid {
  display: grid;
  gap: 16px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.field > span {
  font-size: 14px;
  font-weight: 700;
}

.field small,
.switch-row small {
  color: var(--muted);
  font-weight: 500;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfbfa;
  color: var(--text);
  outline: none;
  padding: 14px 15px;
  transition: border-color .15s, box-shadow .15s;
}

input {
  min-height: 50px;
}

textarea {
  resize: vertical;
  min-height: 88px;
}

input:focus, textarea:focus, select:focus {
  border-color: #a3a3a3;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .055);
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 44px;
}

.input-with-unit > span {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 700;
}

.calculated {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 54px;
  margin: -2px 0 18px;
  border-radius: 14px;
  background: #f1f1ee;
  padding: 12px 15px;
}

.calculated span {
  color: var(--muted);
  font-size: 13px;
}

.calculated strong {
  font-size: 17px;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
}

.switch-row > span {
  display: grid;
  gap: 2px;
}

.switch-row input {
  width: 22px;
  min-height: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:disabled {
  opacity: .55;
  cursor: wait;
}

.message {
  min-height: 22px;
  margin: 0 0 10px;
  font-size: 14px;
}

.message.success { color: var(--success); }
.message.error, .error { color: var(--error); }

.footnote {
  margin: 14px 8px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.history-list {
  display: grid;
  gap: 12px;
}

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

.history-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.history-heading > div {
  display: grid;
  gap: 3px;
}

.history-heading span {
  color: var(--muted);
  font-size: 12px;
}

.pill {
  border-radius: 999px;
  background: #eeeeea;
  padding: 5px 9px;
  color: var(--text) !important;
  font-size: 11px !important;
  font-weight: 800;
  white-space: nowrap;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 17px;
}

.history-metrics div {
  display: grid;
  gap: 3px;
}

.history-metrics span {
  color: var(--muted);
  font-size: 11px;
}

.history-metrics strong {
  font-size: 14px;
}

.empty-state {
  padding: 54px 20px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

@media (max-width: 430px) {
  .field-grid.two {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .history-metrics {
    grid-template-columns: 1fr 1fr;
  }
}

.auth-shell { max-width: 460px; padding-top: max(64px, env(safe-area-inset-top)); }
.auth-header { margin-bottom: 20px; }
.auth-header p:last-child { margin: 12px 0 0; color: var(--muted); line-height: 1.55; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions form { margin: 0; }
.link-button { border: 0; padding: 0; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }

.notification-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}
.notification-card div { min-width: 0; }
.notification-card strong { font-size: 14px; }
.notification-card p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.secondary-button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f1f1ee;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}
.secondary-button:disabled { opacity: .55; cursor: default; }
@media (max-width: 430px) {
  .notification-card { align-items: stretch; flex-direction: column; }
  .secondary-button { width: 100%; }
}

.datetime-control {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfbfa;
  overflow: hidden;
}

.datetime-display {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 50px;
  padding: 14px 44px 14px 15px;
  color: var(--text);
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.datetime-control::after {
  content: "⌄";
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-54%);
  color: var(--muted);
  font-size: 18px;
  pointer-events: none;
}

.datetime-control input[type="datetime-local"] {
  position: absolute;
  inset: 0;
  width: 100%;
  min-width: 0;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.datetime-control:focus-within {
  border-color: #a3a3a3;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .055);
}

.fuel-title {
  font-size: clamp(34px, 9.5vw, 46px);
  line-height: 1;
  letter-spacing: -.045em;
  white-space: nowrap;
}

@media (max-width: 430px) {
  .topbar {
    gap: 12px;
  }

  .top-actions {
    gap: 10px;
  }

  .top-actions .text-link,
  .top-actions .link-button {
    font-size: 14px;
  }
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.delete-log-button {
  border: 0;
  border-radius: 999px;
  background: #f5e8e8;
  color: var(--error);
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.delete-log-button:disabled {
  opacity: .55;
  cursor: wait;
}

.detected-location {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8f8f6;
  padding: 14px 15px;
}

.detected-location[hidden] { display: none; }

.detected-location-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.detected-location-heading > span {
  font-size: 14px;
  font-weight: 800;
}

.detected-location-heading small {
  color: var(--muted);
  font-size: 11px;
}

.location-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.location-grid div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.location-grid span {
  color: var(--muted);
  font-size: 11px;
}

.location-grid strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.coordinates-display {
  margin-top: 11px;
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 430px) {
  .location-grid { grid-template-columns: 1fr; gap: 8px; }
  .location-grid div { grid-template-columns: 72px minmax(0, 1fr); align-items: baseline; }
}

.refresh-button {
  white-space: nowrap;
}

@media (max-width: 430px) {
  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 6px;
  }

  .refresh-button {
    width: 100%;
    text-align: right;
  }
}

.page-footer {
  margin-top: 28px;
  padding: 8px 0 4px;
  text-align: center;
}

.page-footer form {
  margin: 0;
}

.footer-logout-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.footer-logout-button:active {
  opacity: .6;
}

/* Journey / route history */
.journey-shell { width: min(100% - 28px, 760px); }
.journey-date-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 8px; margin-bottom: 14px; }
.journey-date-row input { min-height: 44px; padding: 9px 12px; text-align: center; }
.journey-date-button { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 24px; cursor: pointer; }
.journey-summary-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 12px 30px rgba(0,0,0,.035); }
.journey-summary-primary { display: grid; gap: 3px; margin-bottom: 18px; }
.journey-summary-primary span, .journey-summary-grid span { color: var(--muted); font-size: 11px; }
.journey-summary-primary strong { font-size: 34px; letter-spacing: -.04em; }
.journey-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.journey-summary-grid > div { display: grid; gap: 4px; }
.journey-summary-grid strong { font-size: 14px; }
.journey-section { margin-top: 24px; }
.journey-section-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 10px; }
.journey-section-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.journey-section-heading span { color: var(--muted); font-size: 11px; }
.journey-timeline { display: grid; }
.timeline-event { display: grid; grid-template-columns: 58px 12px minmax(0, 1fr); gap: 10px; min-height: 58px; color: var(--text); text-decoration: none; }
.timeline-event time { padding-top: 2px; color: var(--muted); font-size: 11px; text-align: right; }
.timeline-event > div { display: grid; align-content: start; gap: 2px; padding-bottom: 14px; }
.timeline-event > div strong { font-size: 13px; }
.timeline-event > div span { color: var(--muted); font-size: 12px; }
.timeline-dot { position: relative; width: 10px; height: 10px; margin-top: 3px; border: 2px solid var(--text); border-radius: 50%; background: var(--bg); }
.timeline-dot::after { content: ""; position: absolute; top: 9px; left: 3px; width: 1px; height: 45px; background: var(--line); }
.timeline-event:last-child .timeline-dot::after { display: none; }
.journey-trip-card { display: block; color: var(--text); text-decoration: none; }
.journey-trip-route { display: flex; align-items: center; gap: 8px; min-width: 0; }
.journey-trip-route strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.journey-trip-route span { color: var(--muted); }
.journey-trip-time { margin-top: 5px; color: var(--muted); font-size: 12px; }
.journey-detail-route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.journey-detail-route > div { display: grid; gap: 3px; min-width: 0; }
.journey-detail-route > div:last-child { text-align: right; }
.journey-detail-route span { color: var(--muted); font-size: 11px; }
.journey-detail-route strong { overflow-wrap: anywhere; }
.journey-arrow { color: var(--muted); font-size: 20px; }
.detail-grid { margin-top: 18px; }
.route-card { position: relative; min-height: 260px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: linear-gradient(180deg, #fbfbfa, #f2f2ef); }
.route-svg { width: 100%; height: 260px; display: block; }
.route-svg polyline { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.route-svg circle { fill: var(--surface); stroke: var(--text); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#route-end { fill: var(--text); }
.route-empty { padding: 80px 20px; color: var(--muted); text-align: center; }
.timeline-event.static { cursor: default; }
@media (max-width: 560px) {
  .journey-summary-grid { grid-template-columns: 1fr 1fr; }
  .journey-detail-route { grid-template-columns: 1fr auto 1fr; gap: 8px; }
  .timeline-event { grid-template-columns: 50px 12px minmax(0,1fr); gap: 8px; }
}
