:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #646b78;
  --line: #e3e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e6eefd;
  --done: #16a34a;
  --danger: #dc2626;
  --radius: 14px;
  --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d23;
    --text: #eceef2;
    --muted: #9aa1ad;
    --line: #2b2f37;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --accent-soft: #1d2740;
    --done: #34c759;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

/* Top bar */
.bar { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin-bottom: 8px; }
.bar h1 { flex: 1; margin: 0; font-size: 26px; line-height: 1.2; overflow-wrap: anywhere; }
.bar .title-wrap { flex: 1; min-width: 0; }
.bar .title-wrap h1 { font-size: 22px; }
.sub { color: var(--muted); font-size: 15px; margin-top: 2px; }

/* Buttons */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--accent); padding: 0 10px; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  border: 0; border-radius: 12px; background: transparent; color: var(--accent);
  font-size: 28px; line-height: 1;
}
.btn:active, .icon-btn:active { opacity: 0.7; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); }
.trip-list { display: grid; gap: 10px; margin-top: 14px; }
.trip-card {
  display: block; width: 100%; text-align: left; border: 0; padding: 14px 16px;
  background: var(--card); border-radius: var(--radius);
}
.trip-card .name { font-weight: 600; font-size: 18px; }
.trip-card .meta { color: var(--muted); font-size: 15px; }
.trip-card .progress { margin-top: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Progress */
.progress-row { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--muted); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.progress > span { display: block; height: 100%; background: var(--done); border-radius: 99px; transition: width 0.2s; }
.summary { padding: 14px 16px; margin-bottom: 12px; }
.summary .count { color: var(--text); font-weight: 600; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; min-height: 32px; }
.toggle input {
  appearance: none; flex: none; position: relative; margin: 0;
  width: 50px; height: 30px; border-radius: 99px; background: var(--line); transition: background 0.15s;
}
.toggle input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.toggle input:checked { background: var(--done); }
.toggle input:checked::after { transform: translateX(20px); }
.toggle input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.all-done { color: var(--done); font-weight: 600; margin-top: 10px; }

/* Add bar */
.add { display: flex; gap: 8px; margin-bottom: 16px; }
/* The packing-list add bar stays pinned to the top while scrolling. The
   solid background and padding hide the list scrolling underneath it. */
.add.sticky {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -16px 8px; padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}
.add input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.add input:focus, .field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Sections and items */
.section { margin-bottom: 16px; }
.section h2 {
  display: flex; justify-content: space-between; margin: 0 4px 6px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.items { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .check {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px;
  min-height: 52px; padding: 8px 4px 8px 16px; border: 0; background: transparent; text-align: left;
}
.box {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--muted); display: grid; place-items: center;
}
.item.packed .box { background: var(--done); border-color: var(--done); }
.item.packed .box::after { content: ""; width: 7px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-1px) rotate(45deg); }
.item .label { overflow-wrap: anywhere; }
.item.packed .label { color: var(--muted); text-decoration: line-through; }
.qty {
  flex: none; min-width: 56px; min-height: 36px; padding: 0 10px; margin-left: 4px;
  border: 0; border-radius: 99px; background: var(--bg);
  font-size: 15px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums;
}
.item.partial .qty { background: var(--accent-soft); color: var(--accent); }
.item.packed .qty { color: var(--done); }
.item.partial .box { border-color: var(--done); background: linear-gradient(to top, var(--done) 50%, transparent 50%); }
.item .edit { flex: none; color: var(--muted); font-size: 18px; }

.todo-heading { margin-top: 28px; }

/* Bottom sheet dialog */
.sheet {
  width: min(560px, 100%); max-width: 100%; max-height: 90dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--card); color: var(--text);
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet form { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.sheet h3 { margin: 0; font-size: 20px; }
.sheet p { margin: 0; color: var(--muted); }
.field { display: grid; gap: 6px; font-size: 15px; color: var(--muted); }
.field input, .field select {
  min-height: var(--tap); padding: 0 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
/* iOS gives date inputs a wide intrinsic size; keep them inside their column */
.field input[type="date"] { -webkit-appearance: none; appearance: none; display: block; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; width: 80px; flex: none; }
.stepper .icon-btn { background: var(--accent-soft); }
.actions { display: grid; gap: 8px; margin-top: 4px; }
.menu { display: grid; gap: 4px; }
.menu .btn { text-align: left; background: transparent; color: var(--text); font-weight: 500; padding: 0 8px; }
.menu .btn.danger { color: var(--danger); }

/* Login */
.login { min-height: 80dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; }
.login form { width: min(340px, 100%); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; text-align: center; }
.login h1 { margin: 0 0 4px; }
.login input {
  width: 100%; min-width: 0; min-height: 60px; text-align: center; font-size: 28px; letter-spacing: 0.4em;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
}
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* Sync status pill */
.status {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 8px 14px; border-radius: 99px; background: var(--text); color: var(--bg);
  font-size: 14px; z-index: 10; white-space: nowrap;
}
