:root {
  --gold: #c9a54c;
  --gold-2: #e3c97a;
  --gold-dk: #9c7a2c;
  --ink: #0b0b0b;
  --ink-2: #1a1a1a;
  --paper: #f6f3ec;
  --card: #ffffff;
  --line: #e4ddcc;
  --txt: #1b1b1b;
  --muted: #7a7366;
  --danger: #b3261e;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #121212; --card: #1d1d1d; --line: #2c2a25; --txt: #f1ece0; --muted: #a39b89; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--txt); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; background: var(--paper); }
.screen.active { display: flex; }
.screen.dark { background: #000; color: #fff; }

/* topo */
.top { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-t) + 10px) 14px 10px; background: var(--ink); color: #fff; border-bottom: 1px solid #000; }
.dark-top { background: rgba(0,0,0,.85); }
.brand-ico { width: 38px; height: 38px; border-radius: 9px; }
.brand-txt { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt strong { color: var(--gold-2); font-size: 18px; letter-spacing: .3px; }
.brand-txt span { font-size: 12px; color: #bdb39a; letter-spacing: 1.5px; text-transform: uppercase; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: var(--gold-2); }
.icon-btn:active { background: rgba(255,255,255,.12); }
.icon-btn.light { color: #fff; background: rgba(0,0,0,.35); }
.doc-title { flex: 1; text-align: left; color: #fff; font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-title { flex: 1; text-align: center; font-weight: 600; }
.ok-btn { background: var(--gold); color: #111; font-weight: 700; padding: 9px 16px; border-radius: 22px; }

/* busca e lista */
.search { padding: 10px 14px 4px; }
.search input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--txt); font-size: 15px; }
.doc-list { flex: 1; overflow-y: auto; padding: 8px 14px calc(110px + var(--safe-b)); }
.doc-item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 10px; width: 100%; text-align: left; }
.doc-item img { width: 56px; height: 74px; object-fit: cover; border-radius: 6px; background: #ddd; border: 1px solid var(--line); flex: none; }
.doc-item .meta { flex: 1; min-width: 0; }
.doc-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.doc-item .go { color: var(--gold-dk); }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 32px 120px; }
.empty-logo { width: 150px; margin-bottom: 18px; border-radius: 12px; }

/* barra inferior */
.dock { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-around; padding: 10px 10px calc(var(--safe-b) + 10px); background: var(--ink); color: #e9dfc4; border-top: 1px solid #000; }
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; min-width: 64px; padding: 4px; }
.scan-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 86px; height: 86px; margin-top: -40px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--gold-2), var(--gold) 55%, var(--gold-dk)); color: #111; font-weight: 700; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.45), 0 0 0 5px var(--ink); }
.scan-btn svg { width: 32px; height: 32px; stroke-width: 2.2; }
.primary-btn { display: flex; align-items: center; gap: 8px; background: var(--gold); color: #111; font-weight: 700; padding: 12px 18px; border-radius: 26px; }
.doc-dock { justify-content: space-between; }

/* câmera */
.cam-wrap { position: absolute; inset: 0; background: #000; overflow: hidden; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash-fx { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
#flash-fx.on { opacity: .75; transition: none; }
.cam-hint { position: absolute; left: 50%; top: calc(var(--safe-t) + 74px); transform: translateX(-50%); background: rgba(0,0,0,.55); padding: 7px 14px; border-radius: 18px; font-size: 14px; white-space: nowrap; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(var(--safe-t) + 10px) 12px 10px; }
.pill { background: rgba(0,0,0,.5); color: #fff; padding: 8px 12px; border-radius: 18px; font-size: 13px; }
.pill b { color: var(--gold-2); }
.pill.off b { color: #aaa; }
.cam-bottom { position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px 22px calc(var(--safe-b) + 22px); background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; }
.shutter span { width: 62px; height: 62px; border-radius: 50%; background: var(--gold); transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.thumb-btn { position: relative; width: 56px; height: 56px; border-radius: 10px; overflow: visible; border: 2px solid #fff; background: #222; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.thumb-btn img:not([src]) { visibility: hidden; }
.thumb-btn span { position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: var(--gold); color: #111; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.done-btn { min-width: 76px; padding: 12px 16px; border-radius: 24px; background: #fff; color: #111; font-weight: 700; }
.cam-mode { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 130px); transform: translateX(-50%); background: var(--gold); color: #111; padding: 8px 16px; border-radius: 18px; font-weight: 700; white-space: nowrap; }

/* documento */
.doc-info { padding: 10px 16px 0; color: var(--muted); font-size: 13px; }
.page-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; padding: 12px 14px calc(110px + var(--safe-b)); align-content: start; }
.page-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center; }
.page-card img { max-width: 100%; max-height: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.page-card .n { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.65); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 9px; }
.page-card.wait::after { content: "Tratando…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.6); color: #333; font-size: 13px; border-radius: 10px; }

/* edição */
.edit-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 14px; touch-action: none; }
#edit-canvas { max-width: 100%; max-height: 100%; touch-action: none; }
#edit-preview { max-width: 100%; max-height: 100%; position: absolute; }
#loupe { position: absolute; width: 110px; height: 110px; border-radius: 50%; border: 3px solid var(--gold); pointer-events: none; display: none; top: 20px; left: 20px; background: #000; }
.edit-tabs { display: flex; justify-content: center; gap: 8px; padding: 6px; }
.tab { padding: 8px 18px; border-radius: 18px; color: #bbb; }
.tab.active { background: #262626; color: var(--gold-2); font-weight: 600; }
.edit-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 6px 12px; }
.edit-tools:last-child { padding-bottom: calc(var(--safe-b) + 12px); }
.tool { padding: 9px 14px; border-radius: 10px; background: #1f1f1f; color: #eee; font-size: 14px; }
.tool.danger { color: #ff8a80; }
.chip { padding: 8px 13px; border-radius: 18px; background: #1f1f1f; color: #eee; font-size: 14px; border: 1px solid #333; }
.chip.active { background: var(--gold); color: #111; border-color: var(--gold); font-weight: 600; }

/* ocr */
.ocr-status { padding: 10px 16px; color: var(--muted); font-size: 14px; }
#ocr-text { flex: 1; margin: 0 14px calc(var(--safe-b) + 14px); padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--txt); font: 15px/1.5 ui-monospace, Menlo, Consolas, monospace; resize: none; }
.dark-txt { color: #fff; }

/* ajustes */
.settings { flex: 1; overflow-y: auto; padding: 14px 16px calc(var(--safe-b) + 24px); }
.settings label { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-weight: 600; }
.settings select { display: block; width: 100%; margin-top: 8px; padding: 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--paper); color: var(--txt); font-size: 15px; }
.about { text-align: center; padding: 18px 8px; }
.about img { width: 120px; border-radius: 10px; }

/* folha de opções */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; z-index: 20; }
.sheet-box { width: 100%; background: var(--card); color: var(--txt); border-radius: 18px 18px 0 0; padding: 14px 14px calc(var(--safe-b) + 14px); }
.sheet-box h3 { margin: 4px 6px 12px; font-size: 16px; }
.sheet-box button.opt { display: block; width: 100%; text-align: left; padding: 14px; border-radius: 10px; font-size: 16px; }
.sheet-box button.opt:active { background: rgba(0,0,0,.06); }
.sheet-box button.opt.danger { color: var(--danger); }
.sheet-box input { width: 100%; padding: 12px; font-size: 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--txt); margin-bottom: 10px; }
.sheet-row { display: flex; gap: 10px; }
.sheet-row button { flex: 1; padding: 13px; border-radius: 10px; font-weight: 700; background: var(--line); }
.sheet-row button.go { background: var(--gold); color: #111; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 120px); transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 18px; border-radius: 20px; opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.6); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 40; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.25); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
