:root {
  color-scheme: light dark;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --text: #14201d;
  --muted: #64716d;
  --line: #e2e8e5;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8f0ec;
  --danger: #b42318;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --shadow: 0 6px 24px rgba(20, 32, 29, 0.14);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #151d2c;
    --text: #e8edf2;
    --muted: #93a1b0;
    --line: #253044;
    --accent: #2dd4bf;
    --accent-ink: #062a25;
    --accent-soft: #123a36;
    --danger: #f97066;
    --warn: #fdb022;
    --warn-soft: #3a2a08;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body { padding-top: var(--safe-top); min-height: 100dvh; }
h1, h2 { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
.logo { border-radius: 22%; display: block; }

/* --- login ---------------------------------------------------------------- */
.login {
  min-height: calc(100dvh - var(--safe-top));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px; max-width: 420px; margin: 0 auto;
  padding: 32px 24px calc(32px + var(--safe-bottom));
}
.login h1 { font-size: 2rem; letter-spacing: -0.02em; }
.login p { margin: 0; color: var(--muted); }

/* --- buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; min-height: 46px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; font-weight: 600; color: var(--text);
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-google { margin-top: 12px; width: 100%; box-shadow: var(--shadow); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-icon {
  border: 0; background: transparent; padding: 8px; border-radius: 10px;
  display: inline-flex; color: var(--muted); font-size: 1.4rem; line-height: 1;
}
.btn-icon:active { background: var(--line); }

/* --- top bar -------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; font-weight: 700; flex: 1; }
.status { display: flex; gap: 6px; }
.pill {
  font-size: 0.75rem; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.pill-off { background: var(--line); color: var(--muted); }
.pill-wait { background: var(--warn-soft); color: var(--warn); }
.pill-err { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.hint {
  margin: 12px 16px 0; padding: 10px 6px 10px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--text); font-size: 0.9rem;
  display: flex; align-items: center; gap: 8px;
}
.hint span { flex: 1; }

/* --- feed ----------------------------------------------------------------- */
.feed { padding: 8px 16px calc(120px + var(--safe-bottom)); max-width: 900px; margin: 0 auto; }
.empty {
  text-align: center; color: var(--muted); padding: 80px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.day h2 {
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 20px 0 10px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.card {
  display: block; width: 100%; padding: 0; border: 0; cursor: pointer;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); text-align: left;
}
.card:active { transform: scale(0.98); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card-photo { position: relative; width: 100%; aspect-ratio: 3 / 4; overflow: hidden; background: var(--line); }
.card-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.card-pending .card-photo img { opacity: 0.75; }
.badge {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--warn); color: #fff; display: grid; place-items: center; font-weight: 800;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.card-error .badge { background: var(--danger); }
.card-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.card-time { font-weight: 600; font-size: 0.95rem; }
.card-note { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- capture buttons ------------------------------------------------------ */
.fab-row {
  position: fixed; left: 0; right: 0; bottom: calc(18px + var(--safe-bottom));
  display: flex; align-items: center; justify-content: center; gap: 14px;
  pointer-events: none; z-index: 6;
}
.fab-row > * { pointer-events: auto; }
.fab {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.fab:active { transform: scale(0.94); }
.btn-library {
  position: absolute; right: 20px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 10px 14px; font-size: 0.85rem; font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

/* --- detail sheet --------------------------------------------------------- */
.sheet {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.sheet-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.sheet-title { display: flex; flex-direction: column; min-width: 0; }
.sheet-title strong { font-size: 1rem; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px; max-width: 700px; width: 100%; margin: 0 auto;
}
/* The whole receipt, fitted to the screen; tap for the zoomable full-screen view. */
.photo-stage {
  position: relative; display: block; width: 100%; padding: 0; border: 0; cursor: zoom-in;
  height: min(62dvh, 720px); border-radius: var(--radius); overflow: hidden;
  background: #111; box-shadow: var(--shadow);
}
.photo-stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
.photo-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 0.75rem; font-weight: 600; color: #fff; background: rgba(0, 0, 0, 0.55);
  padding: 4px 10px; border-radius: 999px; pointer-events: none;
}

/* --- full-screen viewer --------------------------------------------------- */
.viewer {
  position: fixed; inset: 0; z-index: 30; background: #000; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.viewer img {
  position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%;
  transform-origin: center center; will-change: transform; -webkit-user-drag: none;
}
.viewer-close {
  position: absolute; top: calc(10px + var(--safe-top)); right: 12px; z-index: 1;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, 0.18); color: #fff; display: grid; place-items: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field textarea, .field input {
  font: inherit; font-weight: 400; font-size: 1rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; resize: vertical; width: 100%;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form { display: flex; flex-direction: column; gap: 12px; width: 100%; text-align: left; }
.form .btn { width: 100%; }
.form-title { font-size: 1rem; font-weight: 700; margin: 0; }
.login .form { margin-top: 12px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow); z-index: 20; max-width: calc(100% - 32px);
}
