/* ==========================================================================
   Provas de Vinho — design tokens + app styles
   Mobile-first PWA. Wine-inspired palette.
   ========================================================================== */

:root {
  /* Brand — wine palette */
  --wine-900: #2e0a16;
  --wine-800: #45102010;
  --wine-700: #6b1230;
  --wine-600: #8a1738;
  --wine-500: #a11d3a;
  --wine-400: #c24a63;
  --gold-500: #c8a24a;
  --gold-400: #d9bd77;

  --cream: #f8f2e9;
  --cream-2: #f1e7d7;
  --ink: #2a1a1f;
  --ink-soft: #5c4a50;
  --line: #e4d8c8;
  --white: #ffffff;

  --danger: #b23b3b;
  --ok: #3f7d4e;

  /* Semantic */
  --bg: var(--cream);
  --surface: var(--white);
  --surface-2: var(--cream-2);
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --primary: var(--wine-600);
  --primary-strong: var(--wine-700);
  --accent: var(--gold-500);
  --border: var(--line);

  /* Type */
  --font-head: "Georgia", "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Spacing / radius / shadow */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --r-sm: 8px; --r-md: 14px; --r-lg: 22px; --r-full: 999px;
  --shadow-1: 0 1px 3px rgba(46,10,22,.08), 0 1px 2px rgba(46,10,22,.06);
  --shadow-2: 0 6px 20px rgba(46,10,22,.12);
  --header-h: 56px;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a0d12;
    --surface: #26141a;
    --surface-2: #301a21;
    --text: #f3e9df;
    --text-soft: #c3aeb2;
    --border: #3c2630;
    --primary: #b8324f;
    --primary-strong: #c24a63;
  }
}

* { box-sizing: border-box; }

/* Inline line icons */
svg.ic { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -0.18em; flex: 0 0 auto; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; line-height: 1.2; }
a { color: var(--primary); }
img { max-width: 100%; display: block; }

/* Layout ------------------------------------------------------------------ */
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  padding-top: env(safe-area-inset-top);
  background: var(--primary-strong);
  color: var(--cream);
  box-shadow: var(--shadow-1);
}
.app-header .brand { display: flex; align-items: center; gap: var(--sp-3);
  font-family: var(--font-head); font-weight: 700; font-size: 1.1rem; min-width: 0; }
.app-header .brand-logo { height: 40px; width: auto; flex: 0 0 auto; }
.app-header .brand-name { position: relative; padding-left: var(--sp-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .brand-name::before { content: ""; position: absolute; left: 0; top: 50%;
  transform: translateY(-50%); height: 22px; width: 1px; background: rgba(248,242,233,.35); }
@media (max-width: 380px) { .app-header .brand-name { display: none; } }
.app-header .header-action {
  background: transparent; border: 0; color: var(--cream);
  font-size: 1.4rem; cursor: pointer; line-height: 1; padding: var(--sp-2);
}

main { max-width: 720px; margin: 0 auto; padding: var(--sp-4); }

.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Bottom nav -------------------------------------------------------------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(46,10,22,.06);
}
.bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-soft); font-size: .72rem; font-family: var(--font-body);
}
.bottom-nav button svg { width: 24px; height: 24px; }
.bottom-nav button.active { color: var(--primary); }
.bottom-nav .fab-slot { flex: 0 0 auto; position: relative; width: 72px; }
.bottom-nav .fab {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  width: 60px; height: 60px; border-radius: var(--r-full);
  background: var(--primary); color: var(--cream);
  border: 4px solid var(--surface);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2); cursor: pointer;
}
.bottom-nav .fab svg { width: 30px; height: 30px; }

/* Cards ------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-4);
  box-shadow: var(--shadow-1); margin-bottom: var(--sp-4);
}
.section-title { display: flex; align-items: baseline; justify-content: space-between;
  margin: var(--sp-5) 0 var(--sp-3); }
.section-title h2 { font-size: 1.25rem; margin: 0; }
.muted { color: var(--text-soft); }
.small { font-size: .82rem; }

/* Tasting list card */
.tasting-item {
  display: flex; gap: var(--sp-3); align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-3);
  margin-bottom: var(--sp-3); box-shadow: var(--shadow-1);
  cursor: pointer; text-align: left; width: 100%;
}
.tasting-item .thumb {
  width: 52px; height: 52px; border-radius: var(--r-sm); flex: 0 0 auto;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  color: var(--primary); overflow: hidden;
}
.tasting-item .thumb svg.ic { width: 26px; height: 26px; }
.tasting-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tasting-item .ti-body { flex: 1; min-width: 0; }
.tasting-item .ti-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tasting-item .ti-meta { font-size: .8rem; color: var(--text-soft); }
.tasting-item .ti-rating { color: var(--accent); font-size: .95rem; white-space: nowrap; }

/* Type badge */
.badge { display: inline-block; font-size: .72rem; padding: 2px 8px;
  border-radius: var(--r-full); background: var(--surface-2); color: var(--text-soft); }
.badge.tinto { background: #5a1023; color: #f3d9df; }
.badge.branco { background: #e9e0c2; color: #6b5b1f; }
.badge.rose { background: #f0c9cf; color: #8a2b45; }
.badge.espumante { background: #dfeaf0; color: #2b5a6b; }

/* Forms ------------------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: var(--sp-2); }
.field .hint { font-weight: 400; color: var(--text-soft); font-size: .8rem; }
input[type=text], input[type=number], input[type=search],
input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 12px 14px; font-size: 1rem; font-family: var(--font-body);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(161,29,58,.15);
}
.field-row { display: flex; gap: var(--sp-3); }
.field-row > * { flex: 1; }

/* Chips (aroma notes / type select) */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  padding: 8px 14px; border-radius: var(--r-full); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: .88rem; user-select: none;
}
.chip.selected { background: var(--primary); color: var(--cream); border-color: var(--primary); }

/* Sliders */
.slider-field { margin-bottom: var(--sp-4); }
.slider-field .slider-top { display: flex; justify-content: space-between; align-items: baseline; }
.slider-field label { font-weight: 600; font-size: .9rem; }
.slider-field .slider-val { font-size: .85rem; color: var(--primary); font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--primary); }
.slider-scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-soft); }

/* Star rating */
.stars { display: flex; gap: 6px; font-size: 2rem; }
.stars .star { cursor: pointer; color: var(--border); line-height: 1; }
.stars .star.on { color: var(--accent); }

/* Buttons ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 13px 20px; font-size: 1rem; font-weight: 600; font-family: var(--font-body);
  border-radius: var(--r-full); border: 1px solid transparent; cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--cream); }
.btn-primary:active { background: var(--primary-strong); }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 24px; font-size: 1.05rem; }

.form-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }
.form-actions .btn { flex: 1; }

/* Empty state */
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-soft); }
.empty .emoji { font-size: 3rem; }
.empty .empty-ic svg.ic { width: 54px; height: 54px; color: var(--border); stroke-width: 1.4; }
.detail-hero .hero-ic svg.ic { width: 72px; height: 72px; color: var(--primary); }
.empty h3 { margin: var(--sp-3) 0 var(--sp-2); color: var(--text); }

/* Search / autocomplete */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 var(--r-sm) var(--r-sm); max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow-2);
}
.ac-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.active { background: var(--surface-2); }
.ac-item .ac-meta { font-size: .78rem; color: var(--text-soft); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-4); text-align: center; }
.stat .num { font-family: var(--font-head); font-size: 1.8rem; color: var(--primary); font-weight: 700; }
.stat .lbl { font-size: .78rem; color: var(--text-soft); }

/* Detail view */
.detail-hero { text-align: center; margin-bottom: var(--sp-4); }
.detail-hero img { max-height: 240px; margin: 0 auto var(--sp-3); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.detail-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-row .k { color: var(--text-soft); }
.detail-row .v { font-weight: 600; text-align: right; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--cream); padding: 12px 20px;
  border-radius: var(--r-full); box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100; font-size: .9rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Photo picker */
.photo-picker { display: flex; align-items: center; gap: var(--sp-3); }
.photo-preview { width: 84px; height: 84px; border-radius: var(--r-sm); object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border); }
.hidden { display: none !important; }

/* Home masthead + discover ------------------------------------------------ */
.home-masthead { text-align: center; padding: var(--sp-4) 0 var(--sp-3); }
.home-masthead .home-logo { height: 84px; width: auto; margin: 0 auto var(--sp-1); }
.home-masthead .home-tag { margin: 0; color: var(--text-soft); font-family: var(--font-head);
  font-style: italic; font-size: .95rem; }

.discover-card {
  display: flex; align-items: center; gap: var(--sp-3); text-decoration: none;
  color: var(--cream); border-radius: var(--r-md); padding: var(--sp-4);
  margin-bottom: var(--sp-3); box-shadow: var(--shadow-2);
  background: linear-gradient(135deg, var(--wine-700), var(--wine-500));
  position: relative; overflow: hidden;
}
.discover-card::after { content: ""; position: absolute; right: -30px; top: -30px;
  width: 120px; height: 120px; border-radius: 50%; background: rgba(216,189,119,.18); }
.discover-icon { flex: 0 0 auto; z-index: 1; display: flex; }
.discover-icon svg.ic { width: 30px; height: 30px; stroke-width: 1.6; }
.discover-body { flex: 1; min-width: 0; z-index: 1; }
.discover-title { display: block; font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; }
.discover-sub { display: block; font-size: .85rem; opacity: .9; }
.discover-arrow { font-size: 1.6rem; opacity: .8; z-index: 1; }

.discover-card.discover-alt { background: linear-gradient(135deg, #3a2b12, #6b5320); }

/* Story share overlay ----------------------------------------------------- */
.story-overlay { position: fixed; inset: 0; z-index: 210; background: rgba(20,6,12,.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-4); gap: var(--sp-4); }
.story-box { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4);
  max-height: 100%; }
.story-box img { max-height: 72vh; width: auto; border-radius: 18px; box-shadow: var(--shadow-2); }
.story-actions { display: flex; gap: var(--sp-3); }

/* Digitalizer CTA --------------------------------------------------------- */
.scan-cta { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  background: var(--surface-2); }
.scan-cta .btn { flex: 0 0 auto; white-space: nowrap; }

/* Scan overlay */
.scan-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(30,10,16,.6);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4); }
.scan-box { background: var(--surface); border-radius: var(--r-lg); padding: var(--sp-6) var(--sp-5);
  text-align: center; width: 100%; max-width: 320px; box-shadow: var(--shadow-2); }
.scan-spinner { width: 46px; height: 46px; margin: 0 auto var(--sp-4); border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-progress { height: 8px; background: var(--surface-2); border-radius: var(--r-full);
  overflow: hidden; margin: var(--sp-3) 0 var(--sp-4); }
.scan-progress > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* Learn / book ------------------------------------------------------------ */
.learn-hero { text-align: center; padding: var(--sp-4) 0 var(--sp-2); }
.learn-hero .learn-logo { height: 96px; width: auto; margin: 0 auto var(--sp-2); }
.learn-hero h2 { margin: var(--sp-2) 0 4px; }
.learn-card { display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-3); box-shadow: var(--shadow-1); cursor: pointer; }
.learn-card-icon { flex: 0 0 auto; display: flex; color: var(--primary); }
.learn-card-icon svg.ic { width: 28px; height: 28px; }
.learn-card-body { flex: 1; min-width: 0; }
.learn-card-title { display: block; font-weight: 600; font-family: var(--font-head); }
.learn-card-sum { display: block; font-size: .82rem; color: var(--text-soft); }
.learn-card-arrow { color: var(--text-soft); font-size: 1.4rem; }

.btn-back { margin-bottom: var(--sp-3); }
.article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-5); box-shadow: var(--shadow-1); }
.article .article-title { font-size: 1.5rem; margin: 0 0 var(--sp-4); color: var(--primary-strong); }
.article h3 { font-size: 1.1rem; margin: var(--sp-5) 0 var(--sp-2); color: var(--primary); }
.article p { margin: 0 0 var(--sp-3); }
.article ul.cols { columns: 2; list-style: none; padding: 0; }
.article ul.cols li { padding: 3px 0; }
.article .glass-list, .article .grape-list { margin: 0; }
.grape-list dt { font-weight: 700; margin-top: var(--sp-3); font-family: var(--font-head); }
.grape-list dt span { font-weight: 400; font-size: .78rem; color: var(--accent); margin-left: 6px; }
.grape-list dd { margin: 2px 0 0; color: var(--text-soft); }
.temp-table { width: 100%; border-collapse: collapse; margin: var(--sp-3) 0; }
.temp-table th, .temp-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.temp-table th { color: var(--text-soft); font-size: .8rem; }

/* Tablet / desktop -------------------------------------------------------- */
@media (min-width: 768px) {
  :root { --nav-h: 68px; }
  main { padding: var(--sp-5) var(--sp-5); }
  .home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); align-items: start; }
}
