:root {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
  background: #f5f7fb;
  color: #192438;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

main {
  width: 100%;
  max-width: 440px;
  display: grid;
  gap: 16px;
}

h1 {
  margin: 0 0 8px;
  font-size: 26px;
  line-height: 1.3;
  text-align: center;
}

button,
.button {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 18px 24px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
  color: #192438;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

button:hover,
.button:hover {
  background: #edf2fa;
  border-color: #b9c6dc;
}

.primary {
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
}

.primary:hover {
  border-color: #1d4ed8;
  background: #1d4ed8;
}

button:focus,
.button:focus {
  outline: 3px solid #192438;
  outline-offset: 4px;
  box-shadow: 0 0 0 3px #f5f7fb, 0 0 0 6px #192438;
}

.back {
  justify-self: center;
  padding: 8px;
  color: #2563eb;
  text-underline-offset: 4px;
}

.back:focus-visible {
  outline: 3px solid #192438;
  outline-offset: 4px;
  border-radius: 4px;
}

.distance-mode {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
}

.distance-mode legend {
  padding: 0 6px;
  font-weight: 600;
}

.distance-mode label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  line-height: 1.4;
  cursor: pointer;
}

.distance-mode input {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: #2563eb;
}

.distance-mode input:focus-visible {
  outline: 2px solid #192438;
  outline-offset: 3px;
}

.distance-field[hidden] {
  display: none;
}

.distance-value {
  margin: 8px 0 0;
  color: #425572;
  text-align: center;
  overflow-wrap: anywhere;
}

.distance-value:empty {
  display: none;
}

.distance-summary {
  margin: 0;
  padding: 16px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.distance-summary[data-state="ready"] {
  border-color: #a7d7bc;
  background: #edf8f1;
}

.distance-summary[data-state="error"] {
  border-color: #edb6b6;
  background: #fff1f1;
}

.distance-help {
  margin: 0;
  color: #425572;
  font-size: 14px;
  line-height: 1.5;
}

.distance-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 16px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
}

.distance-form[hidden] {
  display: none;
}

.distance-form label {
  font-size: 15px;
  line-height: 1.4;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.input-row input,
.expense-input,
.expenses textarea {
  width: 100%;
  min-width: 0;
  padding: 12px;
  border: 1px solid #b9c6dc;
  border-radius: 12px;
  font: inherit;
  font-size: 18px;
}

.input-row input:focus,
.expense-input:focus,
.expenses textarea:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.input-row button {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 12px;
}

.allowance-list {
  margin: 12px 0 0;
  padding: 12px 16px 12px 40px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.expenses textarea {
  resize: vertical;
  min-height: 96px;
}

.expense-comment {
  display: block;
  color: #425572;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.allowance-error {
  margin: 12px 0 0;
  color: #a32121;
  line-height: 1.5;
}

dialog {
  width: calc(100% - 48px);
  max-width: 440px;
  max-height: calc(100svh - 48px);
  padding: 24px;
  border: 1px solid #d9e0eb;
  border-radius: 20px;
  color: #192438;
  background: #fff;
  overflow: auto;
}

dialog::backdrop {
  background: rgb(25 36 56 / 50%);
}

dialog h2,
.history-card h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.4;
}

dialog p {
  margin: 0;
  line-height: 1.5;
}

.dialog-content {
  display: grid;
  gap: 16px;
}

dialog > .dialog-content {
  margin-top: 20px;
}

.dialog-content[hidden],
.history-card[hidden],
#complete-trip[hidden],
#payment-toggle[hidden] {
  display: none;
}

#completion-date {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px;
  border: 1px solid #b9c6dc;
  border-radius: 12px;
  font: inherit;
}

#completion-date:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.history-list,
.history-card {
  display: grid;
  gap: 16px;
}

.history-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.history-card p {
  margin: 0;
}

.history-card summary {
  min-height: 44px;
  padding: 10px 0;
  cursor: pointer;
}

.payment-breakdown {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid #d9e0eb;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.payment-breakdown h3,
.payment-breakdown p {
  margin: 0;
}

.payment-total {
  padding: 12px;
  border-radius: 12px;
  background: #edf8f1;
  font-size: 20px;
  font-weight: 700;
}

button:disabled {
  cursor: default;
  opacity: .65;
}

[hidden] {
  display: none !important;
}

.stack,
.panel-form,
.identity {
  display: grid;
  gap: 16px;
  min-width: 0;
}

main.wide {
  max-width: 760px;
}

.panel-form,
.identity {
  padding: 20px;
  border: 1px solid #d9e0eb;
  border-radius: 16px;
  background: #fff;
}

.panel-form input:not([type="checkbox"]):not([type="radio"]),
.panel-form select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px;
  border: 1px solid #b9c6dc;
  border-radius: 12px;
  color: #192438;
  background: #fff;
  font: inherit;
  font-size: 16px;
}

.panel-form input:focus-visible,
.panel-form select:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.panel-form h2,
.panel-form h3,
.identity p {
  margin: 0;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.check-label input {
  width: 20px;
  height: 20px;
  accent-color: #2563eb;
}

.compact {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 16px;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tab-row [aria-selected="true"] {
  border-color: #2563eb;
  color: #fff;
  background: #2563eb;
}

.badge {
  justify-self: start;
  padding: 4px 12px;
  border-radius: 20px;
  color: #425572;
  background: #edf2fa;
  font-size: 14px;
}

@media (max-width: 400px) {
  .allowances .input-row,
  .tab-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  button,
  .button {
    transition: none;
  }
}
