:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --ink: #f9fafb;
    --muted: #9ca3af;
    --line: #2c2c2e;
    --accent: #60a5fa;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
}

button { font: inherit; cursor: pointer; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
}

.top h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }

.icon-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.6rem; line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* ---------- Cards (Wallet-style stack) ---------- */
.cards { display: grid; gap: 14px; }

.card {
  position: relative;
  min-height: 200px;
  padding: 18px 18px 16px;
  border-radius: 18px;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  background: var(--card, linear-gradient(135deg, #1e3a8a, #0f172a));
}

.card .thumb {
  position: absolute;
  right: -18px; top: 18px;
  width: 42%;
  border-radius: 6px;
  opacity: 0.22;
  transform: rotate(6deg);
  pointer-events: none;
}

.card .kicker {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0.8;
}

.card .name { margin: 2px 0 14px; font-size: 1.6rem; font-weight: 700; }

.card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0 0 16px;
  position: relative;
}

.card dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.card dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.card .status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.8rem; font-weight: 600;
}

.card .status.warn { background: #f59e0b; color: #111; }
.card .status.bad { background: #dc2626; }

.card .actions { display: flex; gap: 8px; position: relative; }

.card .open {
  flex: 1;
  padding: 12px;
  border: 0; border-radius: 12px;
  background: #fff; color: #111827;
  font-weight: 700;
}

.card .open-arrival {
  flex: 1;
  padding: 12px 8px;
  border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, 0.88); color: #111827;
  font-weight: 700;
}

.card .edit {
  padding: 12px 16px;
  border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, 0.2); color: #fff;
  font-weight: 600;
}

.card.empty .open { background: rgba(255, 255, 255, 0.9); }

.hint, .foot { color: var(--muted); font-size: 0.85rem; text-align: center; }
.hint { margin: 20px 8px 0; padding: 12px; border-radius: 12px; background: var(--surface); }
.foot { margin-top: 18px; }

/* ---------- Viewer ---------- */
.viewer {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column;
  background: #111;
}

.viewer[hidden] { display: none; }

.viewer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: #1c1c1e; color: #fff;
}

.viewer-bar span { font-weight: 600; }

.viewer-tools {
  position: absolute;
  right: 12px; bottom: calc(env(safe-area-inset-bottom) + 14px);
  z-index: 11;
  display: flex; gap: 6px;
}

.pill {
  min-width: 44px; height: 40px;
  padding: 0 12px;
  border: 0; border-radius: 999px;
  background: rgba(28, 28, 30, 0.85); color: #fff;
  font-weight: 700;
}

.pages {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 80px;
}

.pages canvas {
  display: block;
  margin: 0 auto 10px;
  background: #fff;
}

.text-btn {
  padding: 8px 6px;
  border: 0; background: none;
  color: var(--accent);
  font-weight: 600;
}

.viewer .text-btn { color: #60a5fa; }
.text-btn.danger { color: var(--danger); }

/* ---------- Editor sheet ---------- */
.sheet {
  width: min(100% - 24px, 520px);
  margin: auto auto calc(env(safe-area-inset-bottom) + 12px);
  padding: 18px;
  border: 0; border-radius: 18px;
  background: var(--surface); color: var(--ink);
}

.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet h2 { margin: 0 0 12px; font-size: 1.25rem; }

.sheet label { display: block; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }

.sheet input {
  display: block; width: 100%;
  margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming into the field */
}

.sheet small { display: block; margin-top: 4px; }
.sheet label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.sheet label.check[hidden] { display: none; }
.sheet label.check input { width: auto; min-height: 0; margin: 0; }
.pages img { display: block; margin: 0 auto; background: #fff; }
.sheet .row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.sheet input { min-width: 0; min-height: 44px; }
.sheet input[type="date"] { -webkit-appearance: none; appearance: none; }

.sheet-actions { display: flex; align-items: center; gap: 8px; }
.sheet-actions span { flex: 1; }

.solid-btn {
  padding: 10px 18px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-weight: 700;
}

/* ---------- Lock ---------- */
.top-btns { display: flex; gap: 10px; }
.icon-btn svg { display: block; margin: auto; }

.lock {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.lock[hidden] { display: none; }

.lock form { width: min(100%, 340px); text-align: center; }
.lock-icon { width: 72px; height: 72px; border-radius: 16px; }
.lock h2 { margin: 12px 0 4px; }
.lock p { margin: 0 0 16px; color: var(--muted); font-size: 0.9rem; }

.lock input {
  display: block; width: 100%;
  margin-bottom: 10px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 18px; text-align: center;
}

.lock input[hidden] { display: none; }
.sheet .lock-msg { min-height: 1.3em; margin: 0 0 8px; color: var(--danger); }
.lock .lock-msg { min-height: 1.3em; margin: 4px 0 10px; color: var(--danger); }
.lock .solid-btn { width: 100%; padding: 12px; font-size: 1rem; }
.lock .text-btn { margin-top: 10px; }
.lock .text-btn[hidden] { display: none; }
.lock .faceid-btn { margin-bottom: 14px; padding: 14px; font-size: 1.05rem; }
.lock form.face-first #lock-input, .lock form.face-first #lock-submit { display: none; }
.lock .faceid-btn[hidden], .sheet .solid-btn[hidden], .foot .text-btn[hidden] { display: none; }
.sheet-note { margin: 0 0 12px; color: var(--muted); font-size: 0.85rem; }

/* While locked or in the app switcher, nothing behind the lock is drawn. */
body.locked > :not(.lock),
body.covered > :not(.lock) { visibility: hidden; }
