/* =========================================================
   ScanPro PWA — reprend les couleurs/dimensions des layouts Android
   (1dp ≈ 1px CSS, 1sp ≈ 1px CSS)
   ========================================================= */
:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --accent: #10b981;
  --bg: #0f172a;
  --surface: #1e293b;
  --stroke: #475569;
  --muted: #94a3b8;
  --muted2: #64748b;
  --credits: #38bdf8;
  --danger: #f87171;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body {
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", Arial, sans-serif;
  color: #fff; font-size: 14px;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Vues ---------- */
.view { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.view-dark { background: var(--bg); }
.view-black { background: #000; }
.view-white { background: #fff; color: #1e293b; }

/* ---------- Utilitaires de mise en page ---------- */
.row { display: flex; flex-direction: row; }
.center-v { align-items: center; }
.grow { flex: 1 1 0; min-width: 0; }
.gap { gap: 8px; }
.mb8 { margin-bottom: 8px; }
.mt8 { margin-top: 8px; }

/* ---------- Icônes ---------- */
.ico { width: 24px; height: 24px; flex: none; fill: currentColor; }
.btn .ico { width: 20px; height: 20px; }

.icon-btn {
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: transparent; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.muted { color: var(--muted); }
.icon-btn.round { background: rgba(255,255,255,.12); }

/* ---------- Boutons Material ---------- */
.btn {
  height: 48px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; border: 1px solid transparent;
  padding: 0 12px; color: #fff; font-size: 14px; font-weight: 500;
  letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: filter .15s, background .15s;
}
.btn span { overflow: hidden; text-overflow: ellipsis; }
.btn.filled { background: var(--btn, #0ea5e9); }
.btn.filled:active { filter: brightness(.88); }
.btn.outlined { background: transparent; border-color: var(--stroke); }
.btn.outlined:active { background: rgba(255,255,255,.06); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.big { height: 56px; }
.btn.bold { font-weight: 700; }
.btn.small-text { font-size: 11px; height: 46px; border-radius: 6px; text-transform: uppercase; }
.btn.small-btn { width: auto; height: 36px; padding: 0 16px; border-radius: 18px; }

/* ---------- Écran principal ---------- */
.ad-container { min-height: 50px; background: var(--surface); flex: none; }
.preview-area { position: relative; flex: 1 1 auto; min-height: 0; }
.img-preview { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; object-fit: contain; touch-action: pan-y; }
.welcome { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.welcome-logo { width: 100px; height: 100px; object-fit: contain; }
.welcome-title { font-size: 28px; font-weight: bold; margin-top: 16px; }
.welcome-sub { font-size: 14px; color: var(--muted); margin-top: 8px; }
.overlay-tl { position: absolute; top: 16px; inset-inline-start: 16px; }
.overlay-tr { position: absolute; top: 16px; inset-inline-end: 16px; }
.page-indicator {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.5); padding: 8px 16px; font-size: 14px; font-weight: bold;
  box-shadow: 0 2px 4px rgba(0,0,0,.4);
}

.footer {
  flex: none; background: var(--surface);
  padding: 16px 16px calc(16px + var(--safe-b)) 16px;
  max-height: 62vh; overflow-y: auto;
}
.credits { color: var(--credits); font-size: 14px; font-weight: bold; margin-bottom: 8px; }
.amount { margin-top: 8px; color: #10b981; font-size: 16px; font-weight: bold; text-align: center; }

/* ---------- Scanner ---------- */
.scanner-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#scanVideo { width: 100%; height: 100%; object-fit: cover; }
.scan-nocam { color: var(--muted); padding: 24px; text-align: center; }
.scanner-top {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: 8px; background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.scan-count { font-weight: bold; font-size: 16px; }
.scanner-bottom {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-around;
  padding: 24px 16px calc(32px + var(--safe-b));
  background: linear-gradient(transparent, rgba(0,0,0,.7));
}
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid #fff; background: var(--primary); box-shadow: 0 0 0 4px rgba(14,165,233,.35);
}
.shutter:active { transform: scale(.94); }
.scan-thumb {
  width: 48px; height: 48px; border-radius: 8px; background: #1e293b center/cover no-repeat;
  border: 2px solid #fff; position: relative;
}
.scan-thumb:empty:not([style*="url"]) { opacity: .35; }
.scan-thumb b {
  position: absolute; top: -8px; right: -8px; background: var(--primary); border-radius: 10px;
  min-width: 20px; height: 20px; font-size: 12px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---------- Recadrage ---------- */
.crop-stage { position: relative; flex: 1 1 auto; min-height: 0; margin: 8px 16px; touch-action: none; }
#cropCanvas { position: absolute; }
.crop-svg { position: absolute; overflow: visible; }
.crop-svg polygon { fill: rgba(14,165,233,.18); stroke: #0ea5e9; stroke-width: 2; }
.crop-svg circle { fill: rgba(14,165,233,.35); stroke: #fff; stroke-width: 2; cursor: grab; }
.crop-bottom { display: flex; justify-content: center; gap: 32px; padding: 12px 0 calc(24px + var(--safe-b)); }

/* ---------- Topbars ---------- */
.topbar { display: flex; align-items: center; background: var(--surface); flex: none; }
.topbar.h56 { height: 56px; padding: 0 16px 0 8px; }
.topbar.h52 { height: 52px; padding: 0 8px 0 4px; }
.topbar-title { flex: 1; font-size: 18px; font-weight: bold; margin-inline-start: 8px; }

/* ---------- Documents ---------- */
.doc-count { color: var(--muted2); font-size: 14px; padding: 12px; flex: none; }
.empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.doc-grid {
  flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(2, 1fr);
  padding: 8px 8px 60px; align-content: start;
}
@media (min-width: 700px) { .doc-grid { grid-template-columns: repeat(4, 1fr); } }
.doc-card {
  margin: 8px; background: var(--surface); border-radius: 16px; overflow: hidden;
  box-shadow: 0 4px 10px rgba(0,0,0,.35); cursor: pointer; min-width: 0;
}
.doc-thumb { position: relative; height: 140px; background: #0f172a; display: flex; align-items: center; justify-content: center; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.doc-thumb .type-ico { width: 72px; height: 88px; }
.doc-thumb .more { position: absolute; top: 8px; inset-inline-end: 8px; width: 36px; height: 36px; color: #38bdf8; }
.doc-badge {
  position: absolute; bottom: 8px; inset-inline-start: 8px; font-size: 10px; font-weight: bold;
  padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.55);
}
.doc-info { padding: 12px; }
.doc-name { font-size: 14px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--muted2); margin-top: 4px; }
.doc-meta i { color: var(--stroke); font-style: normal; }

/* ---------- Éditeur Word ---------- */
.editor-header { color: #fff; }
.file-name {
  flex: 1; min-width: 0; height: 36px; margin: 0 8px; border: 0; outline: 0; background: transparent;
  color: #fff; font-size: 15px; font-weight: bold;
}
.file-name::placeholder { color: var(--muted2); }
.char-count { color: var(--muted2); font-size: 11px; }
.toolbar {
  height: 44px; flex: none; background: #f1f5f9; display: flex; align-items: center;
  padding: 0 8px; overflow-x: auto; scrollbar-width: none; gap: 2px;
}
.toolbar::-webkit-scrollbar { display: none; }
.tb-btn {
  flex: none; width: 40px; height: 36px; border: 0; border-radius: 4px; background: transparent;
  color: #1e293b; font-size: 16px; display: inline-flex; align-items: center; justify-content: center;
}
.tb-btn:active { background: #e2e8f0; }
.tb-btn.small { width: 36px; font-size: 13px; }
.tb-btn.big { font-size: 18px; }
.tb-btn.on { color: #0ea5e9; }
.tb-btn.align.active { color: #0ea5e9; background: #dbeafe; }
.tb-btn .ico { width: 20px; height: 20px; }
.tb-size { flex: none; width: 36px; text-align: center; font-size: 13px; font-weight: bold; color: #1e293b; }
.tb-sep { flex: none; width: 1px; height: 24px; background: #cbd5e1; margin: 0 6px; }
.editor-content {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px; outline: none;
  color: #1e293b; font-size: 15px; line-height: 1.5; background: #fff;
  user-select: text; -webkit-user-select: text; white-space: pre-wrap; word-wrap: break-word;
}
.editor-content:empty::before { content: attr(data-placeholder); color: #94a3b8; pointer-events: none; }
.editor-content div, .editor-content p { margin: 0; }
.editor-footer {
  flex: none; display: flex; gap: 8px; background: var(--surface);
  padding: 10px 10px calc(16px + var(--safe-b));
}

/* ---------- Paramètres ---------- */
.settings-body { padding: 32px 16px; display: flex; flex-direction: column; gap: 8px; }
.settings-btn { background: var(--surface); color: var(--muted); font-size: 13px; border-radius: 4px; text-transform: uppercase; }
.settings-lang {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px;
  background: var(--surface); color: var(--muted); padding: 10px 16px; border-radius: 4px; font-size: 13px;
}
.settings-lang select { background: var(--bg); color: #fff; border: 1px solid var(--stroke); border-radius: 6px; padding: 6px; }

/* ---------- Progress ---------- */
.progress { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; pointer-events: none; }
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid rgba(14,165,233,.25); border-top-color: #0ea5e9; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(96px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  max-width: 85vw; background: rgba(50,50,50,.95); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; text-align: center; animation: toastIn .2s ease-out; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Dialogues (AlertDialog) ---------- */
.dlg-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 24px; animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.dlg {
  width: min(420px, 100%); background: #fff; color: #1e293b; border-radius: 28px; padding: 24px 24px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); user-select: text;
}
.dlg h3 { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
.dlg p { margin: 0 0 16px; color: #475569; line-height: 1.45; }
.dlg input[type=text] {
  width: 100%; font-size: 16px; padding: 10px 2px; border: 0; border-bottom: 2px solid #0ea5e9;
  outline: 0; margin-bottom: 16px; color: #1e293b; background: transparent;
}
.dlg-items { margin: 0 -24px 8px; }
.dlg-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 24px; border: 0; background: transparent; text-align: start; color: #1e293b; font-size: 16px; }
.dlg-item:active { background: #f1f5f9; }
.dlg-item .swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-actions button { border: 0; background: transparent; color: #0284c7; font-weight: 500; padding: 10px 12px; border-radius: 20px; text-transform: uppercase; }
.dlg-actions button:active { background: #e0f2fe; }

/* ---------- Popup menu ---------- */
.menu-backdrop { position: fixed; inset: 0; z-index: 95; }
.menu {
  position: fixed; min-width: 168px; background: #fff; color: #1e293b; border-radius: 4px; padding: 8px 0;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); animation: fadeIn .12s;
}
.menu button { display: block; width: 100%; text-align: start; border: 0; background: transparent; padding: 12px 16px; font-size: 15px; color: inherit; }
.menu button:active { background: #f1f5f9; }

[dir=rtl] .js-back .ico, [dir=rtl] #btnBack .ico, [dir=rtl] #btnHome .ico { transform: scaleX(-1); }
