/* PDF Studio — interface */
:root {
  --bg: #eceff5;
  --surface: #ffffff;
  --surface-2: #f3f5fa;
  --text: #121830;
  --muted: #5d6784;
  --border: #dde2ee;
  --accent: #3a3fd9;
  --accent-ink: #ffffff;
  --accent-soft: #e8e9fc;
  --mark: #ffe14d;
  --danger: #d6264a;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(18, 24, 48, .06), 0 10px 30px rgba(18, 24, 48, .10);
  --radius: 12px;
  --font: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1220; --surface: #161b2e; --surface-2: #1d2340; --text: #e8ebf7; --muted: #98a2c3;
    --border: #283052; --accent: #7a80ff; --accent-ink: #0e1220; --accent-soft: #232a55;
    --danger: #ff6b8a; --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 30px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { display: block; }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px;
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-soft:hover { filter: brightness(.97); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -.02em; font-size: 19px; }

/* ====================================================================== */
/* ACCUEIL                                                                 */
/* ====================================================================== */
.home { min-height: 100vh; display: flex; flex-direction: column; }
.site-head { display: flex; align-items: center; justify-content: space-between; padding: 20px clamp(18px, 5vw, 56px); }
.head-note { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.hero { width: 100%; max-width: 860px; margin: 0 auto; padding: clamp(24px, 6vh, 64px) 20px 48px; flex: 1; }
.hero h1 { font-size: clamp(36px, 6.4vw, 64px); line-height: 1.03; letter-spacing: -.035em; margin: 0 0 18px; font-weight: 800; }
.lede { font-size: clamp(16px, 2vw, 19px); color: var(--muted); max-width: 56ch; margin: 0 0 32px; }
.alert { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--text); padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; }

.drop {
  position: relative; display: flex; align-items: center; gap: 28px; padding: 30px 34px; cursor: pointer;
  background: var(--surface); border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: 20px;
  transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
}
.drop:hover, .drop.hot { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--shadow); }
.drop.hot { transform: scale(1.012); }
.sheet {
  position: relative; flex: none; width: 74px; height: 96px; background: #fff; border-radius: 6px 18px 6px 6px;
  box-shadow: 0 0 0 1px var(--border), 0 8px 18px rgba(18, 24, 48, .14); transform: rotate(-4deg); transition: transform .2s;
}
.sheet::after { content: ""; position: absolute; top: 0; right: 0; width: 20px; height: 20px; background: var(--surface-2); border-radius: 0 0 0 8px; box-shadow: -1px 1px 0 var(--border); }
.drop:hover .sheet, .drop.hot .sheet { transform: rotate(0deg) translateY(-3px); }
.sheet-line { position: absolute; left: 12px; height: 5px; border-radius: 3px; background: #c9cfe2; }
.sheet-line.l1 { top: 30px; width: 48px; } .sheet-line.l2 { top: 44px; width: 40px; } .sheet-line.l3 { top: 58px; width: 46px; }
.sheet-mark { position: absolute; left: 10px; top: 41px; width: 44px; height: 11px; background: var(--mark); opacity: .75; border-radius: 2px; mix-blend-mode: multiply; }
.drop-text { display: flex; flex-direction: column; gap: 4px; }
.drop-text strong { font-size: clamp(20px, 3vw, 26px); letter-spacing: -.02em; }
.drop-text span { color: var(--muted); }

.progress-card { margin-top: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; box-shadow: var(--shadow); }
.pc-top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.pc-ico { color: var(--accent); }
.pc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pc-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-info small { color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .2s; }
.pc-err { margin-top: 12px; color: var(--danger); font-weight: 600; }

.facts { list-style: none; display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 28px 0 0; padding: 0; color: var(--muted); font-size: 14px; }
.facts li { display: inline-flex; align-items: center; gap: 8px; }
.facts svg { color: var(--accent); }

.recent { margin-top: 48px; }
.recent h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -.01em; }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent li { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px 10px 16px; }
.r-ico { color: var(--accent); }
.r-main { flex: 1; min-width: 0; display: flex; flex-direction: column; color: inherit; text-decoration: none; }
.r-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-main small { color: var(--muted); }
.site-foot { text-align: center; color: var(--muted); font-size: 13px; padding: 22px 20px 28px; max-width: 70ch; margin: 0 auto; }

/* ====================================================================== */
/* ÉDITEUR                                                                 */
/* ====================================================================== */
body.editor { height: 100vh; height: 100dvh; display: grid; grid-template-rows: 56px 52px minmax(0, 1fr); overflow: hidden; }

.topbar { display: flex; align-items: center; gap: 6px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { padding: 4px 6px; }
.doc-name { font-weight: 650; max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0 12px 0 4px; }
.top-actions { display: flex; gap: 2px; padding-left: 12px; border-left: 1px solid var(--border); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 13px; white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip[data-state="saving"] i { background: #f59e0b; }
.chip[data-state="error"] i, .chip[data-state="toolarge"] i { background: var(--danger); }
.chip-time.urgent { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

.optbar { display: flex; align-items: center; gap: 18px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.optbar > * { flex: none; }
.optbar .hint { color: var(--muted); font-size: 14px; }
.opt-title { font-weight: 700; font-size: 14px; padding-right: 4px; }
.opt { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.opt input[type="range"] { width: 110px; accent-color: var(--accent); }
.opt output { min-width: 42px; color: var(--text); font-variant-numeric: tabular-nums; }
.opt select { height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 8px; }
.swatches { gap: 6px; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--surface); background: var(--c); box-shadow: 0 0 0 1px var(--border); padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--accent); }
.colorpick { width: 30px; height: 30px; padding: 0; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.toggle { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--muted); }
.toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.spacer { flex: 1; }

.workspace { display: grid; grid-template-columns: 76px 184px minmax(0, 1fr); min-height: 0; }
body.no-side .workspace { grid-template-columns: 76px 0 minmax(0, 1fr); }
body.no-side .sidebar { visibility: hidden; border: 0; }

.rail { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 10px 8px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.rail hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px 6px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); transition: background .12s, color .12s; }
.tool small { font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.on { background: var(--accent); color: var(--accent-ink); }

.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 16px; font-size: 14px; }
.thumbs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 6px 0 24px; }
.thumb { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; padding: 6px; border-radius: 10px; border: 2px solid transparent; }
.thumb:hover { background: var(--surface-2); }
.thumb.on { border-color: var(--accent); background: var(--accent-soft); }
.thumb.over { border-color: var(--accent); border-style: dashed; }
.tbox { position: relative; background: #fff; box-shadow: 0 0 0 1px var(--border), 0 2px 6px rgba(18, 24, 48, .12); overflow: hidden; }
.tnum { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb.on .tnum { color: var(--accent); font-weight: 700; }

.stage { position: relative; min-width: 0; min-height: 0; }
.scroller { position: absolute; inset: 0; overflow: auto; background: var(--bg); }
.viewer { position: relative; width: max-content; min-width: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 22px 24px 140px; }
.page { position: relative; flex: none; background: #fff; box-shadow: 0 0 0 1px rgba(18, 24, 48, .07), var(--shadow); }
.inner { position: absolute; left: 50%; top: 50%; transform-origin: center; }
.inner canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; touch-action: pan-y pinch-zoom; }
.viewer[data-tool="select"] .layer { cursor: default; }
.viewer:not([data-tool="select"]) .layer { cursor: crosshair; }
.viewer[data-tool="text"] .layer { cursor: text; }
.viewer[data-tool="ink"] .layer, .viewer[data-tool="highlight"] .layer, .viewer[data-tool="rect"] .layer, .viewer[data-tool="ellipse"] .layer, .viewer[data-tool="line"] .layer, .viewer[data-tool="whiteout"] .layer { touch-action: none; }
.viewer[data-tool="select"] [data-aid] { cursor: move; }
.viewer[data-tool="edittext"] .layer { cursor: default; }
.tlayer { position: absolute; inset: 0; pointer-events: none; }
.viewer:not([data-tool="edittext"]) .tlayer { display: none; }
.tblk { position: absolute; pointer-events: auto; cursor: text; border-radius: 2px; outline: 1px dashed color-mix(in srgb, var(--accent) 35%, transparent); }
.tblk:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); outline: 1.5px solid var(--accent); }
.tblk.on { background: color-mix(in srgb, var(--accent) 30%, transparent); outline: 1.5px solid var(--accent); }
.tedit { position: absolute; z-index: 4; white-space: pre; border-radius: 2px; outline: 2px solid var(--accent); user-select: text; -webkit-user-select: text; cursor: text; }

.vec { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.ah { position: absolute; user-select: none; -webkit-user-select: none; }
.ah.txt { white-space: pre; outline: 1px dashed transparent; border-radius: 2px; }
.viewer[data-tool="select"] .ah.txt:hover { outline-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.ah.txt.sel { outline: 1.5px solid var(--accent); }
.ah.txt.editing { user-select: text; -webkit-user-select: text; cursor: text; outline: 1.5px solid var(--accent); background: rgba(255, 255, 255, .6); min-width: 2em; }
.ah.img { object-fit: fill; -webkit-user-drag: none; }

.selbox { position: absolute; border: 1.5px solid var(--accent); pointer-events: none; }
.selbox.line { border: 0; inset: 0; }
.hd { position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; pointer-events: auto; touch-action: none; }
.selbox:not(.line) .hd[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.selbox .hd[data-h="n"] { left: 50%; top: 0; cursor: ns-resize; }
.selbox .hd[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.selbox .hd[data-h="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.selbox .hd[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.selbox .hd[data-h="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.selbox .hd[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.selbox .hd[data-h="w"] { left: 0; top: 50%; cursor: ew-resize; }
.selbox.line .hd { border-radius: 50%; cursor: grab; }

.page-pill { position: absolute; top: 8px; right: 8px; display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); opacity: 0; transition: opacity .15s; z-index: 5; }
.page:hover .page-pill, .page:focus-within .page-pill { opacity: 1; }
.page-pill button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); }
.page-pill button:hover { background: var(--surface-2); color: var(--text); }
.pg-num { padding: 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); }

.navpill { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 5px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 99px; box-shadow: var(--shadow); z-index: 10; }
.navpill .pg { font-size: 13px; color: var(--muted); padding: 0 6px; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.navpill .pg b { color: var(--text); }
.navpill .sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.zoom-label { min-width: 58px; height: 32px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.zoom-label:hover { background: var(--surface-2); }

/* ---------- fenêtres, toasts, chargement ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(8, 12, 28, .5); backdrop-filter: blur(3px); }
.modal { width: min(600px, 100%); background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 10px; font-size: 19px; letter-spacing: -.01em; }
.modal p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.sigpad { display: block; width: 100%; height: auto; aspect-ratio: 560 / 200; background: repeating-linear-gradient(transparent, transparent 38px, var(--border) 38px, var(--border) 39px), var(--surface-2); border: 1px solid var(--border); border-radius: 12px; touch-action: none; cursor: crosshair; }
.sig-colors { display: flex; gap: 8px; margin-top: 10px; }

.busy { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(8, 12, 28, .45); backdrop-filter: blur(2px); }
.busy-card { display: flex; align-items: center; gap: 14px; background: var(--surface); padding: 18px 24px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; }
.spin { width: 22px; height: 22px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toasts { position: fixed; top: 70px; right: 16px; z-index: 150; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(-6px); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  body.editor { grid-template-rows: 54px 50px minmax(0, 1fr); }
  .doc-name, .top-actions { display: none; }
  .chip-time, #save-status span { display: none; }
  .top-right .lbl { display: none; }
  .top-right .btn { width: 40px; padding: 0; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 62px; }
  .rail { order: 2; flex-direction: row; justify-content: flex-start; overflow-x: auto; overflow-y: hidden; border-right: 0; border-top: 1px solid var(--border); padding: 6px 8px; }
  .rail hr { width: 1px; height: 36px; border: 0; border-left: 1px solid var(--border); margin: 0 4px; align-self: center; }
  .tool { min-width: 58px; }
  .stage { order: 1; }
  .sidebar { position: fixed; top: 104px; left: 0; bottom: 62px; width: 170px; z-index: 40; box-shadow: var(--shadow); }
  body.no-side .workspace { grid-template-columns: minmax(0, 1fr); }
  body.no-side .sidebar { display: none; }
  body:not(.no-side) .sidebar { display: flex; }
  .viewer { padding: 14px 10px 130px; }
  .navpill { bottom: 12px; }
  .hero h1 { margin-bottom: 14px; }
  .drop { flex-direction: column; text-align: center; padding: 26px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: .01ms !important; }
}
