/* Garrafeira — interface móvel, pensada para usar numa garagem mal iluminada:
   alvos grandes, contraste alto, poucos passos por garrafa. */

:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe7dc;
  --ink: #1f1a17;
  --ink-2: #5d534c;
  --line: #ddd2c4;
  --accent: #7b1e3a;
  --accent-ink: #ffffff;
  --accent-soft: #f3dfe4;
  --ok: #2f6b3a;
  --warn: #9a5b00;
  --warn-soft: #fbecd2;
  --danger: #a3242b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 26, 23, .06), 0 6px 20px rgba(31, 26, 23, .06);
  --tabbar-h: 64px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151112;
    --surface: #1f191b;
    --surface-2: #2a2224;
    --ink: #f2ece7;
    --ink-2: #b8ada6;
    --line: #3a3033;
    --accent: #d26a86;
    --accent-ink: #1a0b10;
    --accent-soft: #3b2129;
    --ok: #79c08a;
    --warn: #e7b25a;
    --warn-soft: #3a2c16;
    --danger: #ef7a80;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151112; --surface: #1f191b; --surface-2: #2a2224; --ink: #f2ece7; --ink-2: #b8ada6;
  --line: #3a3033; --accent: #d26a86; --accent-ink: #1a0b10; --accent-soft: #3b2129;
  --ok: #79c08a; --warn: #e7b25a; --warn-soft: #3a2c16; --danger: #ef7a80; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); letter-spacing: .02em; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- topo */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--accent); color: var(--accent-ink);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #2a1219; color: #f2ece7; } }
.cellar-btn {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: none; border: 0; padding: 6px 0; cursor: pointer; color: inherit;
}
.cellar-name { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: inherit;
  border-radius: 999px; padding: 4px 10px; font-size: .8rem; cursor: pointer; white-space: nowrap;
}
.sync-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #c9c0b8; }
.sync-badge.online .dot { background: #7fdc95; }
.sync-badge.pending .dot { background: #ffc35a; }
.sync-badge.busy .dot { background: #ffc35a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------------------------------------------------------------- vista */
.view {
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 760px; margin: 0 auto; outline: none;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 18px 0 8px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card.warn { background: var(--warn-soft); border-color: transparent; }

/* ---------------------------------------------------------------- botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 72px; font-size: 1.15rem; border-radius: 16px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.light { background: #fff; color: #111; border-color: #fff; }
.btn.ghost-light { background: rgba(0,0,0,.35); color: #fff; border-color: rgba(255,255,255,.4); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------------------------------------------------------------- formulários */
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--ink-2); }
input[type=text], input[type=number], input[type=url], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 16px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- listas */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 64px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.thumb {
  width: 48px; height: 48px; border-radius: 10px; flex: none; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; color: var(--ink-2);
}
.thumb svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: .85rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-end { text-align: right; flex: none; }
.count { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); vertical-align: middle; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.empty { text-align: center; padding: 32px 16px; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { font-size: .72rem; color: var(--ink-2); }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .9rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.pos-card { display: flex; align-items: center; gap: 12px; }
.pos-code { font: 700 1.6rem/1 var(--mono); }

/* ---------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--ink-2); font-size: .7rem; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* ---------------------------------------------------------------- scanner */
.scanner { position: fixed; inset: 0; z-index: 35; background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; left: 50%; top: 45%; width: min(70vw, 70vh, 340px); aspect-ratio: 1;
  transform: translate(-50%, -50%); border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.9);
}
.scan-top { position: absolute; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 14px) 16px 0; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.scan-pos { background: rgba(0,0,0,.6); color: #fff; padding: 8px 14px; border-radius: 999px; font-weight: 600; }
.scan-pos b { font-family: var(--mono); }
.scan-flash { min-height: 40px; color: #fff; font-weight: 700; font-size: 1.05rem; text-align: center; text-shadow: 0 1px 3px #000; }
.scan-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px);
}

/* ---------------------------------------------------------------- folha (bottom sheet) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-width: 760px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-close { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: none; font-size: 1.2rem; line-height: 1; }
.photo-big { width: 100%; max-height: 46vh; object-fit: contain; border-radius: 12px; background: var(--surface-2); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); z-index: 40;
  transform: translateX(-50%) translateY(-12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; max-width: calc(100vw - 32px); transition: .2s; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- leitor Bluetooth */
.hid-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.hid-input {
  font-family: var(--mono); text-align: center; letter-spacing: .04em;
  border-style: dashed !important; background: var(--surface-2) !important;
}
.hid-input:focus { outline: 2px solid var(--accent); border-style: solid !important; }

.scanner.barcode .scan-frame { aspect-ratio: auto; width: min(88vw, 460px); height: min(22vh, 160px); }

/* ---------------------------------------------------------------- desfazer */
.undo-bar {
  position: fixed; left: 12px; right: 12px; z-index: 39; max-width: 640px; margin: 0 auto;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px;
  background: var(--ink); color: var(--bg); border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.undo-bar .undo-msg { flex: 1; font-size: .92rem; min-width: 0; }
.undo-bar button { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 10px 14px; border-radius: 10px; cursor: pointer; }
.stats.two { grid-template-columns: repeat(3, 1fr); }

/* ---------------------------------------------------------------- modo simples */
html.simple { font-size: 18px; }
html.simple body { font-size: 18px; }
.simple .adv,
.simple .tabbar [data-view="locations"],
.simple .tabbar [data-view="labels"] { display: none !important; }
.simple .tabbar { grid-template-columns: repeat(3, 1fr); }
.simple .tabbar button { font-size: .8rem; }
.simple .tabbar svg { width: 28px; height: 28px; }
.simple .btn { min-height: 56px; }
.simple .btn.big { min-height: 84px; font-size: 1.3rem; }
.simple .item { min-height: 72px; }
.simple .item-title { font-size: 1.05rem; }
.simple .stat b { font-size: 1.3rem; }
