/* Pour Decision — design tokens + app shell.
   Dark mode is the default (mostly used in the evening); a light toggle sets
   [data-theme="light"] on <html>. Deep bottle-green accent with aged-gold
   highlights throughout — the "cellar glass and gilt" palette. */

:root {
  /* brand — bottle green + aged gold */
  --green: #2f9268;
  --green-bright: #45c092;
  --green-dim: #1b4d39;
  --gold: #d9a441;

  /* dark (default) — neutral warm charcoal, no colour cast */
  --bg: #14181a;
  --surface: #1c2224;
  --surface-2: #26302d;
  --border: #33403b;
  --text: #eef2ef;
  --text-dim: #9aada6;
  --accent: var(--green);
  --accent-text: #ffffff;
  --danger: #d1795b;
  --star: var(--gold);

  --radius: 14px;
  --radius-sm: 10px;
  --tab-h: 64px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f2f5f2;
  --surface: #ffffff;
  --surface-2: #e8efe9;
  --border: #d5e0d8;
  --text: #17231d;
  --text-dim: #5d6f66;
  --accent: #1f7a54;
  --green-bright: #1f7a54;
  --accent-text: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* keyboard focus ring — visible, accent-coloured, never on mouse click */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ---- app frame ---- */

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#view {
  flex: 1;
  padding: var(--pad);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin: 8px 0 20px;
}
.app-title .glass { color: var(--accent); }

/* ---- bottom tab bar ---- */

#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}
#tabbar.hidden { display: none; }
#tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
}
#tabbar button .ico { font-size: 1.25rem; line-height: 1; }
#tabbar button {
  font-size: 0.72rem;
  gap: 5px;
  transition: color 0.15s ease;
}
#tabbar button .ico { line-height: 0; }
#tabbar button .ico svg {
  width: 23px;
  height: 23px;
  display: block;
  stroke: currentColor;
}
#tabbar button.active { color: var(--accent); }
#tabbar button.active .ico svg { stroke-width: 2; }
#tabbar button:active { color: var(--text); }

/* ---- generic controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1rem;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); filter: brightness(0.92); }
.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.ghost {
  background: none;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn:disabled { opacity: 0.5; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.input.flagged { border-color: var(--gold); background: var(--surface-2); }
textarea { resize: vertical; min-height: 80px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.muted { color: var(--text-dim); }
.center { text-align: center; }
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 24px;
}
.empty .empty-ico {
  color: var(--border);
  margin-bottom: 14px;
}
.empty .empty-ico svg { width: 44px; height: 44px; display: inline-block; stroke: currentColor; }
.empty .empty-title { color: var(--text); font-weight: 600; }

.svg-ico { display: inline-flex; line-height: 0; }

/* field flag — replaces the old emoji flag glyph */
.flag-mark {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: 7px;
  vertical-align: middle;
}

/* transient toast — replaces blocking alert() */
#toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  max-width: 528px;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- PIN screen ---- */

#pin-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  z-index: 50;
}
#pin-screen.hidden { display: none; }
#pin-screen .brand { font-size: 1.8rem; font-weight: 700; }
#pin-screen .brand .glass { color: var(--accent); }
#pin-input {
  width: 200px;
  text-align: center;
  letter-spacing: 8px;
  font-size: 1.4rem;
}
#pin-error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 0;
  color: var(--text-dim);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ===== demo banner ===== */
.demo-banner {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.demo-banner button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.72rem;
}

/* ===== camera viewfinder ===== */
.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; }
.viewfinder .cam-fallback {
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
  font-size: 0.85rem;
}
/* label-shaped guide overlay */
.guide {
  position: absolute;
  inset: 18% 14%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.guide::after {
  content: "Line the label up here";
  position: absolute;
  bottom: -28px;
  left: 0; right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.75rem;
}
.capture-row { display: flex; gap: 10px; margin-top: 14px; }
.capture-btn {
  width: 70px; height: 70px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  background: var(--surface);
  margin: 16px auto 0;
  display: block;
}

/* ===== session bar (Add to rack batch) ===== */
.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.session-bar .count { font-weight: 600; }

/* ===== match cards ===== */
.section-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 6px 0 8px;
}
.match-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  width: 100%;
  text-align: left;
  color: var(--text);
}
.match-card:active { background: var(--surface-2); }

/* ===== list rows (cellar / history / timeline) ===== */
.thumb {
  width: 46px; height: 60px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
  flex: 0 0 auto;
}
.thumb.sm { width: 38px; height: 50px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  width: 100%;
  text-align: left;
  color: var(--text);
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.row .meta { font-size: 0.78rem; color: var(--text-dim); text-align: right; white-space: nowrap; }
.row-action {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
  flex: 0 0 auto;
}

/* ===== stars ===== */
.stars { color: var(--star); letter-spacing: 2px; }
.stars .off { color: var(--border); }
.starpick {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 2.6rem;
  margin: 20px 0;
}
.starpick span { color: var(--border); cursor: pointer; }
.starpick span.on { color: var(--star); }

/* ===== chips / badges / filters ===== */
.type-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.status-chip {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.status-chip.cellared { background: var(--green-dim); color: #cdeadd; }
.status-chip.opened { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters select { width: auto; flex: 1; min-width: 120px; padding: 9px 10px; font-size: 0.85rem; }

/* ===== timeline (wine detail) ===== */
.timeline-item {
  border-left: 2px solid var(--border);
  padding: 0 0 16px 14px;
  margin-left: 6px;
  position: relative;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -7px; top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline-item:last-child { border-left-color: transparent; }
.detail-head { display: flex; gap: 14px; margin-bottom: 18px; }
.detail-head .thumb { width: 72px; height: 96px; }
.detail-head h2 { margin: 0 0 4px; font-size: 1.2rem; }

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  padding: 4px 0;
  margin-bottom: 8px;
  width: auto;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { height: 8px; }
h2.screen { font-size: 1.35rem; margin: 4px 0 16px; }
