/* =========================================================
   Audit premium — même palette que le chat, accent Logic'API (#009fe3)
   ========================================================= */

:root {
	/* Charte Intelegis — couleurs du logo */
	--navy: #0B1F3A;
	--gold: #C9A227;
	--gold-soft: rgba(201, 162, 39, .28);
	--teal: #157C8C;
	--slate: #64748B;

	--bg-app: #081426;
	--bg-sidebar: #0B1F3A;
	--bg-card: #0F2742;
	--bg-elev: #14324F;
	--text-primary: #E9EFF6;
	--text-secondary: #A3B4C6;
	--border-color: #1D3A57;
	--accent: #C9A227;
	--accent-hover: #DCBB45;
	--accent-strong: #B8901F;
	--danger: #E05A4E;
	--warning: #C9A227;
}

body {
	background: var(--bg-app);
	color: var(--text-primary);
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	margin: 0;
	min-height: 100vh;
}

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

/* ---------- barre haute ---------- */
.audit-topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px 20px;
	background: var(--bg-sidebar);
	border-bottom: 1px solid var(--border-color);
}

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

.audit-nav {
	display: flex;
	align-items: center;
	gap: 16px;
	font-size: 14px;
}

.audit-nav a {
	color: var(--text-secondary);
	text-decoration: none;
}

.audit-nav a:hover,
.audit-nav a.active { color: var(--text-primary); }

.audit-user { color: var(--text-secondary); font-size: 13px; }

/* ---------- structure ---------- */
.audit-main {
	max-width: 980px;
	margin: 0 auto;
	padding: 28px 20px 60px;
}

.audit-hero h1 {
	font-size: 26px;
	margin: 0 0 6px;
}

.audit-sub {
	color: var(--text-secondary);
	font-size: 14px;
	margin: 0 0 24px;
}

.audit-card {
	background: var(--bg-card);
	border: 1px solid var(--border-color);
	border-radius: 14px;
	padding: 22px;
	margin-bottom: 20px;
}

.audit-step {
	font-size: 15px;
	margin: 0 0 10px;
	color: var(--text-primary);
}

.audit-hint,
.audit-legal {
	color: var(--text-secondary);
	font-size: 13px;
	line-height: 1.55;
	margin: 0 0 14px;
}

.audit-legal { margin-top: 14px; font-size: 12px; }

.audit-muted { color: var(--text-secondary); font-weight: 400; font-size: 13px; }

/* ---------- dépôt ---------- */
.audit-drop {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 26px;
	border: 2px dashed var(--border-color);
	border-radius: 12px;
	cursor: pointer;
	background: var(--bg-elev);
	transition: border-color .2s, background .2s;
	margin-bottom: 16px;
}

.audit-drop:hover { border-color: var(--accent); }

.audit-drop input[type="file"] {
	position: absolute;
	width: 1px; height: 1px;
	opacity: 0;
	pointer-events: none;
}

.audit-drop-icon { font-size: 26px; }
.audit-drop-label { font-size: 14px; font-weight: 600; }
.audit-drop-file { font-size: 12px; color: var(--text-secondary); }

/* ---------- types d'analyse ---------- */
.audit-types {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
	gap: 25px;
	margin-bottom: 35px;
}

.audit-type {
	display: block;
	cursor: pointer;
}

.audit-type input {
	position: absolute;
	opacity: 0;
}

.audit-type-body {
	display: block;
	height: 100%;
	padding: 5px 10px;
	border: 1px solid var(--border-color);
	border-radius: 10px;
	background: var(--bg-elev);
	transition: border-color .2s, background .2s;
}

.audit-type-body strong { display: block; font-size: 14px; margin-bottom: 4px; }
.audit-type-body small { color: var(--text-secondary); font-size: 12px; line-height: 1.45; }

.audit-type input:checked + .audit-type-body {
	border-color: var(--accent);
	background: rgba(0, 159, 227, .12);
}

/* ---------- champs ---------- */
textarea,
input[type="text"] {
	width: 100%;
	background: #262626;
	border: 1px solid var(--border-color);
	border-radius: 10px;
	color: var(--text-primary);
	padding: 12px 14px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.5;
	box-sizing: border-box;
}

textarea:focus { outline: none; border-color: var(--accent); }

.audit-submit {
	width: 100%;
	padding: 14px;
	border: none;
	border-radius: 10px;
	background: var(--accent);
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
	transition: background .2s;
}

.audit-submit:hover:not(:disabled) { background: var(--accent-hover); }
.audit-submit:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- alertes ---------- */
.audit-alert {
	padding: 12px 16px;
	border-radius: 10px;
	font-size: 13px;
	line-height: 1.5;
	margin-bottom: 16px;
}

.audit-alert.danger { background: #451a1a; border: 1px solid #7f1d1d; color: #fca5a5; }
.audit-alert.warning { background: #453a1a; border: 1px solid #7f6b0f; color: #fcd34d; }

/* ---------- métadonnées / tableau ---------- */
.audit-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 18px;
	list-style: none;
	padding: 0;
	margin: 0 0 16px;
}

.audit-meta li {
	display: flex;
	flex-direction: column;
	gap: 2px;
	font-size: 12px;
	color: var(--text-secondary);
}

.audit-meta strong { color: var(--text-primary); font-size: 14px; }

.audit-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.audit-table th,
.audit-table td {
	text-align: left;
	padding: 9px 10px;
	border-bottom: 1px solid var(--border-color);
}

.audit-table th { color: var(--text-secondary); font-weight: 500; font-size: 12px; }

.audit-link { color: var(--accent); text-decoration: none; }

/* ---------- badges ---------- */
.audit-badge {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
	background: #333;
	color: var(--text-secondary);
}

.audit-badge.extracted,
.audit-badge.done,
.audit-badge.native { background: rgba(16, 163, 127, .18); color: #5ee0b5; }
.audit-badge.ocr { background: rgba(240, 180, 41, .18); color: #f0b429; }
.audit-badge.vision { background: rgba(21, 124, 140, .22); color: #5fd0e0; }
.audit-badge.error { background: rgba(231, 76, 60, .18); color: #ff8f8f; }
.audit-badge.extracting,
.audit-badge.queued,
.audit-badge.analyzing { background: rgba(21, 124, 140, .22); color: #5fd0e0; }
/* En attente : neutre, pour ne pas le confondre avec « en cours » */
.audit-badge.pending { background: rgba(148, 163, 184, .20); color: #94A3B8; }
.audit-badge.uploaded { background: rgba(100, 116, 139, .22); color: #a3b4c6; }

.audit-flag {
	font-size: 11px;
	color: var(--warning);
	background: rgba(240, 180, 41, .12);
	padding: 1px 7px;
	border-radius: 999px;
}

/* ---------- pages ---------- */
.audit-pages { display: flex; flex-direction: column; gap: 6px; }

.audit-page {
	border: 1px solid var(--border-color);
	border-radius: 10px;
	background: var(--bg-elev);
	overflow: hidden;
}

.audit-page summary {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 14px;
	cursor: pointer;
	font-size: 13px;
	list-style: none;
}

.audit-page summary::-webkit-details-marker { display: none; }
.audit-pnum { font-weight: 600; }

.audit-page-body { padding: 0 14px 14px; }

.audit-risky {
	list-style: none;
	padding: 0;
	margin: 0 0 10px;
	font-size: 12px;
	color: var(--warning);
	line-height: 1.6;
}

.audit-text {
	white-space: pre-wrap;
	word-wrap: break-word;
	background: #1a1a1a;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 12px;
	font-size: 12px;
	line-height: 1.55;
	color: #d6d6d6;
	max-height: 320px;
	overflow: auto;
	margin: 0;
}

.hidden { display: none; }

@media (max-width: 640px) {
	.audit-main { padding: 18px 12px 40px; }
	.audit-card { padding: 16px; }
	.audit-meta { gap: 12px; }
}

/* ---------- rapport ---------- */
.audit-list { margin: 0 0 14px; padding-left: 20px; font-size: 13px; line-height: 1.6; color: #d6d6d6; }

.audit-anomaly {
	border: 1px solid var(--border-color);
	border-radius: 10px;
	padding: 14px;
	margin-bottom: 10px;
	background: var(--bg-elev);
	font-size: 13px;
	line-height: 1.6;
}

.audit-anomaly header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.audit-anomaly p { margin: 6px 0; color: #d6d6d6; }

.audit-quote {
	margin: 8px 0;
	padding: 8px 12px;
	border-left: 3px solid var(--text-secondary);
	background: #191919;
	color: #cfcfcf;
	font-style: italic;
	font-size: 12.5px;
}

.audit-quote.ok { border-left-color: var(--accent); }

.audit-refs { list-style: none; padding: 0; margin: 0; }
.audit-refs li { padding: 10px 0; border-bottom: 1px solid var(--border-color); font-size: 13px; }
.audit-refs li:last-child { border-bottom: none; }

/* badges de certitude / gravité / référence */
.audit-badge.averee { background: rgba(231, 76, 60, .18); color: #ff8f8f; }
.audit-badge.potentielle { background: rgba(240, 180, 41, .18); color: #f0b429; }
.audit-badge.indeterminee { background: #333; color: #bbb; }

.audit-badge.gravite-critique { background: rgba(231, 76, 60, .28); color: #ff6b6b; }
.audit-badge.gravite-elevee { background: rgba(231, 76, 60, .18); color: #ff9f9f; }
.audit-badge.gravite-moyenne { background: rgba(240, 180, 41, .18); color: #f0b429; }
.audit-badge.gravite-faible { background: #333; color: #bbb; }

.audit-badge.ref-verifiee { background: rgba(16, 163, 127, .2); color: #5ee0b5; }
.audit-badge.ref-sourcee { background: rgba(16, 163, 127, .12); color: #7fd8bd; }
.audit-badge.ref-non_reverifiee { background: rgba(240, 180, 41, .15); color: #f0b429; }
.audit-badge.ref-a_verifier { background: rgba(240, 180, 41, .2); color: #f0b429; }
.audit-badge.ref-introuvable { background: rgba(231, 76, 60, .2); color: #ff8f8f; }

.audit-flag.ok { background: rgba(16, 163, 127, .16); color: #5ee0b5; }
.audit-flag.ko { background: rgba(231, 76, 60, .16); color: #ff8f8f; }

.audit-meta-wide li { min-width: 130px; }

/* Liens Légifrance dans les fondements */
.audit-ref-link {
	color: var(--accent);
	text-decoration: none;
	font-weight: 600;
	border-bottom: 1px dotted rgba(0, 159, 227, .55);
}

.audit-ref-link:hover { border-bottom-style: solid; }
.audit-ext { font-size: 11px; opacity: .7; }

/* Bandeau d'export PDF */
.audit-export {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	flex-wrap: wrap;
}

.audit-export .audit-hint { margin: 0; }

.audit-submit-inline {
	width: auto;
	padding: 12px 18px;
	text-decoration: none;
	display: inline-block;
}

/* Barre de progression indéterminée (analyse en file) */
.audit-progress {
	height: 4px;
	background: #2a2a2a;
	border-radius: 999px;
	overflow: hidden;
	margin-top: 6px;
}

.audit-progress span {
	display: block;
	width: 35%;
	height: 100%;
	background: var(--accent);
	border-radius: 999px;
	animation: audit-slide 1.4s infinite ease-in-out;
}

.audit-progress.determinee span {
	animation: none;
	transition: width .4s ease;
}

@keyframes audit-slide {
	0%   { transform: translateX(-100%); }
	100% { transform: translateX(320%); }
}

.audit-badge.queued { background: rgba(240, 180, 41, .16); color: #f0b429; }
.audit-badge.analyzing { background: rgba(0, 159, 227, .18); color: #66b4ea; }

/* Actions sur le document + zone de suppression */
.audit-doc-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: 0 0 16px;
}

.audit-btn {
	display: inline-block;
	padding: 9px 14px;
	border-radius: 9px;
	border: 1px solid var(--border-color);
	background: var(--bg-elev);
	color: var(--text-primary);
	font-size: 13px;
	font-family: inherit;
	text-decoration: none;
	cursor: pointer;
	transition: background .2s, border-color .2s;
}

.audit-btn:hover { border-color: var(--accent); }

.audit-btn-danger { color: #ff8f8f; border-color: rgba(231, 76, 60, .45); }
.audit-btn-danger:hover { background: rgba(231, 76, 60, .12); border-color: var(--danger); }

.audit-danger-zone {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	flex-wrap: wrap;
	border-color: rgba(231, 76, 60, .3);
}

.audit-danger-zone .audit-hint { margin: 0; }

.audit-badge.vigilance { background: rgba(240, 180, 41, .18); color: #f0b429; }

.audit-alert.success { background: #17321f; border: 1px solid #1f5c34; color: #86efac; }

/* Niveaux de lecture + badges des nouvelles catégories */
.audit-levels {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
	gap: 10px;
	margin-bottom: 18px;
}

.audit-level-icon {
	display: inline-block;
	font-size: 16px;
	line-height: 1;
	cursor: help;
	opacity: .9;
}

/* ---------- Traceur ---------- */
.trace-filters {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 10px;
	margin-bottom: 14px;
}

.trace-filters label {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 12px;
	color: var(--text-secondary);
}

.trace-filters input,
.trace-filters select {
	background: #262626;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	color: var(--text-primary);
	padding: 8px 10px;
	font-size: 13px;
	font-family: inherit;
}

.trace-actions { display: flex; gap: 10px; align-items: center; }

.trace-table td { font-size: 12px; vertical-align: top; }
.trace-date { white-space: nowrap; color: var(--text-secondary); }
.trace-event { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
.trace-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.trace-meta { color: var(--text-secondary); font-size: 11px; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.trace-cat {
	display: inline-block;
	padding: 1px 8px;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
}
.trace-cat.security { background: rgba(231, 76, 60, .18); color: #ff8f8f; }
.trace-cat.business { background: rgba(16, 163, 127, .18); color: #5ee0b5; }
.trace-cat.support  { background: #333; color: #bbb; }

.trace-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trace-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px;
	border-radius: 999px;
	background: var(--bg-elev);
	border: 1px solid var(--border-color);
	color: var(--text-primary);
	font-size: 12px;
	text-decoration: none;
}
.trace-chip span { color: var(--accent); font-weight: 700; }
.trace-chip:hover { border-color: var(--accent); }

.trace-pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

/* Historique des crédits (panneau utilisateur) */
.credits-panel {
	position: fixed;
	top: 56px;
	right: 16px;
	width: 340px;
	max-height: 60vh;
	overflow: auto;
	background: var(--bg-card);
	border: 1px solid var(--border-color);
	border-radius: 12px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
	z-index: 3000;
	font-size: 13px;
}

.credits-panel-head {
	padding: 10px 14px;
	border-bottom: 1px solid var(--border-color);
	font-weight: 600;
}

.credits-panel-body { padding: 8px 14px 12px; }

.credits-list { list-style: none; margin: 0; padding: 0; }
.credits-list li {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 0;
	border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.credits-list li:last-child { border-bottom: none; }
.credits-date { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }
.credits-op { font-weight: 600; }
.credits-list li.plus .credits-op { color: #5ee0b5; }
.credits-list li.minus .credits-op { color: #ff8f8f; }
.credits-bal { color: var(--text-secondary); font-size: 11px; }

.credit-plus { color: #5ee0b5; font-weight: 600; }
.credit-minus { color: #ff8f8f; font-weight: 600; }

/* Identifiant utilisateur, toujours visible à côté du nom */
.trace-uid { color: var(--text-secondary); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

/* Attente de dépôt */
.upload-wait[hidden] {
	display: none !important;
}

.upload-wait {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 14px;
	color: var(--muted);
	font-size: 14px;
}

.upload-spinner {
	width: 16px;
	height: 16px;
	border: 2px solid var(--border-color);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: upload-spin .8s linear infinite;
}

@keyframes upload-spin { to { transform: rotate(360deg); } }

.upload-ko { color: #ff8f8f; font-size: 13px; }

/* =========================================================
   Responsive — dossiers et audit sur mobile
   ========================================================= */
@media (max-width: 768px) {
	/* Barre haute : on empile au lieu d'écraser */
	.audit-topbar {
		flex-direction: column;
		align-items: stretch;
		gap: 10px;
		padding: 10px 12px;
	}

	.audit-topbar .wrap,
	.audit-topbar > nav { width: 100%; }

	.audit-nav {
		flex-wrap: wrap;
		gap: 8px 14px;
		font-size: 13px;
	}

	.audit-user { width: 100%; order: 10; }

	/* Contenu */
	.audit-main { padding: 16px 10px 48px; }
	.audit-hero h1 { font-size: 22px; }
	.audit-sub { font-size: 13.5px; }

	.audit-card {
		padding: 14px;
		border-radius: 12px;
		/* Les tableaux larges défilent DANS la carte, la page ne déborde plus */
		overflow-x: auto;
	}

	/* Tableaux : largeur minimale lisible + défilement horizontal */
	.audit-table { min-width: 540px; font-size: 12.5px; }
	.trace-table { min-width: 620px; }

	/* Actions d'une pièce : empilées */
	.dossier-actions {
		display: flex;
		flex-direction: column;
		gap: 6px;
		align-items: stretch;
	}

	.dossier-actions form,
	.dossier-actions .audit-btn { width: 100%; }

	.dossier-actions .audit-btn { text-align: center; }

	/* Filtres : une colonne */
	.trace-filters { grid-template-columns: 1fr; }

	/* Métadonnées : deux par ligne */
	.audit-meta { gap: 10px 18px; }
	.audit-meta li { min-width: 120px; }

	/* Textes longs (noms de fichiers, meta JSON) */
	.trace-meta,
	.audit-muted,
	.trace-event {
		word-break: break-word;
		max-width: 220px;
	}

	/* Formulaires : champs pleine largeur */
	.trace-filters input,
	.trace-filters select,
	textarea { font-size: 16px; } /* évite le zoom iOS */

	.audit-submit-inline { width: 100%; }
}


/* Badge d'indexation + pourcentage : toujours sur une seule ligne */
.doc-index-inline {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	white-space: nowrap;
}

/* Indexation en cours : teal + pulsation, pour ne pas la confondre avec l'attente */
.audit-badge.analyzing {
	animation: audit-pulse 1.6s ease-in-out infinite;
}

@keyframes audit-pulse {
	0%, 100% { opacity: 1; }
	50%      { opacity: .55; }
}

/* ---------- nom des analyses (29/10) ---------- */
.audit-name-field { margin: 4px 0 22px; }
.audit-name-field label {
	display: block;
	margin-bottom: 8px;
	font-size: 14px;
	font-weight: 600;
	color: var(--text-primary);
}
.audit-name-field .audit-hint { margin: 8px 0 0; }
.audit-optional { font-weight: 400; opacity: .65; }

.audit-id {
	margin-left: 6px;
	font-size: 12px;
	font-weight: 400;
	opacity: .55;
}

.audit-name-cell a { color: var(--text-primary); text-decoration: none; font-weight: 600; }
.audit-name-cell a:hover { color: var(--accent); }

.audit-rename {
	display: flex;
	gap: 8px;
	margin: 6px 0 14px;
	max-width: 560px;
}
.audit-rename input[type="text"] { flex: 1; padding: 8px 12px; font-size: 13px; }
.audit-rename .audit-btn { white-space: nowrap; }
