/* =========================================================
   Fichora — outil Images en PDF
   ========================================================= */
.tool-hero { padding-bottom: 28px; }
.tool { display: grid; gap: 0; grid-template-columns: minmax(0, 1fr); overflow: hidden; scroll-margin-top: calc(var(--header-h) + 12px); }
@media (min-width: 940px) { .tool { grid-template-columns: minmax(0, 1fr) 340px; } }
.tool-main { padding: 16px; min-width: 0; }
@media (min-width: 700px) { .tool-main { padding: 24px; } }
.tool-side { padding: 20px 16px 22px; border-top: 1px solid var(--line); background: var(--surface-2); }
@media (min-width: 700px) { .tool-side { padding: 24px; } }
@media (min-width: 940px) { .tool-side { border-top: 0; border-left: 1px solid var(--line); } }

/* ---------- Zone de dépôt ---------- */
#dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 300px; padding: 30px 18px; border-radius: 20px; cursor: pointer;
  border: 2px dashed color-mix(in srgb, var(--brand) 38%, var(--line));
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--brand) 9%, transparent), transparent 70%),
    var(--surface-2);
  transition: border-color .2s, background-color .2s, transform .2s var(--ease), min-height .35s var(--ease), padding .35s var(--ease);
}
#dropzone:hover { border-color: var(--brand); }
#dropzone:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
#dropzone.over { border-color: var(--brand); border-style: solid; transform: scale(1.01); background-color: var(--brand-soft); }
.dz-icon {
  width: 76px; height: 76px; border-radius: 24px; display: grid; place-items: center; margin-bottom: 16px; color: #fff;
  background: var(--grad); box-shadow: 0 16px 34px -12px rgba(70, 80, 225, .75); animation: float 3.2s ease-in-out infinite;
}
.dz-icon svg { width: 38px; height: 38px; }
#dropzone.over .dz-icon { animation: none; transform: scale(1.12) rotate(-6deg); transition: transform .25s var(--ease); }
.dz-title { font-size: clamp(1.15rem, 2.6vw, 1.4rem); font-weight: 800; margin: 0 0 4px; letter-spacing: -0.02em; }
.dz-or { color: var(--muted); margin: 0 0 16px; font-size: .95rem; }
.dz-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.dz-formats { margin: 16px 0 0; font-size: .84rem; color: var(--muted); font-weight: 600; }
.dz-formats svg { display: inline-block; width: 15px; height: 15px; vertical-align: -3px; margin-right: 4px; color: var(--ok); }
/* Version compacte quand des pages sont présentes */
#dropzone.compact { min-height: 0; padding: 16px; flex-direction: row; flex-wrap: wrap; gap: 12px 16px; text-align: left; justify-content: space-between; }
#dropzone.compact .dz-icon { width: 46px; height: 46px; border-radius: 14px; margin: 0; animation: none; }
#dropzone.compact .dz-icon svg { width: 24px; height: 24px; }
#dropzone.compact .dz-text { flex: 1; min-width: 150px; }
#dropzone.compact .dz-title { font-size: 1rem; margin: 0; }
#dropzone.compact .dz-or, #dropzone.compact .dz-formats { display: none; }
#dropzone.compact .btn { min-height: 42px; padding: 9px 16px; font-size: .93rem; }
@media (max-width: 520px) {
  #dropzone.compact .dz-actions { width: 100%; }
  #dropzone.compact .dz-actions .btn { flex: 1; }
}
/* Sur téléphone, la photo passe en premier */
.only-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .only-touch { display: inline-flex; } .dz-actions .btn-cam { order: -1; } }

/* ---------- Liste des pages ---------- */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 22px 0 4px; }
.list-head h2 { font-size: 1.1rem; margin: 0; letter-spacing: -0.01em; }
.link-danger { background: none; border: none; color: var(--danger); font-weight: 700; padding: 6px 8px; border-radius: 8px; font-size: .92rem; }
.link-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.tap-hint { margin: 0 0 14px; color: var(--muted); font-size: .88rem; }

#grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
@media (min-width: 700px) { #grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.tile {
  position: relative; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: box-shadow .2s, border-color .2s, transform .2s var(--ease), opacity .2s;
}
.tile.new { animation: tile-in .35s var(--ease) both; }
.tile:hover { box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.tile.placeholder { opacity: .3; border-style: dashed; border-color: var(--brand); box-shadow: none; }
.tile.lifted {
  position: fixed; z-index: 95; pointer-events: none; margin: 0; box-shadow: var(--shadow-lg);
  transform: scale(1.06) rotate(-2deg); border-color: var(--brand); transition: none;
}
body.dragging-tile, body.dragging-tile * { cursor: grabbing !important; }
.thumb {
  display: grid; place-items: center; aspect-ratio: 3 / 4; width: 100%; padding: 8px; border: 0; position: relative;
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px;
  cursor: grab;
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, .14); transition: transform .3s var(--ease); }
.tile:hover .thumb img { transform: scale(1.03); }
.thumb .ph { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.pos {
  position: absolute; top: 8px; left: 8px; min-width: 26px; padding: 2px 8px; border-radius: 999px; text-align: center;
  background: rgba(15, 15, 30, .78); color: #fff; font-size: .76rem; font-weight: 800; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.editmark { position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 999px; background: var(--brand); color: #fff; font-size: .7rem; font-weight: 800; }
@media (prefers-color-scheme: dark) { .editmark { color: var(--brand-ink); } }
.tile-tools { display: flex; gap: 2px; padding: 6px; border-top: 1px solid var(--line); }
.tile-tools button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  display: grid; place-items: center; transition: background .15s, color .15s;
}
.tile-tools button svg { width: 18px; height: 18px; }
.tile-tools button:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.tile-tools button.del:hover:not(:disabled) { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.tile-tools button:disabled { opacity: .3; cursor: not-allowed; }

.empty { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); margin: 18px 0 4px; font-size: .95rem; text-align: center; }

/* ---------- Options ---------- */
.tool-side h2 { font-size: 1.05rem; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }
.tool-side h2 svg { width: 20px; height: 20px; color: var(--brand); }
.field { margin-bottom: 15px; }
.field label, .field .lbl { display: block; font-weight: 700; font-size: .88rem; margin-bottom: 6px; }
.field input[type="text"], .field select {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  transition: border-color .15s, box-shadow .15s; font-size: 16px; /* évite le zoom sur iPhone */
}
.field select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238a8fa8'%3E%3Cpath d='M5.3 7.3a1 1 0 0 1 1.4 0L10 10.6l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 20px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 5px; }
#estimate { font-weight: 700; color: var(--ink); min-height: 1.3em; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  margin: 0; display: grid; place-items: center; min-height: 38px; padding: 4px 6px; border-radius: 9px; text-align: center;
  font-size: .82rem; font-weight: 700; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.seg input:checked + label { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
@media (prefers-color-scheme: dark) { .seg input:checked + label { color: var(--brand-ink); } }
.seg input:focus-visible + label { outline: 3px solid var(--brand); outline-offset: 1px; }
.seg input:disabled + label { opacity: .4; cursor: not-allowed; }
.privacy-note { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 0; font-size: .82rem; color: var(--muted); }
.privacy-note svg { width: 17px; height: 17px; flex: none; color: var(--ok); margin-top: 2px; }

/* Résultat */
#result {
  margin-top: 16px; padding: 16px; border-radius: 16px; background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--line)); animation: rise .4s var(--ease);
}
#result .ok { display: flex; gap: 10px; align-items: flex-start; font-weight: 700; margin-bottom: 12px; word-break: break-word; }
#result .ok svg { width: 22px; height: 22px; flex: none; color: var(--ok); }
#result .ok small { display: block; font-weight: 600; color: var(--muted); }
#result .row { display: flex; gap: 8px; flex-wrap: wrap; }
#result .row .btn { flex: 1; min-height: 42px; padding: 9px 14px; font-size: .9rem; }
#result .thanks { margin: 12px 0 0; font-size: .84rem; color: var(--muted); }

/* Barre d'action fixe sur téléphone */
.mobile-cta {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); transform: translateY(110%); transition: transform .3s var(--ease);
}
.mobile-cta.show { transform: none; }
@media (min-width: 940px) { .mobile-cta { display: none; } }

/* ---------- Fenêtres plein écran ---------- */
#overlay { position: fixed; inset: 0; z-index: 110; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(8, 8, 20, .55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
#overlay.show { display: flex; }
.loader { background: var(--surface); border-radius: var(--r-lg); padding: 28px 30px; text-align: center; min-width: 260px; box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); }
.spinner { width: 42px; height: 42px; margin: 0 auto 14px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); border-right-color: var(--teal); animation: spin .8s linear infinite; }
#loadmsg { font-weight: 700; }
.bar { height: 7px; background: var(--line); border-radius: 99px; margin-top: 14px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: 99px; transition: width .2s; }

#camera { position: fixed; inset: 0; background: #000; color: #fff; display: none; flex-direction: column; z-index: 100; }
#camera.show { display: flex; }
#camvideo { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; transition: opacity .12s; }
#camvideo.flash { opacity: .3; }
.camtop { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; padding: 16px; text-align: center; font-weight: 700; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); pointer-events: none; }
.cambar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px calc(22px + env(safe-area-inset-bottom)); background: #000; }
.cambtn { background: rgba(255, 255, 255, .16); color: #fff; border: 0; border-radius: 999px; padding: 12px 16px; font-weight: 700; min-width: 100px; min-height: 46px; }
.cambtn.done { background: #fff; color: #111; }
.cambtn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.shutter { width: 76px; height: 76px; flex: none; border-radius: 50%; border: 4px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; padding: 0; transition: transform .1s; }
.shutter:active { transform: scale(.9); }

#editor { position: fixed; inset: 0; background: #0b0c14; color: #fff; display: none; flex-direction: column; z-index: 102; }
#editor.show { display: flex; }
.edtop { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
#edstage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 22px; overflow: hidden; }
#edbox { position: relative; touch-action: none; }
#edcanvas { display: block; width: 100%; height: 100%; background: #fff; border-radius: 4px; }
#edsvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#edsvg polygon { fill: rgba(140, 127, 255, .2); stroke: #8c7fff; stroke-width: 2; }
.corner { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border: 0; background: none; padding: 0; touch-action: none; cursor: grab; }
.corner::after { content: ""; position: absolute; left: 12px; top: 12px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid #8c7fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.edpanel { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); background: #000; }
.edrow { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 8px; max-width: 900px; margin: 0 auto; }
.edrow:last-child { padding-bottom: 0; }
.chip { flex: 1 0 auto; background: rgba(255, 255, 255, .12); color: #fff; border: 2px solid transparent; border-radius: 12px; min-height: 44px; padding: 6px 12px; font-weight: 700; font-size: .88rem; }
.chip[aria-pressed="true"] { border-color: #8c7fff; background: rgba(140, 127, 255, .28); }
.chip:focus-visible { outline: 3px solid #fff; outline-offset: 1px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 120;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: var(--shadow-lg);
  transition: opacity .2s, transform .25s var(--ease);
}
body.has-cta #toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
#editor.show ~ #toast { bottom: auto; top: calc(70px + env(safe-area-inset-top)); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#toast.error { background: var(--danger); color: #fff; }
#toast button { background: none; border: 0; color: inherit; font-weight: 800; text-decoration: underline; padding: 6px; }

/* Compléments */
.fieldset { border: 0; padding: 0; margin: 0 0 15px; min-width: 0; }
.fieldset legend { padding: 0; }
.t-compact { display: none; }
#dropzone.compact .t-full { display: none; }
#dropzone.compact .t-compact { display: inline; }
.center-cta { text-align: center; margin: 36px 0 0; }
@media (max-width: 520px) {
  #dropzone.compact .btn { white-space: nowrap; padding: 9px 12px; font-size: .9rem; gap: 6px; }
  #dropzone.compact .btn svg { width: 18px; height: 18px; }
}
@media (max-width: 360px) { #dropzone.compact .btn svg { display: none; } }
