[hidden] { display: none !important; }

/* Scanner panel */
.scan-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.btn-like.big { display: flex; align-items: center; justify-content: center; padding: 14px 6px; font-weight: 700; border-radius: 10px; text-align: center; }
label.primary.btn-like { background: var(--brand); color: #fff; border: 0; }
label.primary.btn-like:hover { background: var(--brand-2); }
.scan-pages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.scan-page { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #f1f5f9; aspect-ratio: 3/4; }
.scan-page img { width: 100%; height: 100%; object-fit: contain; cursor: pointer; display: block; background: #e2e8f0; }
.scan-page .n { position: absolute; top: 6px; inset-inline-start: 6px; background: rgba(0,0,0,.65); color: #fff; border-radius: 6px; padding: 0 7px; font-size: 12px; }
.sp-tools { position: absolute; bottom: 0; inset-inline: 0; display: flex; justify-content: space-around; background: rgba(15,23,42,.72); }
.sp-tools button { border: 0; background: none; color: #fff; padding: 6px 0; flex: 1; font-size: 14px; }
.sp-tools button:hover { background: rgba(255,255,255,.12); }
.scan-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.scan-actions button { padding: 10px; }
.danger-t { color: var(--danger) !important; }

/* Full-screen editor */
.scan-editor { position: fixed; inset: 0; z-index: 70; background: #0b1220; color: #e2e8f0; display: flex; flex-direction: column; }
.scan-editor[hidden] { display: none; }
body.se-open { overflow: hidden; }
.se-top { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: #111827; }
.se-top .ghost { color: #e2e8f0; border-color: #334155; }
.se-top .ghost:hover { background: #1f2937; }
.se-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; padding: 8px; }
.se-stage canvas { display: block; background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.5); touch-action: none; }
.se-corners { position: absolute; touch-action: none; overflow: visible; }
.se-corners[hidden] { display: none; }
.se-corners circle { cursor: grab; }
.se-panel { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; padding: 10px 12px; background: #111827; border-top: 1px solid #1f2937; min-height: 56px; }
.se-panel .ghost { color: #e2e8f0; border-color: #334155; }
.se-panel .hint { color: #94a3b8; margin: 0; }
.se-panel label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.se-panel input[type=range] { width: 140px; accent-color: #14b8a6; }
.se-panel input[type=color] { width: 36px; height: 32px; border: 0; background: none; padding: 0; }
.chip { border: 1px solid #334155; background: #1f2937; color: #e2e8f0; border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.active { background: #0f766e; border-color: #14b8a6; color: #fff; }
.se-tabs { display: flex; background: #0f172a; padding-bottom: env(safe-area-inset-bottom); }
.se-tabs button { flex: 1; border: 0; background: none; color: #94a3b8; padding: 12px 4px; font-weight: 600; font-size: 13px; border-top: 3px solid transparent; }
.se-tabs button.active { color: #5eead4; border-top-color: #14b8a6; background: #111827; }

/* Exam-from-book panel */
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 8px; }
.counts label { font-size: 12px !important; }
.book-info { background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 10px; padding: 8px 10px; margin-top: 8px; line-height: 1.9; font-size: 13px; }
.link { border: 0; background: none; color: var(--danger); text-decoration: underline; padding: 0 4px; font-size: 12px; }

/* AI providers modal */
.ai-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.ai-table td, .ai-table th { border-bottom: 1px solid var(--border); padding: 6px; text-align: start; vertical-align: top; }
.ai-table th { color: var(--muted); font-weight: 600; }
#aiProvider { max-width: 150px; padding: 6px 8px; }

@media (max-width: 900px) {
  .topbar .brand { font-size: 17px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tab { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .actions { width: 100%; }
  .actions > * { font-size: 12.5px; padding: 6px 9px !important; }
  #btnProof { display: none; }
  .scan-pages { grid-template-columns: repeat(3, 1fr); }
  .se-tabs button { font-size: 12px; padding: 10px 2px; }
  .se-panel input[type=range] { width: 110px; }
}

/* ---------- 📷 home: سكان · ملفاتي · المعرض ---------- */
.cs-home { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cs-big, .panel label.cs-big { display: grid; margin: 0; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 0 10px; align-items: center; text-align: start;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 16px; padding: 14px; cursor: pointer; font: inherit; }
.cs-big i { grid-row: span 2; font-style: normal; font-size: 30px; line-height: 1; }
.cs-big b { font-size: 16px; }
.cs-big small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.cs-big:hover { border-color: var(--brand); }
.cs-main { grid-column: 1 / -1; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; padding: 18px; }
.cs-main small { color: rgba(255,255,255,.85); }
.cs-main i { font-size: 38px; }
.cs-card-link { display: block; width: 100%; margin-top: 10px; border: 1px dashed var(--border); background: transparent; color: var(--text); border-radius: 12px; padding: 11px; font-weight: 700; font: inherit; cursor: pointer; }
.cs-card-link:hover { border-color: var(--brand); color: var(--brand); }
.cs-doc { margin-top: 14px; }
.cs-doc-head { display: flex; gap: 8px; align-items: center; }
.cs-doc-head input { flex: 1; margin: 0 !important; font-weight: 700 !important; }
.cs-files { display: flex; flex-direction: column; gap: 8px; }
.cs-file { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.cs-file img { width: 56px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--bg); cursor: pointer; }
.cs-file-info { display: flex; flex-direction: column; min-width: 0; cursor: pointer; }
.cs-file-info b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-file-info small { color: var(--muted); }
.cs-where { font-style: normal; color: var(--muted); font-size: 11px; letter-spacing: 2px; }
.cs-file-act { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
@media (max-width: 560px) {
  .cs-file { grid-template-columns: 56px 1fr; }
  .cs-file-act { grid-column: 1 / -1; justify-content: stretch; }
  .cs-file-act .mini-btn { flex: 1; margin: 0; padding: 7px 4px; }
}

/* ---------- crop editor: magnifier ---------- */
.se-loupe { position: absolute; width: 150px; height: 150px; border-radius: 50%; pointer-events: none; z-index: 5; box-shadow: 0 6px 24px rgba(0,0,0,.6); }
.se-corners rect { cursor: grab; }

/* ---------- 📷 live camera (what you see = what you get) ---------- */
.cs-cam { position: fixed; inset: 0; z-index: 990; background: #000; display: flex; flex-direction: column; color: #fff; user-select: none; }
.cs-cam[hidden] { display: none; }
body.cs-open { overflow: hidden; }
.cs-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: #000; }
.cs-ico { width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; flex: none; }
.cs-ico.on { background: #fbbf24; color: #111; }
.cs-modes { flex: 1; display: flex; justify-content: center; gap: 4px; }
.cs-modes button { border: 0; background: transparent; color: rgba(255,255,255,.7); padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.cs-modes button.on { background: rgba(255,255,255,.18); color: #fff; }
.cs-pill { border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff; border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; flex: none; }
.cs-view { position: relative; flex: 1; overflow: hidden; }
.cs-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cs-ov { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.cs-view video { transition: opacity .2s; }
/* guide frame + QR-style sweep line */
.cs-guide { position: absolute; z-index: 2; pointer-events: none; border-radius: 14px; }
.cs-guide .cg { position: absolute; width: 34px; height: 34px; border: 4px solid #fff; filter: drop-shadow(0 0 3px rgba(0,0,0,.5)); transition: border-color .2s; }
/* while nothing is locked the corner brackets breathe a little (like a live scan target) */
.cs-cam:not(.locked) .cs-guide .cg { animation: cgBreathe 1.8s ease-in-out infinite; }
@keyframes cgBreathe { 0%, 100% { opacity: .72; } 50% { opacity: 1; } }
.cs-guide .tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-radius: 14px 0 0 0; }
.cs-guide .tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-radius: 0 14px 0 0; }
.cs-guide .bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-radius: 0 0 0 14px; }
.cs-guide .br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-radius: 0 0 14px 0; }
.cs-sweep { position: absolute; left: 4%; right: 4%; height: 3px; border-radius: 3px; background: linear-gradient(90deg, transparent, #22d3ee 20%, #67e8f9 50%, #22d3ee 80%, transparent);
  box-shadow: 0 0 16px 5px rgba(34, 211, 238, .45); animation: csSweep 2.2s ease-in-out infinite alternate; }
@keyframes csSweep { from { top: 3%; } to { top: 96%; } }
.cs-cam.locked .cs-guide .cg { border-color: #34d399; }
.cs-cam.locked .cs-sweep { background: linear-gradient(90deg, transparent, #34d399 20%, #a7f3d0 50%, #34d399 80%, transparent); box-shadow: 0 0 18px 6px rgba(52, 211, 153, .5); }
.cs-glabel { position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%); white-space: nowrap; background: rgba(15,23,42,.8); padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 700; }
.cs-glabel:empty { display: none; }
/* card mode: everything outside the card frame is dimmed, the frame is the card's own shape */
.cs-cam.card .cs-guide { box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55); border: 2px dashed rgba(255,255,255,.75); border-radius: 16px; }
.cs-cam.card.locked .cs-guide { border-color: #34d399; }
.cs-freeze { position: absolute; z-index: 4; object-fit: fill; pointer-events: none; animation: csFreeze .45s ease-out; }
@keyframes csFreeze { from { filter: brightness(1.6); } to { filter: none; } }
.cs-msg { position: absolute; z-index: 6; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(15,23,42,.8); padding: 7px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
.cs-msg[hidden] { display: none; }
.cs-bar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px calc(18px + env(safe-area-inset-bottom)); background: #000; }
.cs-stack { position: relative; width: 56px; height: 56px; border-radius: 10px; border: 2px solid rgba(255,255,255,.5); background: #111; padding: 0; overflow: visible; }
.cs-stack img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: none; }
.cs-stack.has img { display: block; }
.cs-stack b { position: absolute; top: -8px; inset-inline-end: -8px; min-width: 22px; height: 22px; border-radius: 11px; background: #14b8a6; color: #fff; font-size: 12px; display: grid; place-items: center; padding: 0 5px; }
.cs-shot { position: relative; width: 80px; height: 80px; border: 0; background: transparent; padding: 0; }
.cs-shot svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.cs-shot .ring { fill: none; stroke: #fff; stroke-width: 5; }
.cs-shot .prog { fill: none; stroke: #34d399; stroke-width: 5; stroke-dasharray: 226; stroke-dashoffset: 226; transition: stroke-dashoffset .12s linear; }
.cs-shot i { position: absolute; inset: 11px; border-radius: 50%; background: #fff; transition: transform .1s; }
.cs-shot:active i { transform: scale(.88); }
.cs-done { min-width: 56px; border: 0; background: #14b8a6; color: #fff; border-radius: 999px; padding: 10px 16px; font-weight: 800; font-size: 15px; }
.cs-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cs-flash.on { animation: csFlash .35s ease-out; }
@keyframes csFlash { 0% { opacity: .9; } 100% { opacity: 0; } }

.ghost.ok { border-color: #34d399; color: #34d399; font-weight: 600; }

/* ✓ one-shot result: the finished page at once */
.cs-ready { position: fixed; inset: 0; z-index: 9000; background: rgba(2, 6, 23, .92); display: flex; align-items: center; justify-content: center; padding: 12px; }
.cs-ready[hidden] { display: none; }
.cs-ready-in { width: 100%; max-width: 560px; max-height: 100%; display: flex; flex-direction: column; gap: 10px; color: #fff; }
.cs-ready-head { display: flex; align-items: center; justify-content: space-between; font-size: 17px; }
.cs-ready-head b { color: #4ade80; }
.cs-ready-img { flex: 1; min-height: 0; display: flex; justify-content: center; }
.cs-ready-img img { max-width: 100%; max-height: 58vh; object-fit: contain; border-radius: 6px; background: #fff; box-shadow: 0 6px 30px rgba(0,0,0,.5); }
.cs-ready-f { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.cs-ready-f button { flex: none; border: 1px solid rgba(255,255,255,.3); background: transparent; color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.cs-ready-f button.on { background: #0f766e; border-color: #2dd4bf; }
.cs-ready-act { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cs-ready-act button { padding: 11px 8px; font-size: 14px; }
.cs-ready-act .ghost { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.cs-ready-img { position: relative; }
.cs-ready-img.sweep::after { content: ''; position: absolute; left: 6%; right: 6%; height: 4px; top: 0; border-radius: 4px; background: linear-gradient(90deg, transparent, #22d3ee, #a3e635, #22d3ee, transparent); box-shadow: 0 0 18px 4px rgba(34, 211, 238, .55); animation: csSweep .8s ease-in-out 2 alternate; }
@keyframes csSweep { from { top: 0; } to { top: calc(100% - 4px); } }
