:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --tap: 56px; /* hauteur tactile confortable */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* L'attribut [hidden] doit TOUJOURS masquer, même quand une classe (.overlay,
   .toast…) définit display:flex. Sans ce reset, les styles auteur l'emportent
   sur le display:none par défaut du navigateur et les overlays restent visibles. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); font-weight: 600; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: 0 1.2rem;
  border: none; border-radius: var(--radius);
  font-size: 1.05rem; font-weight: 600;
  color: var(--text); background: var(--surface-2);
  cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-success { background: var(--success); color: #052e12; }
.btn-ghost { background: transparent; border: 1px solid var(--surface-2); }
.btn-lg { min-height: 64px; font-size: 1.15rem; }
.btn-sm { min-height: 40px; font-size: .9rem; padding: 0 .8rem; }
.btn-block { display: flex; width: 100%; margin-top: .8rem; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  padding-top: calc(.7rem + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 1.1rem; }
.topbar-spacer { flex: 1; }
.pill {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--success); display: inline-block;
}
.pill.offline { background: var(--danger); }

/* ---------- Vue principale ---------- */
.view { padding: 1rem; max-width: 720px; margin: 0 auto; }
.field { margin-bottom: 1.2rem; }
.field label, .field .label, .section-title {
  display: block; font-weight: 600; margin-bottom: .4rem;
}
.section-title { margin: 1.6rem 0 .6rem; font-size: 1.05rem; }
input[type=text], input[type=password] {
  width: 100%; min-height: var(--tap);
  padding: 0 1rem; font-size: 1.05rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--surface-2); border-radius: var(--radius);
}

/* Segmented control */
.seg { display: flex; gap: .4rem; background: var(--surface); padding: .3rem; border-radius: var(--radius); }
.seg-btn {
  flex: 1; min-height: 48px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: .95rem;
}
.seg-btn.is-active { background: var(--primary); color: #fff; }

/* Listes documents / file d'attente */
.doc-list, .queue-list { list-style: none; padding: 0; margin: 0; }
.doc-item, .queue-item {
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border-radius: var(--radius);
  padding: .7rem .9rem; margin-bottom: .6rem;
}
.doc-thumb {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover;
  background: var(--surface-2); flex: none;
}
.doc-meta { flex: 1; min-width: 0; }
.doc-meta strong { display: block; }
.doc-meta small { color: var(--muted); }
.doc-actions { display: flex; gap: .4rem; }
.icon-btn {
  width: 44px; height: 44px; border: none; border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 1.1rem;
}

/* Statut file d'attente */
.q-status { font-size: .8rem; padding: .15rem .5rem; border-radius: 999px; }
.q-pending { background: #475569; }
.q-uploading { background: var(--primary); }
.q-error { background: var(--danger); }
.q-done { background: var(--success); color: #052e12; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: .4rem; }
.progress > i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #000; display: flex; flex-direction: column;
}
.capture-stage { flex: 1; position: relative; overflow: hidden; display: flex; }
#cam-video, #cam-canvas { width: 100%; height: 100%; object-fit: contain; background: #000; }

.capture-pages, .capture-thumbs { display: flex; gap: .4rem; padding: .5rem; overflow-x: auto; background: #000; }
.capture-pages img { height: 64px; border-radius: 6px; border: 2px solid transparent; }

.capture-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem; background: #000;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}
.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff; border: 5px solid var(--surface-2);
}
.shutter:active { transform: scale(.94); }
.capture-hint { color: var(--muted); text-align: center; padding: 0 1rem .6rem; min-height: 1.2em; }

/* Aperçu */
.preview-head { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; background: var(--surface); padding-top: calc(.8rem + env(safe-area-inset-top)); }
.preview-pages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.preview-page { position: relative; background: var(--surface); border-radius: var(--radius); padding: .6rem; }
.preview-page img { width: 100%; border-radius: 8px; display: block; }
.preview-page .page-tools { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.preview-tools { padding: .6rem 1rem; background: var(--surface); }
.switch { display: flex; align-items: center; gap: .6rem; }
.switch input { width: 26px; height: 26px; }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.2rem; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border-radius: 18px; padding: 1.6rem;
  text-align: center;
}
.login-card h1 { margin: 0 0 .2rem; }
.login-card form { display: flex; flex-direction: column; gap: .9rem; text-align: left; margin-top: 1.2rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  padding: .8rem 1.2rem; border-radius: 999px; z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90%;
}
