:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #6b7684;
  --line: #dde2e8;
  --primary: #1f3a5f;
  --primary-text: #ffffff;
  --accent: #2e7d4f;
  --danger: #b3261e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1c222b; --text: #e6eaf0; --muted: #94a0ae;
    --line: #2c3440; --primary: #5b8fd6; --primary-text: #0d1117; --accent: #4caf7a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1c222b; --text: #e6eaf0; --muted: #94a0ae;
  --line: #2c3440; --primary: #5b8fd6; --primary-text: #0d1117; --accent: #4caf7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--line); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.view { display: none; min-height: 100dvh; flex-direction: column; }
.view.active { display: flex; }
.view.dark { background: #000; color: #fff; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--primary); color: var(--primary-text);
}
.bar.dark { background: #000; color: #fff; }
.bar h1 { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn { background: none; border: 0; color: inherit; font-size: 1.4rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }
.icon-btn:active { background: rgba(127,127,127,.25); }
.icon-btn.light { color: #fff; }

.pad { padding: 16px; flex: 1; width: 100%; max-width: 900px; margin: 0 auto; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0 12px; line-height: 1.8; }
.hint code { white-space: nowrap; word-break: normal; }
#name-preview { white-space: normal; word-break: break-all; }
.hint.light { color: #b9c2cc; min-height: 1.2em; margin: 2px 0 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 12px 16px; border-radius: var(--radius); font-size: 1rem; font-weight: 500; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 8px 12px; font-size: .9rem; }
.btn.block { display: block; width: 100%; }
.btn.grow { flex: 1; }
.btn:disabled { opacity: .5; }

.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input[type="range"] { padding: 0; }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); margin: 8px 0; }
.check input { width: auto; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.row.tight { gap: 8px; align-items: flex-end; }
.row.tight > .btn { flex: 0 0 auto; }
.row.tight > .btn.grow { flex: 1; }

.cards { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.card .thumb { width: 48px; height: 64px; border-radius: 6px; background: var(--line) center/cover; flex: none; }
.card .info { flex: 1; min-width: 0; }
.card .info b { display: block; }
.card .info span { font-size: .85rem; color: var(--muted); }

.summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: .9rem; }
.summary div { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.summary div span:first-child { color: var(--muted); }
.actions { display: flex; gap: 10px; margin: 14px 0; }
.actions > .btn { flex: 1; }
.sticky-bottom { position: sticky; bottom: 0; padding: 10px 0 calc(env(safe-area-inset-bottom) + 10px); background: var(--bg); margin: 0; }

.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.page {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
}
.page img { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--line); cursor: pointer; display: block; }
.page .meta { padding: 6px 8px; font-size: .75rem; }
.page .meta b { font-size: .85rem; }
.page .meta .fname { color: var(--muted); word-break: break-all; display: block; }
.page .tools { display: flex; border-top: 1px solid var(--line); }
.page .tools button { flex: 1; background: none; border: 0; padding: 8px 0; color: var(--text); font-size: 1rem; cursor: pointer; }
.page .tools button + button { border-left: 1px solid var(--line); }
.page .badge { font-size: .7rem; padding: 1px 6px; border-radius: 6px; background: var(--line); }

.reg-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.reg-list li { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; }
.reg-list li span { flex: 1; }
.reg-list li code { flex: none; }

/* Cámara */
.cam-wrap { position: relative; flex: 1; overflow: hidden; background: #000; }
#cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-status { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 6px 14px; border-radius: 20px; font-size: .85rem; white-space: nowrap; }
.cam-controls { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px calc(env(safe-area-inset-bottom) + 16px); background: #000; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; cursor: pointer; }
.shutter:active { background: #ccc; }
.cam-count { width: 44px; text-align: center; display: flex; flex-direction: column; font-size: 1.3rem; font-weight: 600; }
.cam-count small { font-size: .7rem; font-weight: 400; color: #aaa; }

/* Revisión */
.review-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#review-canvas { max-width: 100%; max-height: 100%; touch-action: none; }
.review-panel { background: #111; padding: 12px 12px calc(env(safe-area-inset-bottom) + 12px); }
.review-panel label { color: #b9c2cc; }
.review-panel input { background: #222; color: #fff; border-color: #333; }
.review-panel .btn { background: #222; color: #fff; border-color: #333; }
.review-panel .btn.primary { background: #5b8fd6; color: #0d1117; }
.seg { display: flex; background: #222; border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; background: none; border: 0; color: #ccc; padding: 8px 4px; border-radius: 8px; font-size: .9rem; cursor: pointer; }
.seg button.on { background: #5b8fd6; color: #0d1117; font-weight: 600; }

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