:root {
  --bg: #000000;
  --surface: #111111;
  --surface-2: #1c1c1c;
  --text: #e7ecff;
  --muted: #9aa3c7;
  --accent: #6c8cff;
  --accent-2: #4a6ae0;
  --danger: #ff6b6b;
  --warn: #ffb84d;
  --ok: #6be3a2;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.muted { color: var(--muted); font-size: 13px; }
.input-row { display: flex; gap: 6px; align-items: stretch; }
.input-row input { flex: 1; }
.icon-btn { padding: 8px 10px; display: inline-grid; place-items: center; }

/* Camera viewfinder */
#cameraStage {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}
#cameraVideo {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.frame {
  position: absolute; inset: 8%;
  pointer-events: none;
  border-radius: 6px;
}
.corner {
  position: absolute; width: 28px; height: 28px;
  border-color: #fff; border-style: solid; border-width: 0;
  filter: drop-shadow(0 0 4px #000a);
}
.corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 6px; }
.corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 6px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 6px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 6px; }
.frame-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: #fff; font-size: 12px; background: #0008; padding: 4px 12px; border-radius: 999px;
  white-space: nowrap; text-align: center;
  pointer-events: none;
}
.fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; color: var(--muted); padding: 20px;
}
.fallback[hidden] { display: none; }
.capture-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.capture-actions > #clearBtn { justify-self: start; }
.capture-actions > .upload-group { justify-self: center; display: flex; gap: 8px; align-items: center; }
.capture-actions > #pageCount { justify-self: end; }
.round-btn {
  width: 40px; height: 40px;
  padding: 0;
  border-radius: 50%;
  display: inline-grid; place-items: center;
}

/* Floating capture button */
.fab {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: 68px; height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: #000000;
  border: 4px solid #ffffffcc;
  font-size: 28px;
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 24px #000a, 0 0 0 4px #6c8cff33;
  z-index: 20;
  padding: 0;
}
.fab:hover { background: var(--accent-2); color: #fff; }
.fab:active { transform: translateX(-50%) scale(0.95); }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #ffffff10;
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
header h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.lang-btn {
  font-weight: 700; font-size: 13px; letter-spacing: .5px;
  padding: 6px 10px; min-width: 40px;
}

/* RTL tweaks */
[dir="rtl"] .findings li { border-left: 0; border-right: 4px solid var(--muted); }
[dir="rtl"] .findings li.high { border-right-color: var(--danger); }
[dir="rtl"] .findings li.medium { border-right-color: var(--warn); }
[dir="rtl"] .findings li.low { border-right-color: var(--ok); }
[dir="rtl"] dialog menu { justify-content: flex-start; }
[dir="rtl"] .pages .num { left: auto; right: 6px; }
[dir="rtl"] .pages .del { right: auto; left: 4px; }
main { padding: 16px; max-width: 760px; margin: 0 auto; display: grid; gap: 18px; }
section { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; text-align: center; }

button, label.primary {
  appearance: none; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
button.primary, label.primary { background: var(--accent); color: #000000; }
button.primary:hover, label.primary:hover { background: var(--accent-2); color: #fff; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid #ffffff20; }
button.big { display: block; margin: 12px auto 0; padding: 14px 28px; font-size: 16px; min-width: 220px; text-align: center; justify-content: center; }
button:disabled { opacity: .5; cursor: not-allowed; }

.pages { list-style: none; padding: 0; margin: 14px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px,1fr)); gap: 10px; }
.pages li { position: relative; background: #0008; border-radius: 10px; overflow: hidden; aspect-ratio: 3/4; }
.pages img { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-tile { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; background: linear-gradient(135deg, #1c2333, #0f1422); color: var(--text); text-align: center; }
.doc-tile-kind { font-size: 18px; font-weight: 700; letter-spacing: 1px; color: #6aa2ff; }
.doc-tile-name { font-size: 10px; opacity: .8; word-break: break-all; line-clamp: 3; -webkit-line-clamp: 3; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.pages .num { position: absolute; top: 6px; left: 6px; background: #000a; color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.pages .del { position: absolute; top: 4px; right: 4px; background: #000a; color: #fff; border-radius: 999px; width: 26px; height: 26px; padding: 0; display: grid; place-items: center; font-size: 14px; }

#status { text-align: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #ffffff22; border-top-color: var(--accent);
  margin: 0 auto 10px; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.summary { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); margin-bottom: 12px; color: var(--muted); }
.findings { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.findings li { background: var(--surface-2); border-left: 4px solid var(--muted); border-radius: 10px; padding: 12px 14px; }
.findings li.high { border-left-color: var(--danger); }
.findings li.medium { border-left-color: var(--warn); }
.findings li.low { border-left-color: var(--ok); }
.findings h3 { margin: 0 0 4px; font-size: 15px; }
.findings .meta { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.findings .quote { font-style: italic; color: var(--muted); margin-top: 6px; font-size: 13px; }
#results .row { justify-content: center; margin-top: 20px; }

dialog {
  border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 18px; max-width: 90vw; width: 420px;
}
dialog::backdrop { background: #000a; }
dialog h2 { margin-top: 0; }
dialog label { display: grid; gap: 6px; margin: 10px 0; font-size: 14px; color: var(--muted); }
dialog input, dialog select { background: #0006; border: 1px solid #ffffff20; color: var(--text); padding: 10px; border-radius: 8px; font: inherit; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 14px 0 0; }

/* PWA install banner */
.install-banner {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2);
  border-bottom: 1px solid #ffffff15;
  padding: 10px 14px;
}
.install-banner[hidden] { display: none; }
.install-text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.install-text strong { font-size: 14px; }
.install-text .muted { font-size: 12px; }
.install-actions { display: flex; gap: 6px; align-items: center; }
.install-actions .primary { padding: 8px 14px; font-size: 14px; }
.install-actions .ghost { padding: 6px 10px; font-size: 18px; line-height: 1; }

/* Account / balance */
#accountBtn { position: relative; }
.balance-pill {
  position: absolute; top: -4px; right: -6px;
  background: var(--accent); color: #000;
  border-radius: 999px; padding: 1px 6px;
  font-size: 11px; font-weight: 700; line-height: 1.4;
  min-width: 18px; text-align: center;
}
[dir="rtl"] .balance-pill { right: auto; left: -6px; }
.divider {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px;
  margin: 14px 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: #ffffff20;
}
.balance-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin: 12px 0;
}
.balance-row > div {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
  display: grid; gap: 4px;
}
.balance-row strong { font-size: 18px; }
#accountDialog .primary { width: 100%; justify-content: center; }
#accountDialog .ghost { width: 100%; justify-content: center; }
