:root {
    --bg: #f5f6f8;
    --card-bg: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e5ea;
    --primary: #003366;
    --primary-dark: #00203f;
    --accent: #cc3366;
    --accent-dark: #a3284f;
    --danger: #b3413a;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    padding: 0.9rem 1.5rem;
}

.topbar-actions { display: flex; align-items: center; gap: 1rem; }

.brand {
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    font-size: 1.05rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { margin-top: 0; }

.flash-stack { margin-bottom: 1rem; }
.flash { padding: 0.6rem 1rem; border-radius: var(--radius); margin-bottom: 0.5rem; }
.flash-success { background: #e3f3ec; color: #1f4238; }
.flash-error { background: #fbe9e7; color: var(--danger); }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    background: var(--card-bg);
    color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef1ef; color: var(--primary-dark); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0; text-decoration: underline; cursor: pointer; }
.btn-danger-link { color: var(--danger); }

.inline-form { display: inline; }

.mission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.mission-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-decoration: none;
    color: var(--text);
    display: block;
}
.mission-card:hover { border-color: var(--accent); }
.mission-card-header { display: flex; gap: 0.4rem; margin-bottom: 0.5rem; }
.mission-card h2 { margin: 0.2rem 0; font-size: 1.1rem; }
.mission-entites { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0.8rem; }
.mission-periode { color: var(--muted); font-size: 0.85rem; }

.badge {
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #eef1ef;
    color: var(--primary-dark);
}
.badge-groupe { background: #fbe8ee; color: var(--accent-dark); }
.badge-statut-termine { background: #e3f3ec; color: #1f4238; }
.badge-statut-en_cours { background: #eaf1fb; color: #244a7a; }

.mission-stats { display: flex; gap: 1.2rem; margin-top: 0.5rem; }
.mission-stats-large { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); }
.stat-label { font-size: 0.72rem; color: var(--muted); }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
    margin-bottom: 1.2rem;
}

.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
    margin-bottom: 1rem;
}
.hidden { display: none; }

.form-row { margin-bottom: 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.form-row label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.form-row input, .form-row select, .form-row textarea {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(204, 51, 102, 0.15);
}
.form-row-split { flex-direction: row; gap: 1rem; }
.form-row-split > div { flex: 1; display: flex; flex-direction: column; gap: 0.3rem; }
.form-row-split-3 { flex-direction: row; gap: 1rem; }
.form-row-split-3 > div { flex: 1; display: flex; flex-direction: column; gap: 0.3rem; }

.radio-group { display: flex; gap: 1.5rem; }
.radio-group label { font-weight: 400; color: var(--text); display: flex; align-items: center; gap: 0.3rem; }

.entite-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.8rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}
.entite-row-line { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.entite-row-line-secondary { font-size: 0.85rem; }
.entite-row input, .entite-row select { padding: 0.45rem; border: 1px solid var(--border); border-radius: 6px; flex: 1; min-width: 140px; }
.entite-row-line-secondary input { min-width: 180px; }
.btn-remove-row { background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; color: var(--danger); flex: 0 0 auto; padding: 0.4rem 0.6rem; }

.btn-siren-lookup {
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid var(--accent);
    color: var(--accent-dark);
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
}
.btn-siren-lookup:hover { background: var(--accent); color: #fff; }
.btn-siren-lookup:disabled { opacity: 0.6; cursor: wait; }

.siren-lookup-status { font-size: 0.78rem; flex: 1 1 100%; }
.siren-lookup-status.status-success { color: #1f4238; }
.siren-lookup-status.status-error { color: var(--danger); }

.form-actions { display: flex; gap: 0.8rem; align-items: center; margin-top: 1rem; }
.hint { color: var(--muted); font-size: 0.82rem; }
.muted { color: var(--muted); }
.empty-state { color: var(--muted); font-style: italic; }

.mission-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.mission-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.mission-actions select { padding: 0.45rem; border-radius: 6px; border: 1px solid var(--border); }

.entite-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; padding-bottom: 0.6rem; }
.entite-tab {
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    background: #eef1ef;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
}
.entite-tab.active { background: var(--primary); color: #fff; }
.entite-tab-add { background: #fff; border: 1px dashed var(--border); }

.entite-info { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.entite-toolbar { display: flex; gap: 0.6rem; margin-bottom: 1rem; }

.data-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.data-table th, .data-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.row-actions { display: flex; gap: 0.6rem; }

.chip { font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 999px; }
.chip-etat-audite { background: #e3f3ec; color: #1f4238; }
.chip-etat-non-audite { background: #f1f1f3; color: var(--muted); }
.chip-risque-forte { background: #fbe9e7; color: var(--danger); }
.chip-risque-modérée { background: #fdf1dc; color: #8a5a00; }
.chip-risque-faible { background: #eaf1fb; color: #244a7a; }
.chip-conformite-conforme { background: #e3f3ec; color: #1f4238; }
.chip-conformite-partiellement-conforme { background: #fdf1dc; color: #8a5a00; }
.chip-conformite-non-conforme { background: #fbe9e7; color: var(--danger); }
.chip-source-ia { background: #fbe8ee; color: var(--accent-dark); font-weight: 600; }
.chip-source-chatgpt { background: #eef1ef; color: var(--muted); }
.chip-source-regle { background: #eaf1fb; color: #244a7a; font-weight: 600; }

.btn-ia {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
}
.btn-ia:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ia:disabled { opacity: 0.6; cursor: wait; }

.btn-regle {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
}
.btn-regle:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-regle:disabled { opacity: 0.6; cursor: wait; }

.ai-progress { margin: 1rem 0; padding: 0.9rem; background: #faf5f7; border: 1px solid var(--border); border-radius: var(--radius); }
.ai-progress-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; margin-bottom: 0.4rem; }
.ai-progress-label { color: var(--muted); }
.ai-progress-pct { font-weight: 600; color: var(--accent-dark); }

.progress-bar { width: 100%; height: 8px; border-radius: 999px; background: #e9dde3; overflow: hidden; }
.progress-bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.2s ease; }

.btn-stop {
    margin-top: 0.8rem;
    background: #fff;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
}
.btn-stop:hover { background: var(--danger); color: #fff; }
.btn-stop:disabled { opacity: 0.6; cursor: wait; }
.ai-stop-hint { margin-top: 0.4rem; margin-bottom: 0; font-size: 0.76rem; }

.ai-progress-row-analyse { margin-top: 0.8rem; margin-bottom: 0; gap: 0.6rem; justify-content: flex-start; }
.ai-progress-status { color: var(--text); }

.ai-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e9dde3;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
    flex: 0 0 auto;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.print-point { border-top: 1px solid var(--border); padding-top: 0.6rem; margin-top: 0.6rem; }
