:root {
  --bg: #111827; --panel: #1f2937; --panel-2: #273449; --text: #f3f4f6; --muted: #9ca3af;
  --accent: #22c55e; --accent-2: #16a34a; --danger: #ef4444; --warn: #facc15;
  --radius: 12px; --sa-top: env(safe-area-inset-top, 0px); --sa-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }

/* ---------- przyciski ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid #374151; background: var(--panel); color: var(--text); text-decoration: none; cursor: pointer; min-height: 44px; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #052e16; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { border-color: #7f1d1d; color: #fca5a5; }
.btn.small { padding: 6px 12px; min-height: 34px; }
.btn.wide { width: 100%; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer; }
.icon-btn.on { background: var(--warn); color: #111; }

/* ---------- skaner ---------- */
body.scanner { overflow: hidden; }
.stage { position: fixed; inset: 0; background: #000; }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: contain; }
#overlay { pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .15s; }
#flash.on { opacity: .85; transition: none; }

.topbar { position: absolute; top: 0; left: 0; right: 0; padding: calc(var(--sa-top) + 10px) 12px 10px; display: flex; align-items: center; gap: 8px; background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0)); }
.status { flex: 1; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.topbar-actions { display: flex; gap: 8px; }

.controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px calc(var(--sa-bottom) + 12px); display: flex; flex-direction: column; gap: 10px; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75) 30%); }
.row { display: flex; align-items: center; gap: 10px; }
.row.settings { justify-content: center; flex-wrap: wrap; }
.row.main { justify-content: space-between; }

.seg { display: inline-flex; border-radius: 999px; background: rgba(31,41,55,.9); padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 999px; cursor: pointer; min-height: 36px; }
.seg button.on { background: var(--text); color: #111; font-weight: 600; }
.toggle { display: inline-flex; align-items: center; gap: 6px; background: rgba(31,41,55,.9); border-radius: 999px; padding: 8px 14px; min-height: 42px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

.shutter { --p: 0; width: 78px; height: 78px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), rgba(255,255,255,.35) 0); position: relative; }
.shutter::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #fff; border: 3px solid #111; }
.shutter:active::after { transform: scale(.92); }
.last-thumb { width: 56px; height: 72px; object-fit: cover; border-radius: 8px; border: 2px solid rgba(255,255,255,.7); background: #222; }
.counters { min-width: 56px; text-align: right; font-size: 13px; color: var(--muted); line-height: 1.5; }
.counters b { color: var(--text); font-size: 16px; }
.failed { text-align: center; background: rgba(127,29,29,.85); border-radius: 10px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; justify-content: center; }

.pages { background: rgba(31,41,55,.92); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.page-strip { display: flex; gap: 8px; overflow-x: auto; min-height: 8px; }
.thumb { position: relative; flex: 0 0 auto; }
.thumb img { width: 54px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid #4b5563; display: block; }
.thumb span { position: absolute; left: 3px; bottom: 3px; background: rgba(0,0,0,.7); color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 6px; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }

.loading { position: absolute; inset: 0; background: rgba(17,24,39,.96); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid #374151; border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- strony (login, galeria) ---------- */
body.page { min-height: 100%; }
.narrow { max-width: 420px; margin: 0 auto; padding: 48px 16px; }
.wide { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 0 0 16px; }
.card-box { background: var(--panel); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
label { color: var(--muted); font-size: 14px; }
input[type="password"], input[type="search"] { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #374151; background: var(--bg); color: var(--text); font: inherit; min-height: 44px; }
.error { color: #fca5a5; margin: 0; }
.success { color: #86efac; margin: 0; }
.small { font-size: 13px; }
.pagebar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: calc(var(--sa-top) + 12px) 16px 12px; background: var(--panel); position: sticky; top: 0; z-index: 2; }
.pagebar h1 { margin: 0; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 220px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.card { background: var(--panel); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.preview { display: block; aspect-ratio: 3 / 4; background: #0b0f19; display: flex; align-items: center; justify-content: center; }
.preview img { width: 100%; height: 100%; object-fit: contain; }
.pdf-badge { font-weight: 800; font-size: 28px; letter-spacing: 2px; color: #fca5a5; border: 3px solid #fca5a5; border-radius: 10px; padding: 8px 14px; }
.meta { padding: 10px 12px 4px; }
.name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.info { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 6px; padding: 8px 12px 12px; }
.actions .btn { flex: 1; padding: 8px 6px; min-height: 38px; font-size: 14px; }

/* ---------- galeria: status, edycja ---------- */
.card.done { opacity: .55; }
.card.done:hover { opacity: 1; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #14532d; color: #86efac; margin-left: 6px; }
.badge.edited { background: #1e3a8a; color: #bfdbfe; }
.actions.confirm { background: rgba(127,29,29,.35); }
.actions .btn.ok { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.done-toggle.on { border-color: var(--accent); color: #86efac; }
.editor { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.editor-box { background: var(--panel); border-radius: var(--radius); padding: 14px; width: min(720px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.editor-preview { background: #0b0f19; border-radius: 8px; display: flex; align-items: center; justify-content: center; min-height: 200px; max-height: 55vh; }
.editor-preview img { max-width: 100%; max-height: 55vh; object-fit: contain; }
.slider { display: flex; flex-direction: column; gap: 4px; color: var(--text); font-size: 14px; }
.slider span { color: var(--muted); font-size: 13px; }
.slider input { width: 100%; accent-color: var(--accent); }
.editor-actions { flex-wrap: wrap; }
