:root {
  --bg: #fbfaf8;
  --fg: #1d1d1b;
  --muted: #6b6a66;
  --line: #dddbd5;
  --field: #ffffff;
  --accent: #2f5d50;
  --accent-fg: #ffffff;
  --danger: #a33a2c;
  --ok: #2f6b3a;
  --notice-bg: #eef3ee;
  --error-bg: #f8ecea;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a19;
    --fg: #e6e4df;
    --muted: #9a9892;
    --line: #3a3936;
    --field: #232322;
    --accent: #8cbcaa;
    --accent-fg: #14211c;
    --danger: #e08a7d;
    --ok: #8fc99a;
    --notice-bg: #1f2a22;
    --error-bg: #2e1f1c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

header.top, main { max-width: 720px; margin: 0 auto; }

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
header.top nav { display: flex; flex-wrap: wrap; gap: 16px; align-items: baseline; }
header.top form { display: inline; }
.brand { font-weight: 600; color: var(--fg); text-decoration: none; }

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1rem; margin: 32px 0 8px; }

a { color: var(--accent); }
code { font-size: 0.9em; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9em; margin: 4px 0; }
.nowrap { white-space: nowrap; }
.row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.row h1 { margin: 0; }

.notice, .error { padding: 8px 12px; border-left: 3px solid; }
.notice { background: var(--notice-bg); border-color: var(--ok); }
.error { background: var(--error-bg); border-color: var(--danger); }
.notice p { margin: 0 0 8px; }

/* forms */
input, select, button, .button {
  font: inherit;
  color: inherit;
}
input, select {
  width: 100%;
  padding: 6px 8px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 3px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="radio"], input[type="checkbox"] { width: auto; margin: 0 6px 0 0; }
textarea {
  width: 100%;
  padding: 6px 8px;
  font: 0.85em/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.stack label.check { flex-direction: row; align-items: center; }

button, .button {
  display: inline-block;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--fg);
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
button.danger { border-color: var(--danger); color: var(--danger); }
button.link {
  padding: 0;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
}
button.link.danger { color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 4px; }
.narrow { max-width: 360px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form.compact { margin: 0; }
.or { margin: 16px 0 8px; }
table.kv { width: auto; margin-bottom: 16px; }
table.kv th { padding-right: 16px; white-space: nowrap; }
table.kv td { word-break: break-all; }

fieldset { border: 1px solid var(--line); border-radius: 3px; padding: 10px 14px 14px; margin: 0; }
legend { padding: 0 4px; font-weight: 600; }
fieldset .radio { flex-direction: row; align-items: center; margin: 10px 0 4px; }
.via-row { display: flex; gap: 8px; margin-bottom: 8px; }
.via-row select { flex: 1; min-width: 0; }
.via-row button { padding: 6px 10px; }
ol.route.locked { margin-bottom: 12px; }

input.copy { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85em; }

/* tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: 0.85em; color: var(--muted); }
td form { display: inline; }
.timeline .note { color: var(--muted); font-style: italic; }

.status-delivered { color: var(--ok); }

/* route */
ol.route { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
ol.route li {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 4px 0 4px 16px;
}
ol.route li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 11px;
  width: 8px;
  height: 8px;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: var(--bg);
}
ol.route li.passed::before { background: var(--muted); }
ol.route li.current::before { background: var(--accent); border-color: var(--accent); }
ol.route li.current .stop-name { font-weight: 600; }
.stop-time { margin-left: auto; font-size: 0.9em; }

.code-block { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.code-block img { border: 1px solid var(--line); background: #fff; }
.code-block p { margin: 0 0 8px; }

details { margin-bottom: 16px; }
summary { cursor: pointer; color: var(--accent); margin-bottom: 10px; }

h3 { font-size: 0.95rem; margin: 16px 0 6px; color: var(--muted); }
form.take { padding: 10px 12px; border-left: 3px solid var(--accent); margin: 16px 0; }
form.take p { margin: 0 0 8px; }

.danger-zone { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); }

/* scan page: big tap targets */
form.scan { display: flex; flex-direction: column; gap: 10px; }
form.scan p { margin: 0; }
form.scan label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
button.big { padding: 14px; text-align: left; font-size: 1.05rem; }

/* printable label */
.label { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; padding: 16px; border: 1px dashed var(--muted); }
.label img { max-width: 100%; height: auto; background: #fff; }
.label-desc { font-size: 1.3rem; font-weight: 600; margin: 0 0 8px; }

@media print {
  :root { --bg: #fff; --fg: #000; --muted: #444; }
  body { padding: 0; }
  .no-print { display: none; }
  .label { border-color: #000; }
}
