:root {
  --bg: #f0eee6;
  --surface: rgba(255, 255, 255, 0.94);
  --border: rgba(20, 20, 19, 0.12);
  --text: #1a1915;
  --muted: #6b6860;
  --accent: #0f6e5c;
  --warn: #d08a12;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
three-d-stage { position: fixed; inset: 0; width: 100vw; height: 100vh; }
three-d-stage:not(:defined) { visibility: hidden; }
button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  padding: 6px 10px; cursor: pointer;
}
button:hover { background: #f7f6f2; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- Topo ---------- */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 12px; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 15px; letter-spacing: 0.2px; }
.source { display: flex; align-items: center; gap: 6px; max-width: 420px; }
.source #fonteNome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.icon { padding: 4px 9px; font-size: 15px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #aaa; flex: none; }
.dot.ok { background: #2e9e6b; }
.dot.loading { background: var(--warn); animation: pulse 1s infinite; }
.dot.erro { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }
.kpis { display: flex; gap: 18px; flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; align-items: flex-end; }
.kpi span { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 11px; }
.kpi.alert span { color: var(--warn); }

/* ---------- Painel ---------- */
.panel {
  position: fixed; top: 76px; right: 12px; bottom: 64px; width: 340px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; overflow: hidden;
}
.search input {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: #fff;
}
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.controls label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11.5px; }
.controls select { padding: 5px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); }
.controls .check { flex-direction: row; align-items: center; gap: 6px; grid-column: span 2; color: var(--text); font-size: 12.5px; }
.legenda { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; color: var(--muted); }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legenda .ramp { width: 90px; height: 8px; border-radius: 4px; display: inline-block; vertical-align: middle; margin: 0 4px; }
.views { display: flex; gap: 6px; }
.views button { flex: 1; font-size: 12px; padding: 5px; }

.detalhe, .resultados, .avisos { overflow: auto; }
.resultados { flex: 1; min-height: 60px; }
.detalhe {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: #fff; max-height: 45%; flex: none;
}
.detalhe h3 { margin: 0 0 2px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.detalhe h3 button { border: none; background: none; font-size: 16px; padding: 0 4px; }
.barra { height: 6px; background: #eceae3; border-radius: 3px; overflow: hidden; margin: 6px 0 8px; }
.barra > div { height: 100%; background: var(--accent); }
.item { padding: 6px 0; border-top: 1px solid var(--border); }
.item:first-of-type { border-top: none; }
.item b { font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 10px; background: #eceae3; color: var(--muted); }
.tag.warn { background: #fbefd6; color: #8a5a00; }
.tag.danger { background: #f8dcd8; color: #8f2318; }

.resultados h4, .avisos h4 { margin: 4px 0 6px; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.res {
  display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left;
  border: none; border-bottom: 1px solid var(--border); border-radius: 0; background: none; padding: 6px 2px;
}
.res:hover { background: #f7f6f2; }
.res .end { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--accent); white-space: nowrap; }
.res .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avisos { max-height: 22%; flex: none; font-size: 12px; border-top: 1px dashed var(--border); padding-top: 6px; }
.avisos li { color: #8a5a00; }
.avisos ul { margin: 0; padding-left: 16px; }

/* ---------- Tooltip / drop / dialog ---------- */
.tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: rgba(26, 25, 21, 0.92); color: #fff; padding: 6px 9px; border-radius: 6px; font-size: 12px;
  max-width: 260px; transform: translate(12px, 12px);
}
.tooltip b { font-family: ui-monospace, Consolas, monospace; }
.drop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 110, 92, 0.18); border: 3px dashed var(--accent); font-size: 18px; font-weight: 600; color: var(--accent);
}
.drop[hidden] { display: none; }
dialog { border: none; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); max-width: 560px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
.dlg { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; }
.dlg fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.dlg legend { font-weight: 600; padding: 0 4px; }
.dlg input[type=text] { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; }
.dlg .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dlg .row.end { justify-content: flex-end; }
.dlg .row label { display: flex; align-items: center; gap: 6px; flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 30;
  background: #1a1915; color: #fff; padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow);
}

@media (min-width: 761px) {
  three-d-stage { width: calc(100vw - 364px); }
}

/* ---------- Navegação ---------- */
.navpad {
  position: fixed; left: 12px; bottom: 12px; z-index: 5;
  display: grid; grid-template-columns: auto auto; grid-template-areas: "onde onde" "hist hist" "pad zoom" "ajuda ajuda";
  gap: 6px; padding: 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); user-select: none; touch-action: none;
}
.navpad .onde { grid-area: onde; font-size: 12px; font-weight: 600; white-space: nowrap; }
.navpad .hist { grid-area: hist; display: flex; gap: 4px; }
.navpad .hist button { flex: 1; font-size: 12px; padding: 5px 6px; }
.navpad button:disabled { opacity: 0.4; cursor: default; }
.navpad .pad { grid-area: pad; display: grid; grid-template-columns: repeat(3, 34px); grid-auto-rows: 34px; gap: 3px; }
.navpad .zoom { grid-area: zoom; display: grid; grid-template-columns: repeat(2, 30px); grid-auto-rows: 22px; gap: 3px; align-content: start; }
.navpad .zoom #navAjuda { grid-column: span 2; }
.navpad .pad button, .navpad .zoom button { padding: 0; font-size: 14px; line-height: 1; }
.navpad .pad button:active, .navpad .zoom button:active { background: var(--accent); color: #fff; }
.navpad .ajuda { grid-area: ajuda; max-width: 340px; font-size: 11.5px; line-height: 1.55; color: var(--muted); border-top: 1px solid var(--border); padding-top: 6px; }
.navpad .ajuda[hidden] { display: none; }

/* Ponto piscando no título da posição selecionada */
.pisca { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #ff2d2d; margin-right: 7px; vertical-align: 1px; animation: piscar 0.7s ease-in-out infinite alternate; }
@keyframes piscar { from { opacity: 1; box-shadow: 0 0 0 0 rgba(255, 45, 45, 0.6); } to { opacity: 0.25; box-shadow: 0 0 0 6px rgba(255, 45, 45, 0); } }
.detalhe h3 > span:last-child { display: flex; gap: 2px; }

.res.sempos { opacity: 0.6; cursor: default; }
.res.sempos .end { color: var(--muted); }
.avisos button { margin: 6px 0 4px; font-size: 12px; }
.avisos small { display: block; }
.avisos code, .dlg code { font-size: 11px; background: #eceae3; padding: 0 4px; border-radius: 3px; }
.kpi.muted-kpi span { color: var(--muted); }
.kpi[hidden] { display: none; }


/* ---------- Botões de modo ---------- */
.brand .sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.modo-btn { font-weight: 600; font-size: 12.5px; }
.modo-btn.ligado { background: var(--accent); color: #fff; border-color: var(--accent); }
#btnApresentacao { background: #1a1915; color: #fff; border-color: #1a1915; }
.abc { display: inline-block; min-width: 16px; text-align: center; border-radius: 4px; color: #fff; padding: 0 4px; font-size: 11px; }
.abc-A { background: #c0392b; } .abc-B { background: #f39c12; } .abc-C { background: #5d7b93; }

/* ---------- Marca d'água ---------- */
.marca-dagua {
  position: fixed; z-index: 40; pointer-events: none; user-select: none;
  left: 50%; bottom: 10px; transform: translateX(-50%);
  font: italic 600 13px/1 Georgia, "Times New Roman", serif; letter-spacing: 1px;
  color: rgba(26, 25, 21, 0.18);
}
body.apresentando .marca-dagua { font-size: 15px; color: rgba(255, 255, 255, 0.38); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); left: auto; right: 28px; bottom: auto; top: 58px; transform: none; }

/* ---------- Feed 4D ---------- */
.feed4d { position: fixed; left: 12px; bottom: 236px; z-index: 6; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; max-width: 380px; pointer-events: none; }
.feed4d li { background: rgba(26, 25, 21, 0.82); color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 7px; animation: entra 0.35s ease-out; }
.feed4d li i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.feed4d code { color: #ffd479; font-size: 11px; }
@keyframes entra { from { opacity: 0; transform: translateX(-12px); } }

/* ---------- Apresentação ---------- */
body.apresentando .topbar, body.apresentando .panel, body.apresentando .navpad,
body.apresentando .feed4d { display: none; }
body.apresentando three-d-stage { width: 100vw; }
.apr { position: fixed; inset: 0; z-index: 30; pointer-events: none; color: #fff; }
.apr[hidden] { display: none; }
.apr::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 230px; background: linear-gradient(rgba(10, 10, 10, 0.55), transparent); }
.apr-titulo { position: absolute; left: 32px; top: 28px; max-width: 62vw; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55); }
.apr-titulo small { text-transform: uppercase; letter-spacing: 2px; font-size: 13px; opacity: 0.85; font-weight: 700; }
.apr-titulo h1 { margin: 4px 0 6px; font-size: clamp(26px, 3.4vw, 54px); line-height: 1.1; }
.apr-titulo p { margin: 0; font-size: clamp(14px, 1.4vw, 22px); opacity: 0.92; }
.apr.troca .apr-titulo { animation: aprEntra 0.9s ease-out; }
@keyframes aprEntra { from { opacity: 0; transform: translateY(-10px); } }
.apr-kpis { position: absolute; left: 32px; bottom: 34px; display: flex; gap: 12px; flex-wrap: wrap; max-width: 60vw; }
.apr-kpis div { background: rgba(20, 20, 20, 0.62); border-radius: 10px; padding: 10px 14px; min-width: 120px; backdrop-filter: blur(4px); }
.apr-kpis b { display: block; font-size: clamp(18px, 1.8vw, 28px); }
.apr-kpis small { opacity: 0.8; font-size: 12px; }
.apr-qr { position: absolute; right: 28px; bottom: 30px; background: #fff; color: #1a1915; border-radius: 14px; padding: 12px; width: 190px; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); }
.apr-qr #aprQr svg { width: 166px; height: 166px; display: block; margin: 0 auto 6px; }
.apr-qr b { display: block; font-size: 14px; }
.apr-qr small { display: block; font-size: 10.5px; color: var(--muted); word-break: break-all; }
.apr-dica { position: absolute; right: 28px; top: 28px; font-size: 13px; opacity: 0.8; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); }
.apr-barra { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, 0.15); }
.apr-barra div { height: 100%; background: #ffd479; width: 0; }

/* ---------- Modo separador (1ª pessoa) ---------- */
.fp-ui[hidden] { display: none; }
.fp-joy { position: fixed; left: 24px; bottom: 90px; z-index: 20; width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.25); border: 2px solid rgba(255, 255, 255, 0.7); box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2); touch-action: none; }
.fp-knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: rgba(15, 110, 92, 0.85); border: 2px solid #fff; }
.fp-mira { position: fixed; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); z-index: 20; pointer-events: none; }
.fp-dica { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); z-index: 20; background: rgba(26, 25, 21, 0.78); color: #fff; font-size: 12px; padding: 6px 12px; border-radius: 8px; pointer-events: none; animation: some 1s 6s forwards; }
@keyframes some { to { opacity: 0; } }
.fp-sair { position: fixed; right: 16px; top: 84px; z-index: 21; background: rgba(26, 25, 21, 0.85); color: #fff; border: none; }
body.modo-fp .navpad { display: none; }
body.modo-fp three-d-stage { touch-action: none; }
@media (hover: hover) and (pointer: fine) { .fp-joy { opacity: 0.55; } }

.inicio-celular { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(15, 30, 26, 0.72); padding: 24px; }
.inicio-celular[hidden] { display: none; }
.inicio-celular > div { background: #fff; border-radius: 16px; padding: 24px; max-width: 360px; text-align: center; }
.inicio-celular h1 { margin: 0 0 8px; }
.inicio-celular button { margin-top: 14px; font-size: 18px; padding: 12px 28px; background: var(--accent); color: #fff; border: none; border-radius: 10px; }

/* ---------- Celular ---------- */
.alca { display: none; }
@media (max-width: 760px) {
  three-d-stage { height: 100dvh; }
  .topbar { top: 6px; left: 6px; right: 6px; padding: 5px 6px; gap: 6px; flex-wrap: nowrap; }
  .kpis { display: none; }
  .brand { flex-wrap: nowrap; gap: 5px; width: 100%; }
  .brand strong { font-size: 13px; white-space: nowrap; margin-left: 2px; }
  .brand .sep, #fonteNome, #fonteHora, #btnApresentacao, #btnFP .rot { display: none; }
  .brand button { padding: 7px 10px; }
  #btn4D { margin-left: auto; }

  /* painel vira uma gaveta que sobe de baixo */
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: auto; max-height: 74dvh; gap: 8px;
    border-radius: 16px 16px 0 0; border-bottom: none; padding: 2px 12px calc(10px + env(safe-area-inset-bottom)); }
  body.folha-aberta .panel { height: 74dvh; }
  body:not(.folha-aberta) .panel :is(.controls, .legenda, .views, .resultados, .avisos) { display: none; }
  .alca { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; border: none; background: none; padding: 6px 0 2px; }
  .alca span { width: 42px; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.22); }
  .alca small { font-size: 11px; color: var(--muted); }
  .search input, .controls select { font-size: 16px; } /* evita o zoom automático do iPhone */
  .controls select { padding: 7px; }
  .views button { padding: 9px 5px; }
  .res { padding: 10px 2px; }
  .detalhe { max-height: 36dvh; }
  body.folha-aberta .detalhe { max-height: 32%; }

  /* navegação por toque: 1 dedo gira, 2 dedos arrastam e dão zoom — fica só o histórico */
  .navpad { top: 56px; bottom: auto; left: 6px; padding: 5px 6px; gap: 4px; grid-template-columns: auto; grid-template-areas: "onde" "hist"; }
  .navpad :is(.pad, .zoom, .ajuda) { display: none !important; }
  .navpad .onde { font-size: 11px; max-width: 62vw; overflow: hidden; text-overflow: ellipsis; }
  .navpad .hist button { padding: 7px 14px; font-size: 14px; }
  .navpad .hist .rot { display: none; }
  .feed4d { bottom: auto; top: 128px; max-width: 70vw; }
  .feed4d li { font-size: 11px; }
  .marca-dagua { font-size: 11px; left: auto; right: 100px; bottom: auto; top: 25px; transform: none; } /* no vão da barra do topo */
  .toast { bottom: 150px; max-width: calc(100% - 24px); }

  /* modo separador: só o cartão do produto tocado */
  body.modo-fp .panel { max-height: 34dvh; left: auto; right: 8px; bottom: 8px; width: 60vw; border-radius: 12px; border-bottom: 1px solid var(--border); }
  body.modo-fp .panel :is(.alca, .search, .controls, .legenda, .views, .resultados, .avisos) { display: none; }
  body.modo-fp .panel:not(:has(.detalhe:not([hidden]))) { display: none; }
  body.modo-fp .fp-joy { bottom: 40px; }
  body.modo-fp .fp-sair { top: 56px; }
}

/* ---------- Marcas ---------- */
.leg-btn { border: none; background: none; padding: 1px 2px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.leg-btn:hover { color: var(--text); text-decoration: underline; }
.bolinha { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
