:root {
  --wine: #7b1e3a;
  --wine-soft: #f6e9ed;
  --bg: #f7f5f3;
  --card: #ffffff;
  --text: #1f1b1c;
  --muted: #6f6669;
  --line: #e7e1e3;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --bad: #b3261e;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --t-tinto: #7b1e3a; --t-branco: #d9c36a; --t-rose: #e8a0b0; --t-espumante: #c9b98a;
  --t-porto: #5a2333; --t-outro: #9b8f93;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --wine: #d1607f; --wine-soft: #3a1f27; --bg: #141112; --card: #1e1a1b;
    --text: #f1eced; --muted: #a99fa2; --line: #332d2f; --ok: #6cc28f; --warn: #e3a64a; --bad: #ef7a72;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
a { color: var(--wine); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--wine); color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }
#topbar-extra { font-size: .85rem; opacity: .9; }

main { max-width: 860px; margin: 0 auto; padding: 14px 16px 24px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 0 6px; font-size: .72rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tabbar a .ic { font-size: 1.3rem; line-height: 1.3; }
.tabbar a.active { color: var(--wine); font-weight: 600; }

/* lista */
.stats { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px; scrollbar-width: none; }
.stat { background: var(--card); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); min-width: 92px; flex: none; }
.stat b { display: block; font-size: 1.25rem; }
.stat span { font-size: .75rem; color: var(--muted); }

.search { display: flex; gap: 8px; margin-bottom: 8px; }
.search input { flex: 1; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 10px; padding: 2px 16px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: .85rem; cursor: pointer;
}
.chip.on { background: var(--wine); border-color: var(--wine); color: #fff; }

.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.wine {
  min-width: 0; display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 14px;
  padding: 12px; box-shadow: var(--shadow); color: var(--text);
}
.wine .thumb {
  width: 44px; height: 60px; border-radius: 8px; flex: none; background: var(--wine-soft);
  display: grid; place-items: center; font-size: 1.4rem; overflow: hidden;
}
.wine .thumb img { width: 100%; height: 100%; object-fit: cover; }
.wine .body { flex: 1; min-width: 0; }
.wine .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wine .sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wine .tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.wine .qty { text-align: center; flex: none; min-width: 44px; }
.wine .qty b { display: block; font-size: 1.3rem; line-height: 1; }
.wine .qty span { font-size: .7rem; color: var(--muted); }
.wine.zero { opacity: .55; }

.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--wine-soft); color: var(--wine); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.tag.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.tag.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 3rem; }

/* detalhe */
.hero { display: flex; gap: 14px; align-items: flex-start; }
.hero .photo {
  width: 96px; height: 132px; border-radius: 12px; background: var(--wine-soft); flex: none; overflow: hidden;
  display: grid; place-items: center; font-size: 2.4rem; cursor: pointer; position: relative;
}
.hero .photo img { width: 100%; height: 100%; object-fit: cover; }
.hero .photo .cam { position: absolute; right: 4px; bottom: 4px; font-size: .9rem; background: rgba(0,0,0,.45); color: #fff; border-radius: 8px; padding: 1px 5px; }
.hero .info { flex: 1; min-width: 0; }
.stockbox {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px;
  box-shadow: var(--shadow); margin-top: 14px;
}
.stockbox .n { font-size: 2rem; font-weight: 700; line-height: 1; }
.stockbox .grow { flex: 1; min-width: 0; }
.stockbox .btns { display: flex; gap: 8px; }
@media (max-width: 480px) {
  .stockbox { flex-wrap: wrap; }
  .stockbox .btns { flex-basis: 100%; }
  .stockbox .btns .btn { flex: 1; min-height: 44px; }
}
.card { background: var(--card); border-radius: 14px; padding: 4px 14px; box-shadow: var(--shadow); }
.kv { display: grid; grid-template-columns: 40% 60%; padding: 9px 0; border-bottom: 1px solid var(--line); gap: 8px; }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.score { font-weight: 700; color: var(--wine); min-width: 58px; }
.tasting { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tasting:last-child { border-bottom: 0; }
.tasting p { margin: 4px 0; }
.tasting .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rating { font-weight: 700; background: var(--wine); color: #fff; border-radius: 8px; padding: 1px 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* formulários */
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--wine) 45%, transparent); border-color: var(--wine); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; margin-top: 18px; color: var(--wine); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.iconbtn { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px; }

.fab {
  position: fixed; right: 18px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 9;
  width: 56px; height: 56px; border-radius: 50%; background: var(--wine); color: #fff; font-size: 1.8rem;
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* modal */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px));
  background: var(--card); color: var(--text); max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
#modal-form { padding: 18px; }
#modal-form h3 { margin: 0 0 6px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn.primary { flex: 1 1 100%; }
.modal-actions .btn { flex: 1; white-space: nowrap; }
.stepper { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 10px 0; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; font-size: 1.4rem; }
.stepper output { font-size: 2rem; font-weight: 700; min-width: 50px; text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: .95; }

table.preview { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.preview th, table.preview td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tablewrap { overflow-x: auto; background: var(--card); border-radius: 14px; padding: 6px 10px; box-shadow: var(--shadow); }
.errors { color: var(--bad); font-size: .9rem; }
.dropzone {
  display: block; border: 2px dashed var(--line); border-radius: 14px; padding: 24px; text-align: center;
  color: var(--muted); cursor: pointer; background: var(--card);
}

@media (min-width: 700px) {
  .list { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .fab { right: calc(50% - 410px); }
}

/* leitura de rótulos */
.topbar-right { display: flex; align-items: center; gap: 12px; }
.gear { color: #fff; font-size: 1.25rem; line-height: 1; opacity: .9; }
.labelbox { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 6px; }
.labelbox-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.shots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.shot {
  margin: 0; height: 130px; border: 2px dashed var(--line); border-radius: 12px;
  display: grid; place-items: center; text-align: center; color: var(--muted); cursor: pointer;
  background: var(--wine-soft) center / cover no-repeat; font-size: .85rem;
}
.shot::before { content: "📷"; display: block; font-size: 1.6rem; }
.shot.has { border-style: solid; border-color: var(--wine); }
.shot.has span, .shot.has::before { display: none; }
#label-status { margin-top: 8px; }
input.filled, select.filled, textarea.filled { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 6%, var(--card)); }

/* harmonizações e faturas */
.pairbtn { margin-top: 14px; }
.pairout { margin-top: 10px; }
.pairout .row { align-items: flex-start; }
.invlist { display: grid; gap: 8px; margin-top: 10px; }
.invitem { background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.invhead { display: flex; gap: 10px; align-items: center; }
.invhead .inc { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--wine); }
.invmeta { margin: 4px 0 0 32px; }
.invgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; margin-left: 32px; }
.invgrid label { margin: 6px 0 2px; font-size: .75rem; }
.invgrid input, .invgrid select { min-height: 38px; padding: 6px 8px; font-size: .9rem; }
.invitem.off { opacity: .45; }
.tabbar a { font-size: .68rem; }

/* mudar de local */
.loc-other { margin-top: 6px; }
.movelink { margin-bottom: 10px; }
.movehead > div { min-width: 0; }
.movelist { display: grid; gap: 8px; }
.moveitem { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid transparent; border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.moveitem.on { border-color: var(--wine); }
.moveitem .body { flex: 1; min-width: 0; }
.moveitem .title { font-weight: 600; overflow-wrap: anywhere; }
.moveitem output { min-width: 26px; text-align: center; font-weight: 700; font-size: 1.15rem; }
.moveitem .rnd { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; flex: none; }
.movebar { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); }
@media (max-width: 480px) {
  .movehead { grid-template-columns: minmax(0, 1fr); }
  .moveitem { flex-wrap: wrap; }
  .moveitem .body { flex-basis: 100%; }
  .moveitem [data-all] { margin-right: auto; }
}
.movebar .btn:disabled { opacity: 1; background: var(--line); border-color: var(--line); color: var(--muted); }

/* versão de telefone */
[hidden] { display: none !important; }
.no-ai [data-ai], .welcome .tabbar, .welcome .gear { display: none !important; }
.no-ai .shots { grid-template-columns: 1fr; }
.card.pad { padding: 12px 14px; }
.card.pad p { margin: 6px 0; }
.notice { display: flex; gap: 12px; align-items: center; background: var(--wine-soft); color: var(--text); border-radius: 14px; padding: 10px 14px; margin-bottom: 10px; font-size: .9rem; }
.choice { flex-direction: column; align-items: flex-start; text-align: left; padding: 12px 16px; margin-bottom: 8px; gap: 2px; }
.choice .small { font-weight: 400; }
.switch { display: flex; align-items: center; gap: 10px; margin: 4px 0; font-size: 1rem; color: var(--text); }
.switch input { width: 24px; height: 24px; min-height: 0; accent-color: var(--wine); }
.steps { padding-left: 22px; }
.steps li { margin: 10px 0; }
label.btn { margin: 0; }
.update { position: fixed; left: 16px; right: 16px; top: calc(64px + env(safe-area-inset-top)); z-index: 40; border: 0; border-radius: 12px; padding: 12px; font: inherit; font-weight: 600; background: var(--wine); color: #fff; }
