/* ---------- AI-MA — Styles globaux ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f6f8;
    color: #1d2330;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Header ---------- */
.aima-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
    color: #fff;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.aima-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: inline-block;
}

.aima-header .subtitle {
    font-size: 0.85rem;
    opacity: 0.85;
    margin-left: 0.75rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.user-name {
    opacity: 0.95;
}

.logout-link {
    color: #fff;
    text-decoration: none;
    padding: 0.35rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    transition: background 0.2s, border-color 0.2s;
}

.logout-link:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.7);
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 1.5rem;
}

/* ---------- Login ---------- */
.login-container {
    width: 100%;
    max-width: 400px;
    margin-top: 3rem;
}

.login-form {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form h2 {
    font-size: 1.4rem;
    color: #1e3a8a;
}

.login-subtitle {
    font-size: 0.9rem;
    color: #6b7280;
    margin-top: -0.5rem;
    margin-bottom: 0.5rem;
}

.login-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: #374151;
    gap: 0.3rem;
}

.login-form input {
    padding: 0.6rem 0.8rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
}

.login-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-form button {
    margin-top: 0.5rem;
    padding: 0.7rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-form button:hover {
    background: #1d4ed8;
}

.alert {
    padding: 0.6rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ---------- Navigation ---------- */
.header-nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    color: #fff;
    text-decoration: none;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ---------- Page contrat ---------- */
.contract-page {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.contract-form-container, .result-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.5rem 2rem;
}

.contract-form-container h2 {
    color: #1e3a8a;
    margin-bottom: 0.25rem;
}

.form-subtitle {
    color: #6b7280;
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.form-row label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #374151;
}

.form-row textarea,
.form-row input[type="file"],
.form-row select {
    padding: 0.6rem 0.8rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
}

.form-row textarea {
    resize: vertical;
    min-height: 120px;
}

.form-row textarea:focus,
.form-row select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-hint {
    font-size: 0.78rem;
    color: #6b7280;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.primary-btn {
    padding: 0.8rem 1.5rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.primary-btn:disabled {
    background: #93b1e0;
    cursor: not-allowed;
}

.secondary-btn {
    padding: 0.45rem 0.9rem;
    background: #f3f4f6;
    color: #1f2937;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: #e5e7eb;
}

/* ---------- Résultat (contrat généré) ---------- */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.result-header h3 {
    color: #1e3a8a;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
}

.contract-render {
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.5rem 1.75rem;
    line-height: 1.7;
    font-size: 0.95rem;
    color: #1f2937;
    max-height: 70vh;
    overflow-y: auto;
}

/* RTL support pour contenus arabes (et autres langues RTL) */
.contract-render[dir="rtl"],
.changes-text[dir="rtl"] {
    text-align: right;
    font-family: "Noto Sans Arabic", "Geeza Pro", "Damascus", -apple-system,
                  BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.contract-render[dir="rtl"] ul,
.contract-render[dir="rtl"] ol,
.changes-text[dir="rtl"] ul,
.changes-text[dir="rtl"] ol {
    margin-right: 1.5rem;
    margin-left: 0;
}

.contract-render[dir="rtl"] hr {
    margin: 1.5rem 0;
}

.contract-render h1 { font-size: 1.4rem; margin: 0.5rem 0 0.75rem; color: #1e3a8a; }
.contract-render h2 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; color: #1e3a8a; }
.contract-render h3 { font-size: 1.02rem; margin: 1rem 0 0.4rem; color: #1f2937; }
.contract-render p { margin: 0.5rem 0; }
.contract-render ul, .contract-render ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.contract-render li { margin: 0.2rem 0; }
.contract-render code { background: #eef1f6; padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }
.contract-render strong { color: #111827; }
.contract-render hr { margin: 1.5rem 0; border: none; border-top: 1px solid #e5e7eb; }

.result-meta {
    margin-top: 1rem;
    font-size: 0.78rem;
    color: #6b7280;
    text-align: right;
}

/* ---------- Version badge + itération ---------- */
.version-badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.15rem 0.6rem;
    background: #2563eb;
    color: #fff;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    vertical-align: middle;
}

.iterate-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.5rem 2rem;
}

.iterate-section h3 {
    color: #1e3a8a;
    margin-bottom: 0.4rem;
}

.iterate-section h4 {
    font-size: 0.95rem;
    color: #374151;
    margin: 0.75rem 0 0.5rem;
}

.iterate-section textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    margin-bottom: 0.75rem;
}

.iterate-section textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.iteration-history {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    color: #374151;
}

.iteration-history:empty {
    display: none;
}

.iteration-history ol {
    margin: 0.25rem 0 0.5rem 1.5rem;
}

.iteration-history li {
    margin: 0.3rem 0;
    line-height: 1.4;
}

/* ---------- Page "Mes contrats" ---------- */
.contracts-page {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
}

.contracts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.contracts-header h2 {
    color: #1e3a8a;
    font-size: 1.5rem;
}

.contracts-header a.primary-btn {
    text-decoration: none;
    display: inline-block;
}

.contracts-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.contract-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.1rem 1.4rem;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1.5rem;
    align-items: center;
}

.contract-card-main {
    min-width: 0;
}

.contract-card-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: #1f2937;
    margin-bottom: 0.35rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.contract-card-meta {
    font-size: 0.82rem;
    color: #6b7280;
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.contract-card-scores {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.score-block {
    text-align: center;
    padding: 0.3rem 0.7rem;
    background: #f3f4f6;
    border-radius: 8px;
    min-width: 64px;
}

.score-block-label {
    font-size: 0.68rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-block-value {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.1;
}

.score-block-value.score-good { color: #16a34a; }
.score-block-value.score-medium { color: #ea580c; }
.score-block-value.score-bad { color: #dc2626; }
.score-block-value.score-critical { color: #991b1b; }

.score-delta-big {
    font-size: 0.78rem;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
}

.score-delta-big .delta-up { color: #16a34a; }
.score-delta-big .delta-down { color: #dc2626; }
.score-delta-big .delta-flat { color: #6b7280; }

.contract-card-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: stretch;
    min-width: 140px;
}

.contract-card-actions button {
    width: 100%;
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
}

.danger-btn {
    padding: 0.4rem 0.85rem;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.danger-btn:hover {
    background: #fee2e2;
}

@media (max-width: 800px) {
    .contract-card {
        grid-template-columns: 1fr;
    }
    .contract-card-row {
        grid-template-columns: 1fr;
    }
    .contract-card-scores {
        justify-content: flex-start;
    }
    .contract-card-actions {
        flex-direction: row;
    }
}

/* Card avec dépliage de versions */
.contract-card {
    display: block;
    padding: 0;
}

.contract-card-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1.5rem;
    align-items: center;
    padding: 1.1rem 1.4rem;
}

.versions-toggle {
    background: transparent;
    border: none;
    color: #2563eb;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-size: 0.82rem;
    font-family: inherit;
}

.versions-toggle:hover {
    text-decoration: underline;
}

.contract-versions-panel {
    border-top: 1px solid #e5e7eb;
    background: #fafbfc;
    padding: 0.75rem 1.4rem 1rem;
}

.contract-versions-loading {
    color: #6b7280;
    font-size: 0.88rem;
    padding: 0.5rem 0;
}

.versions-timeline {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.version-row {
    display: grid;
    grid-template-columns: 60px 60px 1fr auto;
    gap: 0.85rem;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.version-label {
    font-weight: 700;
    color: #1e3a8a;
    font-size: 0.92rem;
}

.version-score {
    text-align: center;
    padding: 0.25rem 0.5rem;
    background: #f3f4f6;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.95rem;
}

.version-score.score-good { color: #16a34a; background: #dcfce7; }
.version-score.score-medium { color: #ea580c; background: #fed7aa; }
.version-score.score-bad { color: #dc2626; background: #fee2e2; }
.version-score.score-critical { color: #991b1b; background: #fecaca; }

.version-info {
    min-width: 0;
    font-size: 0.85rem;
    color: #1f2937;
}

.version-type {
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.15rem;
}

.version-request-short {
    color: #6b7280;
    font-style: italic;
    margin-bottom: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.version-clause {
    color: #6b7280;
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

.version-date {
    color: #9ca3af;
    font-size: 0.75rem;
}

.see-version-btn {
    white-space: nowrap;
}

.version-request-short[data-tooltip],
.version-clause[data-tooltip] {
    cursor: help;
}

/* ---------- Tooltip global au survol (simple ou riche) ---------- */
.global-tooltip {
    position: absolute;
    z-index: 9999;
    max-width: 520px;
    background: #1f2937;
    color: #fff;
    padding: 0.65rem 0.95rem;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.5;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    word-wrap: break-word;
    white-space: normal;
}

.global-tooltip.tooltip-simple {
    max-width: 480px;
    font-size: 0.82rem;
}

/* Tooltip riche pour les versions */
.global-tooltip .tt-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-bottom: 0.55rem;
    margin-bottom: 0.55rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.global-tooltip .tt-version-label {
    font-weight: 800;
    color: #93c5fd;
    font-size: 0.95rem;
}

.global-tooltip .tt-type {
    color: #d1d5db;
    font-size: 0.85rem;
}

.global-tooltip .tt-score {
    margin-left: auto;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.78rem;
    background: rgba(255, 255, 255, 0.1);
}

.global-tooltip .tt-score.score-good { background: #166534; color: #dcfce7; }
.global-tooltip .tt-score.score-medium { background: #9a3412; color: #fed7aa; }
.global-tooltip .tt-score.score-bad { background: #991b1b; color: #fee2e2; }
.global-tooltip .tt-score.score-critical { background: #7f1d1d; color: #fecaca; }

.global-tooltip .tt-section {
    margin-bottom: 0.55rem;
}

.global-tooltip .tt-section:last-of-type {
    margin-bottom: 0;
}

.global-tooltip .tt-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #93c5fd;
    margin-bottom: 0.2rem;
    font-weight: 600;
}

.global-tooltip .tt-value {
    color: #f3f4f6;
    font-size: 0.85rem;
    line-height: 1.5;
}

.global-tooltip .tt-footer {
    margin-top: 0.6rem;
    padding-top: 0.45rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.7rem;
    color: #9ca3af;
    text-align: right;
}

.version-row {
    cursor: default;
    transition: background 0.12s;
}

.version-row.hovered {
    background: #eff6ff;
    border-color: #2563eb;
}

/* Layout 2 colonnes : liste versions à gauche, détails sticky à droite */
.versions-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.versions-list-col {
    min-width: 0;
}

.versions-hint {
    margin-top: 0.6rem;
    font-size: 0.78rem;
    color: #6b7280;
    font-style: italic;
}

.version-details-col {
    min-width: 0;
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 80px);
}

.version-details-panel {
    background: #1f2937;
    color: #fff;
    border-radius: 12px;
    padding: 1rem 1.2rem;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    font-size: 0.86rem;
    line-height: 1.5;
}

.version-details-panel:empty::before {
    content: '💡 Survolez une version à gauche pour voir ses détails ici.';
    color: #9ca3af;
    font-style: italic;
}

/* Reprendre les styles tt-* du tooltip riche dans le panneau */
.version-details-panel .tt-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-bottom: 0.6rem;
    margin-bottom: 0.7rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.version-details-panel .tt-version-label {
    font-weight: 800;
    color: #93c5fd;
    font-size: 1rem;
}

.version-details-panel .tt-type {
    color: #d1d5db;
    font-size: 0.9rem;
}

.version-details-panel .tt-score {
    margin-left: auto;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.82rem;
    background: rgba(255, 255, 255, 0.1);
}

.version-details-panel .tt-score.score-good { background: #166534; color: #dcfce7; }
.version-details-panel .tt-score.score-medium { background: #9a3412; color: #fed7aa; }
.version-details-panel .tt-score.score-bad { background: #991b1b; color: #fee2e2; }
.version-details-panel .tt-score.score-critical { background: #7f1d1d; color: #fecaca; }

.version-details-panel .tt-section {
    margin-bottom: 0.7rem;
}

.version-details-panel .tt-section:last-of-type {
    margin-bottom: 0;
}

.version-details-panel .tt-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #93c5fd;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.version-details-panel .tt-value {
    color: #f3f4f6;
    font-size: 0.88rem;
    line-height: 1.55;
}

.version-details-panel .tt-footer {
    margin-top: 0.8rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.72rem;
    color: #9ca3af;
    text-align: right;
}

@media (max-width: 900px) {
    .versions-split {
        grid-template-columns: 1fr;
    }
    .version-details-col {
        position: static;
        max-height: none;
    }
    .version-details-panel {
        max-height: 50vh;
    }
}

.global-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
}

.global-tooltip:not(.tooltip-below)::after {
    top: 100%;
    border-top-color: #1f2937;
}

.global-tooltip.tooltip-below::after {
    bottom: 100%;
    border-bottom-color: #1f2937;
}

/* ---------- Bouton "Corriger" + entête de clause ---------- */
.clause-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.correct-btn {
    padding: 0.25rem 0.7rem;
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fdba74;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.correct-btn:hover {
    background: #fed7aa;
    border-color: #f97316;
}

.correct-btn:active {
    transform: translateY(1px);
}

/* ---------- Modal de correction ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1.5rem;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    max-width: 720px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.75rem 2rem;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.modal-close:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.modal-content h3 {
    color: #1e3a8a;
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.correction-clause-info {
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.correction-row {
    margin-bottom: 0.85rem;
    font-size: 0.92rem;
    color: #1f2937;
}

.correction-row:last-child {
    margin-bottom: 0;
}

.correction-row strong {
    color: #1e3a8a;
}

.correction-row p {
    margin-top: 0.25rem;
    line-height: 1.55;
}

.correction-quote {
    margin-top: 0.4rem;
    padding: 0.6rem 0.85rem;
    background: #fff;
    border-left: 3px solid #2563eb;
    border-radius: 4px;
    font-style: italic;
    color: #374151;
    font-size: 0.88rem;
    line-height: 1.5;
}

.correction-row textarea {
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.6rem 0.85rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    resize: vertical;
}

.correction-row textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.correction-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

/* ---------- Workspace unifié ---------- */
.workspace-page {
    width: 100%;
    max-width: 1400px;
}

/* Étape A : entry section */
.entry-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 2rem;
    max-width: 900px;
    margin: 0 auto;
}

.entry-section > h2 {
    color: #1e3a8a;
    margin-bottom: 0.5rem;
}

.entry-tabs {
    display: flex;
    gap: 0.5rem;
    margin: 1.5rem 0 1rem;
    border-bottom: 2px solid #e5e7eb;
}

.entry-tab-btn {
    padding: 0.7rem 1.2rem;
    background: transparent;
    color: #6b7280;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.entry-tab-btn:hover {
    color: #1e3a8a;
}

.entry-tab-btn.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

.entry-tab-content {
    display: none;
}

.entry-tab-content.active {
    display: block;
}

/* Étape B : workspace grid */
.workspace-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.versions-sidebar {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.sidebar-header h3 {
    font-size: 1rem;
    color: #1e3a8a;
}

.secondary-btn.small {
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
}

.versions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    background: #f3f4f6;
    transition: background 0.15s;
    font-size: 0.88rem;
}

.version-item:hover {
    background: #e5e7eb;
}

.version-item.active {
    background: #2563eb;
    color: #fff;
}

.version-item-label {
    font-weight: 600;
}

.version-item-score {
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: #fff;
    color: #1f2937;
    font-size: 0.75rem;
    font-weight: 700;
}

.version-item.active .version-item-score {
    color: #1f2937;
}

.version-item-score.score-good { background: #dcfce7; color: #166534; }
.version-item-score.score-medium { background: #fed7aa; color: #9a3412; }
.version-item-score.score-bad { background: #fee2e2; color: #991b1b; }
.version-item-score.score-critical { background: #fecaca; color: #7f1d1d; }

.workspace-main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.workspace-toolbar {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

.small-btn {
    padding: 0.5rem 0.95rem !important;
    font-size: 0.88rem !important;
}

.nav-link-btn {
    text-decoration: none;
    display: inline-block;
}

/* Sidebar "+ Nouveau" plus visible */
.sidebar-header .secondary-btn.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    font-weight: 600;
}

.sidebar-header .secondary-btn.small:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* Version header */
.version-header {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.25rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1.5rem;
    align-items: center;
}

.version-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.version-badge-big {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.version-badge-big.score-good { background: #16a34a; }
.version-badge-big.score-medium { background: #ea580c; }
.version-badge-big.score-bad { background: #dc2626; }
.version-badge-big.score-critical { background: #991b1b; }

.version-meta {
    min-width: 0;
    overflow: hidden;
}

.version-request {
    font-size: 0.9rem;
    color: #1f2937;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.version-tech-meta {
    font-size: 0.72rem;
    color: #9ca3af;
    margin-top: 0.2rem;
}

.score-display {
    text-align: center;
    padding: 0 0.5rem;
}

.score-value-medium {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
}

.score-value-medium.score-good { color: #16a34a; }
.score-value-medium.score-medium { color: #ea580c; }
.score-value-medium.score-bad { color: #dc2626; }
.score-value-medium.score-critical { color: #991b1b; }

.score-label-medium {
    font-size: 0.78rem;
    color: #374151;
    margin-top: 0.2rem;
}

.score-delta {
    font-size: 0.78rem;
    margin-top: 0.3rem;
    color: #6b7280;
}

.score-delta.delta-up { color: #16a34a; font-weight: 700; }
.score-delta.delta-down { color: #dc2626; font-weight: 700; }
.score-delta.delta-flat { color: #6b7280; }

.version-actions {
    display: flex;
    gap: 0.5rem;
}

/* Encart "Changements" */
.changes-block {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 4px 16px rgba(252, 211, 77, 0.15);
}

.changes-block h4 {
    color: #92400e;
    margin-bottom: 0.5rem;
}

.changes-text {
    color: #1f2937;
    font-size: 0.92rem;
    line-height: 1.6;
}

.changes-text ul, .changes-text ol {
    margin-left: 1.25rem;
    margin-top: 0.5rem;
}

.changes-text li {
    margin: 0.3rem 0;
}

/* ---------- Dashboard analyse contrat ---------- */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dashboard-header {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.5rem;
}

.score-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.5rem;
    text-align: center;
}

.score-value {
    font-size: 4rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.score-value.score-good { color: #16a34a; }
.score-value.score-medium { color: #ea580c; }
.score-value.score-bad { color: #dc2626; }
.score-value.score-critical { color: #991b1b; }

.score-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.75rem;
}

.score-meta {
    font-size: 0.72rem;
    color: #6b7280;
    line-height: 1.4;
}

.summary-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.5rem;
}

.summary-card h3 {
    color: #1e3a8a;
    margin-bottom: 0.75rem;
}

.summary-card p {
    color: #1f2937;
    font-size: 0.95rem;
    line-height: 1.6;
}

.dashboard-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    padding: 1.5rem;
}

.dashboard-section h3 {
    color: #1e3a8a;
    margin-bottom: 1rem;
}

.count-badge {
    color: #6b7280;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Filtres */
.clauses-filter {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.4rem 0.85rem;
    background: #f3f4f6;
    color: #1f2937;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.filter-btn:hover {
    background: #e5e7eb;
}

.filter-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

/* Liste de clauses */
.clauses-list,
.missing-list,
.cross-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.clause-card,
.missing-card,
.cross-card {
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: stretch;
}

.clause-bar,
.missing-bar {
    flex: 0 0 6px;
    background: #d1d5db;
    align-self: stretch;
}

.clause-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.clause-card.risk-critical .clause-bar,
.missing-card.risk-critical .missing-bar,
.cross-card.risk-critical .missing-bar { background: #dc2626; }
.clause-card.risk-medium .clause-bar,
.missing-card.risk-medium .missing-bar,
.cross-card.risk-medium .missing-bar { background: #ea580c; }
.clause-card.risk-low .clause-bar,
.missing-card.risk-low .missing-bar,
.cross-card.risk-low .missing-bar { background: #ca8a04; }
.clause-card.risk-ok .clause-bar { background: #16a34a; }

.clause-summary {
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.clause-summary:hover {
    background: #f3f4f6;
}

.clause-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.clause-title {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.95rem;
}

.clause-badge {
    font-size: 0.78rem;
    background: #fff;
    border: 1px solid #d1d5db;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    color: #374151;
    white-space: nowrap;
}

.clause-excerpt {
    color: #4b5563;
    font-size: 0.85rem;
    font-style: italic;
    line-height: 1.4;
}

.clause-details {
    display: none;
    padding: 0 1rem 1rem;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.clause-card.expanded .clause-details {
    display: block;
}

.clause-section {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: #1f2937;
}

.clause-section strong {
    color: #1e3a8a;
}

.clause-section p {
    margin-top: 0.25rem;
    line-height: 1.55;
}

/* Missing / cross-cutting cards */
.missing-content {
    padding: 0.85rem 1rem;
}

.missing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    color: #1f2937;
}

.missing-content p {
    color: #4b5563;
    font-size: 0.88rem;
    line-height: 1.5;
}

.empty-state {
    color: #6b7280;
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

/* ---------- Chat ---------- */
.chat-container {
    width: 100%;
    max-width: 880px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 140px);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.message.user .bubble {
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: #eef1f6;
    color: #1d2330;
    border-bottom-left-radius: 4px;
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background: #fafbfc;
}

.chat-form textarea {
    flex: 1;
    padding: 0.7rem 0.9rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
}

.chat-form textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-form button {
    padding: 0 1.5rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-form button:hover:not(:disabled) {
    background: #1d4ed8;
}

.chat-form button:disabled {
    background: #93b1e0;
    cursor: not-allowed;
}

.status {
    padding: 0.5rem 1rem;
    font-size: 0.78rem;
    color: #6b7280;
    border-top: 1px solid #f1f3f5;
    background: #fafbfc;
    min-height: 24px;
}
