:root {
    --night: #1A2744;
    --slate: #3D4F5F;
    --kraft: #F5F0E8;
    --terracotta: #C75B2A;
    --green: #16A34A;
    --red: #DC2626;
    --muted: #6B7280;
    --border: #E5E7EB;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--kraft);
    color: var(--slate);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: #2563EB; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ─────────────────────────────────────────── */
.header {
    background: var(--night);
    color: #fff;
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.header .brand { font-weight: 700; letter-spacing: 0.03em; }
.header .brand span { color: var(--terracotta); }
.header nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 1.1rem; }
.header nav a { color: #cbd5e1; font-size: 0.9rem; }
.header nav a:hover { color: #fff; }
.header nav a.active { color: #fff; font-weight: 600; }
.header .user-label { color: #9ca3af; font-size: 0.85rem; }

/* ─── Layout ─────────────────────────────────────────── */
.container { width: 100%; max-width: 760px; margin: 2rem auto; padding: 0 1rem; flex: 1; }
.container-wide { width: 100%; max-width: 960px; margin: 2rem auto; padding: 0 1rem; flex: 1; }
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* ─── Boutons ────────────────────────────────────────── */
.btn {
    display: inline-block;
    background: var(--terracotta);
    color: #fff;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 7px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { background: #a84a1f; text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 10px rgba(199, 91, 42, 0.25); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }
.btn-secondary { background: #e5e7eb; color: var(--slate); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }

/* ─── Formulaires ────────────────────────────────────── */
.input, select.input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
}
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; }
.field { margin-bottom: 1.1rem; }
.msg { padding: 0.7rem 1rem; border-radius: 7px; margin-bottom: 1rem; font-size: 0.9rem; }
.msg-ok { background: #dcfce7; color: #166534; }
.msg-error { background: #fee2e2; color: #991b1b; }

/* ─── Zone de glisser-déposer ────────────────────────── */
.dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: #fafafa;
    transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--terracotta); }
.dropzone.dragover {
    border-color: var(--terracotta);
    background: #fff5f0;
}
.dropzone .dz-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.dropzone .dz-text { font-weight: 600; }
.dropzone .dz-sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }
.dropzone .dz-file { margin-top: 0.8rem; font-size: 0.9rem; color: var(--green); font-weight: 600; word-break: break-all; }

/* ─── Toggle switch ──────────────────────────────────── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    font-weight: 500;
    user-select: none;
}
.toggle {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}
.toggle input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 999px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.toggle input:checked + .toggle-slider {
    background: var(--terracotta);
}
.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}
.toggle input:focus-visible + .toggle-slider {
    outline: 2px solid var(--terracotta);
    outline-offset: 2px;
}

/* ─── Tables ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ─── Zones document (historique par fichier d'origine) ─────────────── */
.doc-zone { margin-bottom: 1.25rem; padding: 1.1rem 1.3rem 1rem; }
.doc-zone-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}
.doc-zone-title { font-weight: 700; font-size: 1.02rem; word-break: break-all; }
.doc-zone-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.9rem;
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}
.doc-actions { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.version-badge {
    display: inline-block;
    background: var(--night);
    color: #fff;
    padding: 0.12rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* ─── Boutons icône (historique) — modernes, tooltip natif ───────────── */
.icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--slate);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.icon-btn:hover {
    transform: translateY(-2px);
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: 0 5px 14px rgba(15, 23, 42, 0.12);
    text-decoration: none;
}
.icon-btn:active { transform: translateY(0); }
.icon-btn:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }
/* Variante danger (suppression) */
.icon-btn-danger { color: var(--red); }
.icon-btn-danger:hover { background: #fef2f2; border-color: #fecaca; color: #b91c1c; box-shadow: 0 5px 14px rgba(220, 38, 38, 0.18); }
/* Variante accent (aperçu) */
.icon-btn-accent { color: var(--terracotta); }
.icon-btn-accent:hover { background: #fff5f0; border-color: #f0b79c; }
/* Tooltip natif (au-dessus, centré) */
.icon-btn::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--night);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 20;
}
.icon-btn::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--night);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 20;
}
.icon-btn:hover::after, .icon-btn:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.icon-btn:hover::before, .icon-btn:focus-visible::before { opacity: 1; }

/* Bouton principal « Régénérer » — pilule dégradée + label */
.btn-regen {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.48rem 0.85rem;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--terracotta) 0%, #e07b45 100%);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(199, 91, 42, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-regen svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-regen:hover { transform: translateY(-2px); box-shadow: 0 7px 18px rgba(199, 91, 42, 0.38); filter: brightness(1.04); }
.btn-regen:active { transform: translateY(0); }
.btn-regen:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }

/* Bouton fantôme (Annuler, modale) */
.btn-ghost {
    display: inline-block;
    background: transparent;
    color: var(--slate);
    border: 1.5px solid var(--border);
    padding: 0.55rem 1.1rem;
    border-radius: 7px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; transform: translateY(-1px); text-decoration: none; }
.btn-ghost:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }

/* ─── Barre de progression (compression) ───────────────────────────── */
.progress-track {
    background: #e5e7eb;
    border-radius: 999px;
    height: 14px;
    overflow: hidden;
    margin: 0.6rem 0 0.5rem;
}
.progress-fill {
    background: linear-gradient(90deg, var(--terracotta), #e07b45);
    height: 100%;
    width: 0%;
    border-radius: 999px;
    transition: width 0.5s ease;
}
.progress-pct { font-weight: 700; color: var(--terracotta); font-variant-numeric: tabular-nums; }

/* ─── Modale de prévisualisation ─────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 820px;
    height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1rem;
    background: var(--night);
    color: #fff;
}
.modal-head .title { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-close {
    background: none; border: none; color: #fff;
    font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0.2rem 0.4rem;
}
.modal-box iframe { flex: 1; width: 100%; border: none; }

/* ─── Viewer PDF (pdf.js) ────────────────────────────── */
.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: #f3f4f6;
    border-bottom: 1px solid var(--border);
}
.pdf-viewer {
    flex: 1;
    overflow: auto;
    background: #525659;
    display: flex;
    justify-content: center;
    padding: 12px;
}
.pdf-viewer canvas {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    max-width: 100%;
}

/* ─── Pied de page ───────────────────────────────────── */
.footer {
    background: var(--night);
    color: #9ca3af;
    text-align: center;
    padding: 1.2rem 1rem;
    font-size: 0.85rem;
    margin-top: 2rem;
}

/* ─── Responsive ─────────────────────────────────────── */
@media (max-width: 640px) {
    .header { padding: 0.75rem 1rem; flex-direction: column; align-items: flex-start; }
    .header nav { gap: 0.3rem 1rem; }
    .container, .container-wide { margin: 1.25rem auto; }
    .card { padding: 1.1rem; }
    .dropzone { padding: 2rem 1rem; }
    /* Tables → cartes empilées sur mobile */
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
    td {
        display: flex;
        justify-content: space-between;
        gap: 0.8rem;
        padding: 0.3rem 0;
        border: none;
        font-size: 0.88rem;
    }
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 0.72rem;
        text-transform: uppercase;
    }
    td.actions::before { display: none; }
}
