:root {
    --bg: #F8F7F4;
    --card: #FFFFFF;
    --surface-alt: #F3F1EC;
    --text: #1C1B19;
    --muted: #78746C;
    --muted-light: #A6A199;
    --border: #E7E3DB;
    --primary: #3454D1;
    --primary-hover: #2941A8;
    --primary-tint: #EEF1FC;
    --primary-tint-border: #C9D3F7;
    --danger: #C4392B;
    --danger-tint: #FAEBE8;
    --danger-border: #F0C4BE;
    --ok: #1F7A4D;
    --ok-tint: #E7F5EC;
    --pending: #966008;
    --pending-dot: #B5730A;
    --pending-tint: #FBF1DF;
    --ink: #1C1B19;

    --radius: 14px;
    --radius-sm: 9px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --font-heading: 'Fraunces', Georgia, serif;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}

h1, h2 { font-family: var(--font-heading); }

a { color: var(--primary); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Barre supérieure ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: var(--space-4) var(--space-5);
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
    min-width: 0;
}

.topbar-brand {
    display: flex;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}
.topbar-brand:hover { opacity: 0.85; }

.topbar h1:not(.has-logo-link)::before,
.topbar-logo {
    content: "";
    display: block;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 23V9h3.2l5.8 8.4L21.8 9H25v14h-3.4V14.3l-5.1 7.4h-1.1l-5.1-7.4V23z' fill='%23ffffff'/%3E%3C/svg%3E") center/18px no-repeat;
}

.topbar-logo:hover { opacity: 0.85; }

.topbar .back {
    text-decoration: none;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-right: -4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.topbar .back:hover { background: var(--bg); color: var(--text); }

.logout {
    flex: none;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: var(--space-2) var(--space-1);
}
.logout:hover { color: var(--text); }

main {
    max-width: none;
    margin: var(--space-5) 0;
    padding: 0 var(--space-5) var(--space-6);
}

h2 {
    font-size: 1.35rem;
    font-weight: 600;
    margin: var(--space-6) 0 var(--space-3);
    letter-spacing: -0.01em;
}
h2 .section-count {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 1px 9px;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    vertical-align: middle;
}

.page-intro {
    margin: 0 0 var(--space-5);
}
.page-intro .count {
    font-family: var(--font-heading);
    font-size: 1.9rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0 0 6px;
}
.page-intro p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.empty-state {
    color: var(--muted);
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    text-align: center;
    margin: 0;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}
.badge-ok, .badge-applied { background: var(--ok-tint); color: var(--ok); }
.badge-pending, .badge-standard, .badge-approved { background: var(--pending-tint); color: var(--pending); }
.badge-failed, .badge-rejected { background: var(--danger-tint); color: var(--danger); }
.badge-mineure { background: var(--primary-tint); color: var(--primary); }

/* ---------- Actions ---------- */

.actions-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}
.actions-bar .buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

button {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    padding: 10px 16px;
    min-height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
button:hover { background: var(--bg); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { color: var(--danger); border-color: var(--danger-border); }
button.danger:hover { background: var(--danger-tint); }
button:disabled { opacity: 0.55; cursor: default; pointer-events: none; }

button.is-loading {
    position: relative;
    color: transparent !important;
}
button.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    color: inherit;
    animation: spin 0.7s linear infinite;
}
button.primary.is-loading::after { border-color: #ffffff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Liste des éditeurs (cartes) ---------- */

.editeurs-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.editeur-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 16px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.editeur-row:hover { border-color: var(--primary); background: #FBFAF7; }

.editeur-avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--primary-tint);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.9rem;
}

.editeur-info { flex-grow: 1; min-width: 0; }
.editeur-info .nom { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.editeur-info .date { font-size: 0.8rem; color: var(--muted-light); margin-top: 2px; }

/* ---------- Cartes de proposition (diff) ---------- */

.propositions-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.proposition-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.proposition-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}
.proposition-head input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--primary);
    cursor: pointer;
    flex: none;
}
.proposition-head .titres { flex-grow: 1; min-width: 0; }
.proposition-head .fiche { font-size: 0.95rem; font-weight: 600; }
.proposition-head .champ { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.proposition-head .refs { font-size: 0.78rem; color: var(--muted-light); margin-top: 2px; }

.diff-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}
@media (max-width: 700px) {
    .diff-grid { grid-template-columns: 1fr; }
}

.diff-box {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-alt);
}
.diff-box .label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-light);
    margin-bottom: 6px;
}
.diff-box .value {
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-line;
}
.diff-old .value { color: var(--muted); }
.diff-old .removed { text-decoration: line-through; }
.diff-seg + .diff-seg { margin-top: var(--space-2); }
.diff-gap {
    margin: var(--space-2) 0;
    font-size: 0.75rem;
    font-style: italic;
    font-weight: 400;
    color: var(--muted-light);
    text-align: center;
}
.diff-new {
    background: var(--primary-tint);
    border-color: var(--primary-tint-border);
}
.diff-new .label { color: var(--primary); }
.diff-new .value { color: var(--text); font-weight: 500; }

/* Diff mot à mot dans "Valeur proposée" (suivi des modifications, style Word) */
.diff-new .value ins {
    text-decoration: none;
    background: rgba(34, 197, 94, 0.3);
    color: #000000;
    border-radius: 3px;
    padding: 0 2px;
}
.diff-new .value del {
    text-decoration: line-through;
    background: rgba(239, 68, 68, 0.25);
    color: #000000;
    border-radius: 3px;
    padding: 0 2px;
}

.proposition-source { font-size: 0.75rem; color: var(--muted-light); }

/* ---------- Proposition de création (page ou catégorie CMS) ---------- */
.creation-fields {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-1) var(--space-4);
    margin: 0;
    font-size: 0.85rem;
}
.creation-fields dt { color: var(--muted); }
.creation-fields dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) {
    .creation-fields { grid-template-columns: 1fr; }
    .creation-fields dd { margin-bottom: var(--space-2); }
}
.creation-body .value {
    max-height: 320px;
    overflow: auto;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.78rem;
    font-weight: 400;
    overflow-wrap: anywhere;
}

/* ---------- Historique ---------- */

.historique-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.historique-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 12px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.historique-row .titres { flex-grow: 1; min-width: 0; }
.historique-row .fiche { font-size: 0.88rem; font-weight: 600; }
.historique-row .champ { font-size: 0.8rem; color: var(--muted); margin-top: 1px; }
.historique-row .refs { display: block; font-size: 0.75rem; color: var(--muted-light); margin-top: 1px; }
.historique-row .date { flex: none; font-size: 0.78rem; color: var(--muted-light); }
.historique-row .erreur {
    display: block;
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 2px;
    overflow-wrap: anywhere;
}
.historique-row .btn-delete-placeholder { flex: none; width: 30px; }
.historique-row .btn-delete {
    flex: none;
    padding: 2px 9px;
    font-size: 1rem;
    line-height: 1.2;
    color: var(--muted-light);
    border-color: transparent;
    background: transparent;
}
.historique-row .btn-delete:hover {
    color: var(--danger);
    border-color: var(--danger-border);
    background: var(--danger-tint);
}

.rapport {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}
.rapport ul {
    list-style: none;
    margin: var(--space-2) 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.rapport li {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 0.85rem;
}
.rapport li::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex: none;
    background: var(--ok);
}
.rapport li.echec { color: var(--danger); }
.rapport li.echec::before { background: var(--danger); }
.rapport .indexnow {
    margin: var(--space-2) 0 0;
    font-size: 0.8rem;
    color: var(--muted);
}

/* ---------- Connexion ---------- */

body.login-page {
    margin: 0;
    min-height: 100vh;
    display: flex;
}

.login-brand {
    width: 420px;
    flex: none;
    background: var(--ink);
    color: #FFFFFF;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-6);
}
.login-brand .mark {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.login-brand .mark::before {
    content: "";
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: none;
    background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 23V9h3.2l5.8 8.4L21.8 9H25v14h-3.4V14.3l-5.1 7.4h-1.1l-5.1-7.4V23z' fill='%23ffffff'/%3E%3C/svg%3E") center/18px no-repeat;
}
.login-brand .mark span {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #B5B0A6;
}
.login-brand .headline {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 2.2rem;
    line-height: 1.15;
    margin: 0;
}

.login-wrap {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.login-card {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.login-card .intro { margin: 0 0 var(--space-1); }
.login-card h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 0 0 4px;
    line-height: 1.3;
}
.login-card label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
}
.login-card input {
    padding: 11px 14px;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card);
}
.login-card input:focus {
    border-color: var(--primary);
}
.login-card button {
    margin-top: var(--space-1);
    justify-content: center;
}
.login-card .error {
    background: var(--danger-tint);
    color: var(--danger);
    font-size: 0.85rem;
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
}

@media (max-width: 700px) {
    .login-brand { display: none; }
}

/* ---------- Responsive ---------- */

@media (max-width: 700px) {
    main { padding: 0 var(--space-4) var(--space-5); margin: var(--space-4) auto; }
    .topbar { padding: var(--space-3) var(--space-4); }
    .topbar h1 { font-size: 1rem; }

    .actions-bar { flex-direction: column; align-items: stretch; }
    .actions-bar .buttons { flex-direction: column; }
    .actions-bar button { width: 100%; }

    .editeur-row { padding: 14px 16px; }
    .proposition-card { padding: var(--space-4); }
    .historique-row { flex-wrap: wrap; padding: 12px 16px; }
}
