/* ---------- Thème ---------- */
:root {
    --bg: #f5f3ee;
    --surface: #ffffff;
    --surface-2: #faf8f4;
    --ink: #17151f;
    --muted: #6b6877;
    --line: #e7e3da;
    --accent: #ff5b2e;
    --accent-strong: #e8481c;
    --accent-soft: #ffece5;
    --ok: #12945a;
    --ok-soft: #e0f5ea;
    --err: #d13838;
    --err-soft: #fde9e9;
    --k-image: #7c5cff;
    --k-document: #2f7cf6;
    --k-audio: #e08a00;
    --k-video: #e0407f;
    --radius: 18px;
    --shadow: 0 1px 2px rgb(23 21 31 / .05), 0 12px 32px -12px rgb(23 21 31 / .14);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e0d12;
        --surface: #17161d;
        --surface-2: #1d1c25;
        --ink: #f3f1f7;
        --muted: #9a97a8;
        --line: #2a2833;
        --accent-soft: #3a1d14;
        --ok: #3ccf8e;
        --ok-soft: #12301f;
        --err: #ff7b7b;
        --err-soft: #3a1717;
        --k-image: #a08cff;
        --k-document: #6aa4ff;
        --k-audio: #ffb340;
        --k-video: #ff7aa8;
        --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 16px 40px -16px rgb(0 0 0 / .6);
    }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(900px 420px at 85% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
        var(--bg);
    color: var(--ink);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ---------- Mise en page ---------- */
.shell {
    width: min(100% - 32px, 760px);
    margin: 0 auto;
    padding: 20px 0 48px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 28px; }

.brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; text-decoration: none;
}
.brand-mark {
    display: grid; place-items: center; width: 34px; height: 34px;
    background: var(--accent); color: #fff; border-radius: 10px;
    box-shadow: 0 6px 16px -6px var(--accent);
}
.topbar-note { color: var(--muted); font-size: .85rem; }

.hero { padding: 8px 0 28px; }
.hero h1 {
    font-size: clamp(2rem, 6vw, 3.1rem); line-height: 1.05; letter-spacing: -.035em; font-weight: 800;
    text-wrap: balance;
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin-top: 14px; max-width: 52ch; color: var(--muted); font-size: 1.05rem; text-wrap: pretty; }

.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--radius) + 6px);
    padding: 20px; box-shadow: var(--shadow);
}

/* ---------- Niveaux ---------- */
.levels { border: 0; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.levels legend { padding: 0; margin-bottom: 10px; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.level { position: relative; display: block; cursor: pointer; }
.level input { position: absolute; opacity: 0; inset: 0; }
.level-body {
    display: grid; gap: 2px; height: 100%; padding: 12px 14px;
    border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface-2);
    transition: border-color .15s, background .15s, transform .15s;
}
.level:hover .level-body { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.level input:checked + .level-body { border-color: var(--accent); background: var(--accent-soft); }
.level input:focus-visible + .level-body { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.level-title { font-weight: 700; }
.level-desc { font-size: .8rem; color: var(--muted); line-height: 1.35; }

/* ---------- Zone de dépôt ---------- */
.dropzone {
    display: grid; justify-items: center; gap: 4px; text-align: center;
    padding: 36px 20px; border-radius: var(--radius); cursor: pointer;
    border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
    background: var(--surface-2);
    transition: background .2s, border-color .2s, transform .2s;
}
.dropzone:hover { background: var(--accent-soft); border-color: var(--accent); }
.dropzone-icon {
    display: grid; place-items: center; width: 60px; height: 60px; margin-bottom: 8px;
    color: var(--accent); background: var(--accent-soft); border-radius: 50%;
}
.dropzone-title { font-size: 1.15rem; letter-spacing: -.01em; }
.dropzone-sub { color: var(--muted); }
.dropzone-sub .link { color: var(--accent-strong); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.dropzone-limit { margin-top: 6px; font-size: .8rem; color: var(--muted); }

/* ---------- Formats ---------- */
.formats { display: grid; gap: 8px; margin-top: 16px; }
.format-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.format-label {
    display: inline-flex; align-items: center; gap: 6px; min-width: 104px;
    font-size: .8rem; font-weight: 700; color: var(--k);
}
.format-label svg { width: 16px; height: 16px; }
.format-group[data-kind="image"] { --k: var(--k-image); }
.format-group[data-kind="document"] { --k: var(--k-document); }
.format-group[data-kind="audio"] { --k: var(--k-audio); }
.format-group[data-kind="video"] { --k: var(--k-video); }
.format-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
    padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
    color: var(--k); background: color-mix(in srgb, var(--k) 12%, transparent);
}
.chip.is-off { opacity: .45; text-decoration: line-through; cursor: help; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px; border-radius: 12px; border: 1.5px solid transparent;
    font-weight: 650; text-decoration: none; white-space: nowrap;
    transition: background .15s, transform .1s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 13px; font-size: .88rem; border-radius: 10px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { border-color: var(--muted); color: var(--ink); }

.icon-btn {
    display: grid; place-items: center; width: 32px; height: 32px; padding: 0;
    border: 0; border-radius: 9px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Résultats ---------- */
.results { margin-top: 28px; }
.results-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.results h2 { font-size: 1.25rem; letter-spacing: -.02em; }
.summary { color: var(--muted); font-size: .9rem; min-height: 1.35em; }
.results-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
    --k: var(--muted);
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
    padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 1px 2px rgb(23 21 31 / .04);
    animation: item-in .25s ease both;
}
.item[data-kind="image"] { --k: var(--k-image); }
.item[data-kind="document"] { --k: var(--k-document); }
.item[data-kind="audio"] { --k: var(--k-audio); }
.item[data-kind="video"] { --k: var(--k-video); }
.item.is-leaving { opacity: 0; transform: scale(.98); transition: opacity .18s, transform .18s; }

.item-icon {
    display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
    color: var(--k); background: color-mix(in srgb, var(--k) 13%, transparent);
}
.is-error .item-icon { color: var(--err); background: var(--err-soft); }

.item-body { min-width: 0; display: grid; gap: 6px; }
.item-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.item-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item-size { flex: none; color: var(--muted); font-size: .85rem; }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: .86rem; color: var(--muted); }
.item-meta strong { color: var(--ink); }
.item-meta .was { text-decoration: line-through; text-decoration-thickness: 1px; }
.item-meta .note { color: var(--muted); }
.error-text { color: var(--err); }

.item-actions { display: flex; align-items: center; gap: 6px; }

.badge {
    flex: none; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
    background: var(--surface-2); color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--err-soft); color: var(--err); }

/* Barre de progression (envoi, puis traitement indéterminé) */
.progress { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--k) 14%, transparent); overflow: hidden; }
.progress-bar { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--k); transition: width .15s linear; }
.is-processing .progress-bar {
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--k), transparent);
    animation: slide 1.2s ease-in-out infinite;
}

/* Barre « avant / après » */
.compare { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--k) 14%, transparent); overflow: hidden; }
.compare-fill { display: block; height: 100%; border-radius: inherit; background: var(--k); animation: shrink .9s cubic-bezier(.2, .8, .2, 1) both; }

.foot { margin-top: 36px; text-align: center; color: var(--muted); font-size: .85rem; }

/* Voile affiché pendant un glisser-déposer sur la page */
.drop-overlay {
    position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 24px;
    background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(6px);
    pointer-events: none;
}
.drop-overlay span {
    padding: 28px 36px; border: 2.5px dashed var(--accent); border-radius: 24px;
    background: var(--surface); font-size: 1.2rem; font-weight: 700; text-align: center; box-shadow: var(--shadow);
}
.is-dragging .drop-overlay { display: grid; }
.is-dragging .dropzone { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Animations ---------- */
@keyframes item-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes shrink { from { width: 100%; } }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
    .card { padding: 14px; }
    .levels { grid-template-columns: 1fr; }
    .level-body { grid-template-columns: auto 1fr; align-items: baseline; gap: 2px 10px; }
    .dropzone { padding: 28px 14px; }
    .format-label { min-width: 100%; }
    .item { grid-template-columns: auto 1fr; }
    .item-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .topbar-note { display: none; }
}

/* ======================================================================
   Onglets et outils PDF
   ====================================================================== */
.tabs {
    display: flex; gap: 6px; padding: 5px; margin: 0 0 18px;
    background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 16px;
}
.tab {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 12px; border: 0; border-radius: 12px; background: transparent;
    color: var(--muted); font-weight: 650; transition: background .15s, color .15s;
}
.tab svg { width: 19px; height: 19px; flex: none; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
    background: var(--surface); color: var(--ink);
    box-shadow: 0 1px 2px rgb(23 21 31 / .1), 0 6px 14px -8px rgb(23 21 31 / .3);
}
.tab[aria-selected="true"] svg { color: var(--accent); }

.panel { display: grid; gap: 22px; align-content: start; }
.panel[hidden] { display: none; }
.panel-intro { margin-bottom: 16px; color: var(--muted); text-wrap: pretty; }
.panel-intro strong { color: var(--ink); }

.stack { display: grid; gap: 10px; }
.stack:empty { display: none; }

.hint { margin: 10px 0 0; font-size: .88rem; color: var(--muted); }
.hint:empty { display: none; }

.alert {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
    border-radius: 12px; background: var(--err-soft); color: var(--err); font-size: .92rem;
}
.alert svg { flex: none; width: 20px; height: 20px; margin-top: 1px; }
#split-error:empty { display: none; }

/* Chargement : le dépôt se met en veille pendant l'envoi */
.panel.is-busy .dropzone { opacity: .55; pointer-events: none; }
.panel.is-busy .dropzone-icon { animation: pulse 1s ease-in-out infinite; }
form[aria-busy="true"] { opacity: .75; }

.dropzone-icon svg { width: 30px; height: 30px; }

/* Fusion : liste réordonnable */
.merge-form { margin-top: 18px; display: grid; gap: 12px; }
.merge-form[hidden] { display: none; }
.sortlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sort-item {
    --k: var(--k-document);
    display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 10px;
    padding: 8px 10px 8px 8px; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 12px; cursor: grab;
}
.sort-item:active { cursor: grabbing; }
.sort-item.is-dragged { opacity: .4; }
.grip { display: grid; place-items: center; color: var(--muted); }
.sort-index {
    display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
    font-size: .8rem; font-weight: 700; color: var(--k);
    background: color-mix(in srgb, var(--k) 13%, transparent);
}
.sort-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sort-size { color: var(--muted); font-size: .85rem; }
.sort-actions { display: flex; gap: 2px; }

.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn:disabled:hover { background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.field { display: grid; gap: 4px; flex: 1 1 220px; font-size: .82rem; font-weight: 700; color: var(--muted); }

/* Fusion : aperçu avant validation */
.preview-card {
    --k: var(--k-document);
    display: grid; gap: 12px; padding: 14px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 1px 2px rgb(23 21 31 / .04);
    animation: item-in .25s ease both;
}
.preview-head { display: flex; align-items: center; gap: 14px; }
.preview-head .item-body { flex: 1; gap: 2px; }
.preview-head .badge { background: var(--accent-soft); color: var(--accent-strong); }
.preview-frame {
    width: 100%; height: min(66vh, 520px); border: 1px solid var(--line);
    border-radius: 12px; background: var(--surface-2);
}
.preview-note { font-size: .86rem; color: var(--muted); }
.preview-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.preview-actions form { margin: 0; }

input[type="text"], input[type="number"] {
    width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line);
    background: var(--surface); color: var(--ink); font: inherit; font-weight: 500;
}
input[type="text"]:focus, input[type="number"]:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Séparation : options */
.workbench { margin-top: 18px; display: grid; gap: 18px; }
.source-card {
    --k: var(--k-document);
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
    padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2);
}
.source-card .item-body { gap: 2px; }
.source-card .item-meta { display: block; }

.split-form { display: grid; gap: 14px; }
.levels.modes { grid-template-columns: repeat(4, 1fr); margin: 0; }

.mode-field { display: none; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--muted); }
.mode-field small { font-weight: 500; line-height: 1.4; }
.split-form:has(input[name="mode"][value="every"]:checked) .field-every,
.split-form:has(input[name="mode"][value="ranges"]:checked) .field-ranges,
.split-form:has(input[name="mode"][value="extract"]:checked) .field-extract { display: grid; }
@supports not selector(:has(*)) {
    .mode-field { display: grid; }
}

.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.parts { max-height: 440px; overflow: auto; padding: 2px; margin: -2px; }

@keyframes pulse { 50% { transform: scale(1.12); } }

@media (max-width: 560px) {
    .tab svg { display: none; }
    .tab { padding: 10px 6px; font-size: .92rem; }
    .levels.modes { grid-template-columns: 1fr 1fr; }
    .sort-item { grid-template-columns: auto 1fr auto; }
    .sort-item .grip, .sort-size { display: none; }
    .source-card { grid-template-columns: auto 1fr; }
    .source-card .btn { grid-column: 1 / -1; }
    .preview-head { flex-wrap: wrap; }
    .preview-head .btn { margin-left: auto; }
    .preview-frame { height: 60vh; }
    .preview-actions { justify-content: stretch; }
    .preview-actions form, .preview-actions .btn { flex: 1 1 auto; }
    .preview-actions form .btn { width: 100%; }
}
