:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f6fed;
  --accent-soft: #eaf1fe;
  --ok: #0f9d58;
  --err: #d93025;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 18px 24px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.container { max-width: 860px; margin: 28px auto; padding: 0 20px; }

.steps {
  display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 24px;
}
.step {
  flex: 1; display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--muted);
  padding: 10px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.step span {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px;
  background: var(--line); color: var(--muted);
}
.step.active { color: var(--ink); border-color: var(--accent); }
.step.active span { background: var(--accent); color: #fff; }
.step.done span { background: var(--ok); color: #fff; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }

.dropzone {
  margin: 16px 0; border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 36px; text-align: center; cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner { display: flex; flex-direction: column; gap: 4px; }
.dz-inner strong { font-size: 15px; }

.preview-block {
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fafbff 0%, #ffffff 60%);
  padding: 16px 18px 18px;
}
.preview-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.preview-head label { font-size: 14px; }
.preview-head label strong { color: var(--ink); }
#charCount {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 4px 11px; border-radius: 999px;
  white-space: nowrap;
}
.source-text {
  width: 100%; min-height: 340px; resize: vertical;
  font-family: "Inter", system-ui, sans-serif; font-size: 15px;
  line-height: 1.75; color: var(--ink);
  padding: 20px 22px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .04);
  transition: border-color .15s, box-shadow .15s;
}
.source-text::placeholder { color: #aab1bd; }
.source-text:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
#extractMsg {
  margin: 12px 2px 0; font-size: 13px;
  display: flex; align-items: center; gap: 7px;
}
#extractMsg::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); flex: 0 0 auto;
}
#extractMsg.loading::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.btn {
  font-family: inherit; font-size: 14px; font-weight: 500;
  padding: 10px 18px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: transparent; }

.working { display: flex; align-items: center; gap: 14px; padding: 16px 0; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sortie-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.tabs { display: flex; gap: 6px; }
.tab {
  font-family: inherit; font-size: 13px; padding: 6px 12px;
  border: 1px solid var(--line); background: var(--card); border-radius: 7px; cursor: pointer;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.meta {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0;
}
.meta .chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}

.view { margin-top: 8px; }
.view.code {
  background: #0f1115; color: #d6dae0; padding: 16px; border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
.view h3 { font-size: 14px; margin: 18px 0 6px; }
.view h4 { font-size: 13px; margin: 14px 0 4px; color: var(--muted); }
.view ul { margin: 6px 0; padding-left: 20px; }
.view li { font-size: 14px; margin: 3px 0; }
.view p { font-size: 14px; }

.actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

.error {
  background: #fce8e6; color: var(--err); border: 1px solid #f5c2bd;
  padding: 12px 16px; border-radius: 10px; font-size: 14px;
}
.hidden { display: none !important; }

/* ---- Comparaison ---- */
/* La vue comparaison déborde du conteneur 860px pour occuper la largeur de l'écran */
#panelSortie:has(#view-comparaison:not(.hidden)) {
  max-width: min(1500px, 96vw);
  margin-left: 50%;
  transform: translateX(-50%);
  width: min(1500px, 96vw);
}

.cmp { margin-top: 14px; }

.score-card {
  display: flex; align-items: center; gap: 22px;
  padding: 20px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
}
.score-card.ok     { --c: var(--ok);  border-color: #b7e1c5; background: #f1faf4; }
.score-card.warn   { --c: #d98e00;    border-color: #f3dca6; background: #fdf8ec; }
.score-card.danger { --c: var(--err); border-color: #f5c2bd; background: #fdf0ef; }

.gauge {
  flex: 0 0 auto; position: relative;
  width: 128px; height: 128px; border-radius: 50%;
  display: grid; place-items: center;
  background:
    conic-gradient(var(--c) calc(var(--p) * 1%), #e8eaee 0);
  transition: background .6s ease;
}
.gauge::before {
  content: ""; position: absolute;
  width: 98px; height: 98px; border-radius: 50%; background: var(--card);
}
.gauge-val {
  position: relative; z-index: 1;
  font-size: 38px; font-weight: 700; color: var(--c); line-height: 1;
}
.gauge-val span { font-size: 16px; font-weight: 600; }

.score-info { flex: 1; min-width: 0; }
.score-verdict { font-size: 18px; font-weight: 700; color: var(--c); }
.score-sub { font-size: 12.5px; color: var(--muted); margin: 2px 0 12px; }

.score-stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 9px;
}
.stat-v { font-size: 15px; font-weight: 700; }
.stat-l { font-size: 11px; color: var(--muted); }

/* Tableau de bord détaillé */
.metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0;
}
.metric-group {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); padding: 14px 16px;
}
.metric-group h4 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--accent); font-weight: 700;
}
.metric {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 5px 0; border-top: 1px solid var(--line);
}
.metric:first-of-type { border-top: 0; }
.metric-l { font-size: 12px; color: var(--muted); }
.metric-v { font-size: 14px; font-weight: 600; white-space: nowrap; }
.metric-v em { color: var(--muted); font-style: normal; font-weight: 400; }

/* Liste des passages copiés */
.passages {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); padding: 4px 16px; margin: 14px 0;
}
.passages summary {
  cursor: pointer; font-size: 13px; font-weight: 600; padding: 10px 0;
}
.passages ul { margin: 4px 0 12px; padding-left: 18px; }
.passages li { font-size: 13px; margin: 6px 0; color: var(--ink); }
.pwords {
  display: inline-block; font-size: 11px; font-weight: 700; color: #6b4e00;
  background: #ffe9a8; border-radius: 5px; padding: 1px 7px; margin-right: 6px;
}
.cmp-none {
  font-size: 13px; color: var(--ok); font-weight: 600;
  background: #f1faf4; border: 1px solid #b7e1c5;
  border-radius: var(--radius); padding: 12px 16px; margin: 14px 0;
}

.cmp-legend { font-size: 12.5px; color: var(--muted); margin: 16px 2px 10px; }
.cmp-legend mark { padding: 0 2px; }

.cmp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cmp-col {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--card); min-width: 0;
}
.cmp-col-head {
  font-size: 13px; font-weight: 600; padding: 13px 18px;
  background: #f4f5f7; border-bottom: 1px solid var(--line); color: var(--muted);
  position: sticky; top: 0; z-index: 1;
}
.cmp-col-head.accent { background: var(--accent-soft); color: var(--accent); }
.cmp-text {
  padding: 22px 24px; font-size: 15px; line-height: 1.75;
  height: calc(100vh - 300px); min-height: 420px;
  overflow-y: auto; white-space: normal; word-break: break-word;
  scroll-behavior: smooth;
}
.cmp-text mark {
  background: #ffe9a8; color: #6b4e00;
  border-radius: 3px; padding: 0 2px;
}

@media (max-width: 720px) {
  #panelSortie:has(#view-comparaison:not(.hidden)) {
    max-width: 100%; width: auto; margin-left: 0; transform: none;
  }
  .cmp-cols { grid-template-columns: 1fr; }
  .cmp-text { height: auto; max-height: 60vh; }
  .score-card { flex-direction: column; text-align: center; }
  .metrics { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .metrics { grid-template-columns: 1fr; }
}
