/* ========================================================================
   Décap'Soft — PWA photos d'intervention
   Charte via variables CSS (à ajuster si besoin pour coller au site).
   ======================================================================== */

:root {
  --c-bg: #f3f4f0;
  --c-surface: #ffffff;
  --c-ink: #212721;
  --c-ink-soft: #6b7268;
  --c-accent: #1f7009;        /* vert Décap'Soft (boutons du site) */
  --c-accent-dark: #175407;
  --c-green-deep: #12622b;    /* vert foncé du logo */
  --c-secondary: #ab6f09;     /* doré Décap'Soft */
  --c-sand: #f8e6c7;          /* ton sable du logo */
  --c-ok: #1e9e5a;
  --c-warn: #b8860b;
  --c-err: #cc3333;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(25, 35, 25, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- En-tête --- */
.app-header {
  background: var(--c-surface);
  color: var(--c-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 3px solid var(--c-accent);
}
.app-header__brand { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.app-header__logo { height: 40px; width: auto; display: block; cursor: pointer; }
.app-header h1 {
  margin: 0;
  font-size: 13px;
  letter-spacing: .4px;
  color: var(--c-accent);
  text-transform: uppercase;
  text-align: right;
}
.app-header__device { margin: 2px 0 0; font-size: 12px; color: var(--c-ink-soft); text-align: right; }

/* --- Icônes flat (trait, couleur héritée) --- */
.icon {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.24em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon--spin { animation: spin .9s linear infinite; }

.big-icon { margin: 0 0 4px; color: var(--c-accent); }
.big-icon .icon { width: 46px; height: 46px; stroke-width: 1.8; }
.big-icon--ok { color: var(--c-ok); }

/* --- Structure --- */
#app { max-width: 560px; margin: 0 auto; padding: 14px 14px 90px; }
.screen[hidden] { display: none; }

.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card--center { text-align: center; padding: 28px 20px; }
.card h2 { margin: 8px 0 10px; font-size: 20px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.big-emoji { font-size: 44px; margin: 0; }

/* --- Onglets --- */
.tabs {
  display: flex;
  background: #e2e5e9;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--c-ink-soft);
  border-radius: 9px;
  cursor: pointer;
}
.tab.is-active { background: var(--c-surface); color: var(--c-ink); box-shadow: var(--shadow); }

/* --- Formulaires --- */
.field { margin-bottom: 12px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-ink-soft);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
input[type="text"], textarea {
  width: 100%;
  font-size: 17px;
  padding: 12px;
  border: 1.5px solid #d4d8de;
  border-radius: 10px;
  background: #fbfbfc;
  color: var(--c-ink);
  font-family: inherit;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--c-accent); }
textarea { resize: vertical; min-height: 76px; }
.field--description { margin-top: 16px; margin-bottom: 0; }
.field--description .hint { margin-top: 6px; }

.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }

.hint { font-size: 13px; color: var(--c-ink-soft); margin: 10px 0 0; }

.folder-preview {
  font-weight: 700;
  font-size: 15px;
  background: var(--c-sand);
  border: 1px dashed var(--c-secondary);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0 14px;
  word-break: break-word;
}

/* --- Boutons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn--primary { background: var(--c-accent); color: #fff; }
.btn--primary:active:not(:disabled) { background: var(--c-accent-dark); }
.btn--secondary { background: var(--c-secondary); color: #fff; }
.btn--ghost { background: transparent; color: var(--c-secondary); border: 1.5px solid #d4d8de; }
.btn--small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn--block { display: flex; width: 100%; margin-top: 10px; }
.btn--block { flex-direction: column; line-height: 1.25; }
.btn small { font-weight: 500; font-size: 13px; opacity: .92; }
.btn--pick { flex: 1; flex-direction: column; padding: 18px 10px; font-size: 15px; }

.pick-row { display: flex; gap: 10px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; }

/* --- Liste des dossiers --- */
.folder-list { list-style: none; margin: 12px 0 0; padding: 0; }
.folder-list li { margin-bottom: 8px; }
.folder-list button {
  width: 100%;
  text-align: left;
  background: #fbfbfc;
  border: 1.5px solid #e2e5e9;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--c-ink);
  cursor: pointer;
}
.folder-list button:active { border-color: var(--c-accent); background: var(--c-sand); }
.folder-list .folder-date { display: block; font-size: 12px; font-weight: 400; color: var(--c-ink-soft); margin-top: 3px; }

/* --- Grille de photos --- */
.photo-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
}
.photo-grid li {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #e2e5e9;
}
.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid .ph-file {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-size: 11px; color: var(--c-ink-soft);
  padding: 4px; text-align: center; word-break: break-all;
}
.photo-grid .ph-remove {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px;
  border: 0; border-radius: 50%;
  background: rgba(20, 25, 35, .65);
  color: #fff; font-size: 14px; line-height: 1;
  cursor: pointer;
}
.photo-grid .ph-status {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .55);
  color: var(--c-ink);
}
.photo-grid .ph-status .icon { width: 26px; height: 26px; }
.photo-grid li.is-done .ph-status { color: #fff; }
.photo-grid li.is-error .ph-status { color: #fff; }
.photo-grid li.is-done .ph-status { background: rgba(30, 158, 90, .35); }
.photo-grid li.is-error .ph-status { background: rgba(204, 51, 51, .4); }

/* --- Barre d'envoi --- */
.send-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, var(--c-bg) 30%);
  padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}
#screen-photos:not([hidden]) ~ * .send-bar { display: block; }

.progress {
  height: 8px;
  background: #e2e5e9;
  border-radius: 6px;
  margin-top: 10px;
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0%;
  background: var(--c-ok);
  border-radius: 6px;
  transition: width .25s ease;
}

/* --- Notices / toast --- */
.notice {
  font-size: 14px;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  background: #eef1f4;
  color: var(--c-ink);
}
.notice--warn { background: #fdf6e3; color: #7a5b06; }
.notice--err { background: #fdecec; color: #a02626; }

.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* --- Scanner QR --- */
.btn--scan { font-size: 17px; padding: 15px 18px; }
.hint--center { text-align: center; }

.or-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
  color: var(--c-ink-soft);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.or-sep::before, .or-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #d4d8de;
}

.scanner {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner[hidden] { display: none; }
.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner__frame {
  position: relative;
  width: min(82vw, 380px);
  aspect-ratio: 3 / 1;   /* bande large : adaptée à un numéro imprimé */
  border: 3px solid rgba(255, 255, 255, .95);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.scanner__hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(130px + env(safe-area-inset-bottom));
  text-align: center;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
  margin: 0;
}
.scanner__hint small { font-weight: 400; font-size: 12.5px; opacity: .85; }
.scanner__status {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(100px + env(safe-area-inset-bottom));
  text-align: center;
  color: #ffd76a;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
  margin: 0;
  min-height: 18px;
}
.scanner__close {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(28px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .55);
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, .7);
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
/* Deux boutons côte à côte en bas du scanner */
.scanner__pick { transform: translateX(calc(-50% - 92px)); background: rgba(31, 112, 9, .8); }
.scanner__pick + .scanner__close { transform: translateX(calc(-50% + 92px)); }

/* --- Activation / enrôlement --- */
.enroll-form { margin-top: 14px; }
.enroll-form input {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 3px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  text-transform: uppercase;
}
.enroll-code-display {
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 4px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: var(--c-sand);
  border: 1px dashed var(--c-secondary);
  border-radius: 10px;
  padding: 14px 10px;
  margin: 10px 0 14px;
}
.install-steps { margin: 10px 0 4px; padding-left: 22px; font-size: 15px; }
.install-steps li { margin-bottom: 7px; }

.spinner {
  width: 34px; height: 34px;
  margin: 0 auto 6px;
  border: 4px solid #e2e5e9;
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
