/* Scan: dark, mobile first. Motion uses transform/opacity only. */

:root {
  --bg: #0f1115;
  --bg-2: #151922;
  --card: #1c2230;
  --card-2: #242c3d;
  --ink: #f2f4f7;
  --ink-2: #c9d2df;
  --muted: #8a93a3;
  --line: #2b3444;
  --accent: #38bdf8;
  --accent-d: #0ea5e9;
  --accent-ink: #06202d;
  --danger: #f87171;
  --shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 12px 32px -8px rgba(0, 0, 0, .5);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar-h: 76px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .4; cursor: default; }
img { display: block; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.muted { color: var(--muted); }
.centre { text-align: center; padding: 40px 16px; }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row .btn { flex: 1; }

/* Splash (index.html, before Blazor) */
.splash { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.splash-logo { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.splash-bar { width: 140px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.splash-bar > div { width: 40%; height: 100%; background: var(--accent); animation: slide 1.1s infinite var(--ease); }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* Shell and pages */
.shell { min-height: 100dvh; }
.page { max-width: 960px; margin: 0 auto; padding: var(--safe-t) 16px calc(var(--bar-h) + 16px + var(--safe-b)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; height: 60px; margin: 0 -16px 8px; padding: 0 12px; background: linear-gradient(var(--bg) 70%, transparent); }
.brand { flex: 1; font-size: 24px; font-weight: 800; letter-spacing: -.02em; padding-left: 4px; }
.title-btn { flex: 1; min-width: 0; text-align: left; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 8px 6px; border-radius: 8px; }
.title-btn:active { background: var(--card); }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--ink-2); transition: transform .12s var(--ease), background .12s; }
.icon-btn:active { transform: scale(.9); background: var(--card); }
.icon-btn.dark { background: rgba(0, 0, 0, .45); color: #fff; }

/* Buttons */
.btn { height: 50px; padding: 0 20px; border-radius: 14px; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .12s var(--ease), filter .12s; }
.btn:active:not(:disabled) { transform: scale(.96); filter: brightness(1.1); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--card-2); color: var(--ink); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink-2); }
.pill { height: 36px; padding: 0 14px; border-radius: 18px; background: rgba(0, 0, 0, .45); color: #fff; font-weight: 600; font-size: 14px; }
.pill.on, .pill.auto { background: var(--accent); color: var(--accent-ink); }

.fab-row { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 35%); }
.fab-row .btn { flex: 1; height: 52px; }
.fab-row .fab { flex: 1.4; box-shadow: var(--shadow); }
@media (min-width: 720px) { .fab-row { max-width: 960px; margin: 0 auto; } }

/* Library */
.empty { text-align: center; padding: 60px 20px 20px; max-width: 360px; margin: 0 auto; }
.empty-art { color: var(--accent); margin-bottom: 14px; }
.empty h2 { font-size: 22px; margin-bottom: 8px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.doc-card { position: relative; background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); transition: transform .14s var(--ease); cursor: pointer; }
.doc-card:active { transform: scale(.97); }
.doc-thumb { position: relative; aspect-ratio: 3 / 4; background: #000; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-blank { width: 100%; height: 100%; background: var(--card-2); }
.thumb-blank.big { display: grid; place-items: center; color: var(--muted); }
.doc-pages { position: absolute; left: 8px; bottom: 8px; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: rgba(0, 0, 0, .6); color: #fff; }
.doc-meta { padding: 10px 12px 12px; }
.doc-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-date { font-size: 12px; margin-top: 2px; }
.doc-menu { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff; font-size: 20px; }

/* Sheets, scrims, toasts */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(6, 8, 12, .72); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--ink-2); animation: fade .15s var(--ease); }
.scrim.light { background: rgba(6, 8, 12, .5); }
.sheet-scrim { justify-content: flex-end; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(14px + var(--safe-b)); box-shadow: var(--shadow); animation: up .22s var(--ease); }
@media (min-width: 720px) { .sheet-scrim { justify-content: center; } .sheet { border-radius: 22px; } }
.sheet h3 { font-size: 17px; margin: 0 4px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet p { margin: 0 4px 12px; font-size: 14px; line-height: 1.45; }
.sheet-item { display: block; width: 100%; text-align: left; padding: 13px 12px; border-radius: 12px; font-size: 16px; font-weight: 600; color: var(--ink); }
.sheet-item small { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.sheet-item:active { background: var(--card-2); }
.sheet-item.danger { color: var(--danger); }
.text { width: 100%; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg-2); color: var(--ink); font: inherit; padding: 0 14px; outline: none; }
.text:focus { border-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 24px + var(--safe-b)); transform: translateX(-50%); z-index: 25; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); animation: up .2s var(--ease); }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }

/* Camera */
.camera { position: fixed; inset: 0; background: #000; overflow: hidden; }
.cam-video, .cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-video { object-fit: cover; }
.cam-overlay { pointer-events: none; }
.cam-top { position: absolute; top: var(--safe-t); left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: 12px; gap: 10px; }
.cam-hint { flex: 1; text-align: center; font-size: 14px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.cam-error { position: absolute; left: 24px; right: 24px; top: 40%; transform: translateY(-50%); text-align: center; background: var(--card); padding: 22px; border-radius: 18px; }
.cam-error h2 { margin-bottom: 8px; font-size: 20px; }
.cam-error p { font-size: 14px; line-height: 1.45; margin-top: 6px; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; padding: 22px 28px calc(26px + var(--safe-b)); background: linear-gradient(transparent, rgba(0, 0, 0, .65)); }
.cam-side { width: 84px; height: 48px; color: #fff; font-weight: 700; font-size: 15px; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); border-radius: 24px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.cam-side.done.on { background: var(--accent); color: var(--accent-ink); text-shadow: none; }
.cam-side .count { min-width: 24px; height: 24px; border-radius: 12px; background: var(--accent-ink); color: #fff; font-size: 13px; display: grid; place-items: center; padding: 0 6px; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; transition: transform .1s var(--ease); }
.shutter:active:not(:disabled) { transform: scale(.92); }
.shutter span { width: 62px; height: 62px; border-radius: 50%; background: #fff; }

/* Crop */
.crop { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; }
.crop-top { padding: calc(14px + var(--safe-t)) 16px 10px; text-align: center; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.crop-canvas { flex: 1; width: 100%; min-height: 0; touch-action: none; display: block; }
.crop-actions { display: flex; gap: 8px; padding: 12px 12px calc(14px + var(--safe-b)); }
.crop-actions .btn { flex: 1; padding: 0 8px; font-size: 14px; }
.crop-actions .btn.primary { flex: 1.3; }

/* Editor */
.stage { position: relative; background: #000; border-radius: 16px; overflow: hidden; height: calc(100dvh - 400px); min-height: 260px; display: grid; place-items: center; }
@media (min-width: 720px) { .stage { height: calc(100dvh - 360px); min-height: 400px; } }
.stage-img { width: 100%; height: 100%; display: grid; place-items: center; transition: opacity .15s; }
.stage-img.dim { opacity: .5; }
.stage-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.stage-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 56px; font-size: 30px; color: #fff; background: rgba(0, 0, 0, .35); border-radius: 10px; }
.stage-nav.prev { left: 6px; } .stage-nav.next { right: 6px; }
.stage-count { position: absolute; top: 10px; right: 12px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 10px; background: rgba(0, 0, 0, .6); color: #fff; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 38px; padding: 0 16px; border-radius: 19px; background: var(--card); color: var(--ink-2); font-weight: 600; font-size: 14px; border: 1.5px solid transparent; transition: transform .12s var(--ease); }
.chip:active { transform: scale(.95); }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.tools { display: flex; justify-content: space-between; gap: 4px; padding: 10px 0; }
.tool { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px; font-size: 22px; color: var(--ink-2); }
.tool small { font-size: 11px; font-weight: 600; color: var(--muted); }
.tool:active:not(:disabled) { background: var(--card); }
.tool.danger { color: var(--danger); }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip-item { position: relative; flex: none; width: 58px; height: 76px; border-radius: 10px; overflow: hidden; background: var(--card); border: 2px solid transparent; }
.strip-item.on { border-color: var(--accent); }
.strip-item img { width: 100%; height: 100%; object-fit: cover; }
.strip-item span { position: absolute; left: 4px; bottom: 4px; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; background: rgba(0, 0, 0, .6); color: #fff; }

/* Motion */
.rise { animation: rise .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Blazor error bar */
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; padding: 12px 16px; background: #fde68a; color: #1a1400; }
#blazor-error-ui .dismiss { position: absolute; right: 12px; top: 12px; cursor: pointer; }

/* A label styled as a button (file pickers) */
label.btn, label.cam-side { position: relative; overflow: hidden; }
label.btn.disabled { opacity: .4; pointer-events: none; }
