/* TripDiary — mobile-first styles. Light/dark follows the system setting. */
:root {
  --bg: #f7f5f2; --surface: #ffffff; --ink: #1d1b20; --muted: #6b6670; --line: #e7e3ea;
  --accent: #0f766e; --accent-ink: #ffffff; --tonal: #d7efec; --tonal-ink: #0b4f4a;
  --warn: #b45309; --danger: #b91c1c; --live: #16a34a;
  --radius: 20px; --shadow: 0 8px 24px -12px rgba(0, 0, 0, .25);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141316; --surface: #1f1d22; --ink: #ece9ef; --muted: #a39daa; --line: #34313a;
    --accent: #5eead4; --accent-ink: #06201d; --tonal: #163b38; --tonal-ink: #bff3ea;
    --warn: #f59e0b; --danger: #f87171; --live: #4ade80; --shadow: 0 8px 24px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.warn { color: var(--warn); }

/* ---------- icons ---------- */
.ic { width: 20px; height: 20px; display: inline-flex; flex: none; }
.ic svg { width: 100%; height: 100%; }
.ic.big { width: 32px; height: 32px; }

/* ---------- layout ---------- */
.view { min-height: 100dvh; display: flex; flex-direction: column; }
.content {
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: 8px 16px calc(112px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.boot { min-height: 100dvh; display: grid; place-items: center; }

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 8px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.appbar-titles { flex: 1; min-width: 0; }
.appbar-title { font-size: 19px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark {
  width: 36px; height: 36px; margin: 0 4px 0 8px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
}
.icon-btn:active { background: color-mix(in srgb, var(--ink) 10%, transparent); }
.icon-btn.light { color: #fff; }
.icon-btn.light:active { background: rgba(255, 255, 255, .15); }

.section-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 14.5px; white-space: nowrap; user-select: none;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.tonal { background: var(--tonal); color: var(--tonal-ink); }
.btn.text { color: var(--accent); padding: 0 12px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  background: var(--tonal); color: var(--tonal-ink);
}
.pill.live { background: color-mix(in srgb, var(--live) 15%, transparent); color: var(--live); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.chip {
  min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted);
}
.chip .ic { width: 16px; height: 16px; }
.chip.on { background: var(--tonal); color: var(--tonal-ink); border-color: transparent; }

/* ---------- home ---------- */
.active-card, .hero, .trip-card, .pdf-card, .day-card, .note-card, .stats {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.active-card { overflow: hidden; }
.active-cover { width: 100%; height: 150px; object-fit: cover; }
.active-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.active-title { font-size: 24px; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.nudge {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 14px;
  font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn);
}
.nudge .ic { width: 16px; height: 16px; }

.hero { padding: 24px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hero h2 { font-size: 21px; line-height: 1.25; }
.hero p { font-size: 14px; max-width: 34ch; }
.hero-art { width: 60px; height: 60px; border-radius: 18px; background: var(--tonal); color: var(--tonal-ink); display: grid; place-items: center; }

.trip-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.trip-card { display: flex; gap: 12px; align-items: center; padding: 10px; }
.trip-card:active { background: color-mix(in srgb, var(--ink) 5%, var(--surface)); }
.trip-thumb { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; flex: none; }
.trip-thumb.empty { display: grid; place-items: center; background: var(--tonal); color: var(--tonal-ink); }
.trip-info { display: flex; flex-direction: column; min-width: 0; }
.trip-info strong { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-info span { font-size: 13px; }

.home-footer { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; margin-top: 4px; }
.backup-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- trip ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 10px 0; text-align: center; }
.stats > div { display: flex; flex-direction: column; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats strong { font-size: 20px; line-height: 1.2; }
.stats span { font-size: 12px; color: var(--muted); }

.pdf-card { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.pdf-card.stale { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.pdf-head { display: flex; gap: 12px; align-items: flex-start; }
.pdf-ic { width: 40px; height: 40px; padding: 9px; border-radius: 12px; background: var(--tonal); color: var(--tonal-ink); }

.day-list { display: flex; flex-direction: column; gap: 12px; }
.day-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.day-card:active { background: color-mix(in srgb, var(--ink) 5%, var(--surface)); }
.day-card.today { border-color: var(--accent); }
.day-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.day-num { font-weight: 800; color: var(--accent); }
.day-date { font-weight: 600; }
.push { margin-left: auto; }
.strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strip-cell { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); }
.strip-cell img { width: 100%; height: 100%; object-fit: cover; }
.strip-more {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .45); color: #fff; font-weight: 700;
}
.play-mini { position: absolute; left: 4px; bottom: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; }
.play-mini .ic { width: 11px; height: 11px; }
.day-note { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.day-note.empty { display: flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: 13.5px; }
.day-note.empty .ic { width: 16px; height: 16px; }

.fab {
  position: fixed; z-index: 20;
  right: max(16px, calc((100vw - 640px) / 2 + 16px)); bottom: calc(20px + var(--safe-bottom));
  min-height: 56px; padding: 0 20px; border-radius: 18px;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .4);
}
.fab:active { transform: scale(.96); }

/* ---------- day ---------- */
.note-card { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.note-card:focus-within { border-color: var(--accent); }
.note-head { display: flex; justify-content: space-between; align-items: center; }
.note {
  width: 100%; min-height: 96px; resize: none; border: 0; outline: 0; padding: 0;
  background: transparent; color: var(--ink);
  font-family: inherit; font-size: 16px; line-height: 1.55; /* 16px avoids input zoom */
}
.note::placeholder { color: var(--muted); opacity: .8; }

.grid-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 34px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .15s ease;
}
.tile img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile.pressing { transform: scale(.93); }
.tile.is-hidden img { opacity: .35; filter: grayscale(1); }
.tile-video {
  position: absolute; left: 5px; bottom: 5px; padding: 1px 6px 1px 3px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 2px;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 11px; font-weight: 600;
}
.tile-video .ic { width: 13px; height: 13px; }
.tile-hidden { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.tile-hidden .ic { width: 26px; height: 26px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.hint { text-align: center; }
.empty-state { padding: 32px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); }
.day-nav { display: flex; justify-content: space-between; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: flex; flex-direction: column; touch-action: pan-y;
}
.viewer-top { display: flex; align-items: center; justify-content: space-between; padding: calc(6px + var(--safe-top)) 8px 6px; }
.viewer-count { font-size: 13px; opacity: .8; padding-right: 16px; }
.viewer-stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer-img.dim { opacity: .4; }
.viewer-play {
  position: absolute; width: 64px; height: 64px; border-radius: 50%; background: rgba(0,0,0,.55);
  display: grid; place-items: center; pointer-events: none;
}
.viewer-play .ic { width: 28px; height: 28px; }
.viewer-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff;
  display: grid; place-items: center;
}
.viewer-arrow.left { left: 8px; } .viewer-arrow.right { right: 8px; }
@media (pointer: coarse) { .viewer-arrow { display: none; } }
.viewer-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(14px + var(--safe-bottom));
}
.viewer-caption { font-size: 13px; opacity: .85; }
.viewer .btn.tonal { background: rgba(255,255,255,.15); color: #fff; }

/* ---------- sheets ---------- */
dialog.sheet {
  margin: auto auto 0; padding: 0; border: 0; width: 100%; max-width: 560px; max-height: 92dvh;
  background: var(--surface); color: var(--ink); border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow);
}
dialog.sheet[open] { animation: up .22s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 24px; } }
.sheet-body { padding: 10px 20px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.sheet-handle { width: 36px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 4px; }
.sheet-title { font-size: 20px; font-weight: 700; }
.sheet-text { color: var(--muted); }
.sheet-list { margin: -6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.action-list { display: flex; flex-direction: column; margin: 0 -8px; }
.action-item { min-height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 12px; border-radius: 12px; text-align: left; font-weight: 500; }
.action-item:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.action-item.danger { color: var(--danger); }

.import-details { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.import-details summary { color: var(--accent); font-weight: 600; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.import-details ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 40dvh; overflow: auto; }
.imp-row { display: flex; justify-content: space-between; gap: 8px; }
.imp-name { font-weight: 600; overflow-wrap: anywhere; }
.imp-res { flex: none; font-size: 12px; font-weight: 700; padding: 0 8px; border-radius: 999px; background: var(--line); }
.imp-res.added { background: var(--tonal); color: var(--tonal-ink); }
.imp-res.failed, .imp-res.skipped { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.imp-meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12.5px; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 16px; outline: 0;
}
.field input:focus { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13.5px; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- toast & busy ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-action { color: var(--accent); filter: brightness(1.4); font-weight: 800; letter-spacing: .04em; text-transform: uppercase; min-height: 32px; }
@media (prefers-color-scheme: dark) { .toast-action { filter: brightness(.7); } }

.busy { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 24px; }
.busy-card { width: 100%; max-width: 320px; background: var(--surface); border-radius: 20px; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.busy-label { font-weight: 600; }
.busy-bar { width: 100%; height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.busy-fill { width: 0; height: 100%; background: var(--accent); transition: width .2s ease; }
.busy-hint { font-size: 12.5px; color: var(--muted); }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
