/* Palette anthracite et moutarde. Thème clair par défaut, sombre selon
   l'appareil (auto) ou forcé via data-theme sur <html>. */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ebe9e3;
  --text: #2b2f33;
  --muted: #6b6f73;
  --border: #dcd9d1;
  --accent: #d9a404;
  --accent-strong: #b58700;
  --accent-text: #2b2f33;
  --header: #2b2f33;
  --header-text: #f4f3ef;
  --danger: #c0392b;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f2225;
    --surface: #2b2f33;
    --surface-2: #363b40;
    --text: #ecebe6;
    --muted: #a3a6a9;
    --border: #41464b;
    --accent: #e6b422;
    --accent-strong: #f0c445;
    --header: #17191b;
    --danger: #e57366;
  }
}
:root[data-theme="dark"] {
  --bg: #1f2225;
  --surface: #2b2f33;
  --surface-2: #363b40;
  --text: #ecebe6;
  --muted: #a3a6a9;
  --border: #41464b;
  --accent: #e6b422;
  --accent-strong: #f0c445;
  --header: #17191b;
  --danger: #e57366;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--header);
  color: var(--header-text);
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar h1 span { color: var(--accent); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  border: none;
  background: none;
  color: var(--header-text);
  opacity: .7;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}
.tab:hover { opacity: 1; }
.tab.active { opacity: 1; box-shadow: inset 0 -3px 0 var(--accent); border-radius: 0; font-weight: 600; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn.danger { color: var(--danger); }

.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 100px;
  cursor: pointer;
}
.stat.info { cursor: default; background: var(--surface-2); }
.stat.selected { outline: 2px solid var(--accent); }
.stat .n { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.toolbar .btn.primary { margin-left: auto; }
.hint { color: var(--muted); margin: 0; flex: 1; min-width: 240px; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input:not([type=date]) { flex: 1; min-width: 160px; }
.row input[type=date] { width: auto; }

.alert {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 0 0 16px;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toolbar input, .toolbar select { width: auto; }

.table-wrap, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.card { padding: 20px 24px; max-width: 560px; }
.card h2 { font-size: 17px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }

table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.list th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.list tr:last-child td { border-bottom: none; }
.list tbody tr:hover { background: var(--surface-2); }
.list .sub { color: var(--muted); font-size: 13px; }
.list .actions { white-space: nowrap; text-align: right; }
.list .clickable { cursor: pointer; }
.overdue { color: var(--danger); font-weight: 600; }

.empty { color: var(--muted); text-align: center; padding: 32px; margin: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag { display: inline-block; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 6px; }
.s-a_postuler { background: #e4e3df; color: #3d4144; }
.s-postule    { background: #d9e3ec; color: #24435e; }
.s-relance    { background: #f6e3a6; color: #6b4e00; }
.s-entretien  { background: #e5dcef; color: #4b2d6e; }
.s-offre      { background: #d3ead9; color: #1f5a31; }
.s-refus      { background: #f2d6d2; color: #85281d; }
.s-abandon    { background: #e9e9e9; color: #6b6f73; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 20px 24px;
}
dialog::backdrop { background: rgba(20, 22, 24, .55); }
dialog h2 { margin-top: 0; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; position: sticky; bottom: -20px; background: var(--surface); padding: 8px 0; }

.segmented { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.segmented label {
  flex-direction: row; align-items: center; gap: 6px; margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px;
  color: var(--text); cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }
.segmented input { width: auto; margin: 0; }

form[data-type="spontanee"] .only-offre { display: none; }
form[data-doctype="modele"] .not-modele, form:not([data-doctype="modele"]) .only-modele { display: none; }

details { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

#analyse:not(:empty) { margin-top: 12px; }
.kw-group { margin-bottom: 10px; }
.kw-group h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.chip {
  display: inline-block;
  padding: 3px 9px;
  margin: 0 4px 4px 0;
  border-radius: 999px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.chip.tech { background: color-mix(in srgb, var(--accent) 25%, var(--surface)); border-color: var(--accent); }
.chip small { color: var(--muted); }

#analyse-ia:not(:empty) { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
#analyse-ia h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
#analyse-ia ul { margin: 0; padding-left: 20px; }
#analyse-ia p { margin: 0 0 6px; }
.note-ia { font-weight: 600; }
button.chip { font: inherit; font-size: 13px; color: inherit; cursor: pointer; }
.chip.ajout::before { content: "+ "; font-weight: 700; }
.chip.ajout:hover { border-color: var(--accent); }

.historique { list-style: none; padding: 0; margin: 0 0 10px; }
.historique li { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.historique li time { color: var(--muted); font-size: 13px; min-width: 80px; }
.historique li span { flex: 1; }
.historique li button { border: none; background: none; color: var(--muted); cursor: pointer; }
.historique:empty::before { content: "Aucun échange enregistré."; color: var(--muted); font-size: 13px; }

#lettre-texte { font-family: Georgia, serif; line-height: 1.5; }

@media (max-width: 700px) {
  main, .topbar { padding: 12px 16px; }
  .topbar { gap: 8px; }
  .grid { grid-template-columns: 1fr; }
  .stats { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .stat { flex: 0 0 auto; }
  .toolbar .btn.primary { margin-left: 0; width: 100%; }
  .toolbar select { flex: 1; }
  dialog { padding: 16px; }

  /* Sur téléphone, le tableau devient une liste de cartes. */
  .list thead { display: none; }
  .list, .list tbody, .list tr, .list td { display: block; width: 100%; }
  .list tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .list td { border: none; padding: 2px 0; }
  .list td[data-label]:not(:empty)::before { content: attr(data-label) " : "; color: var(--muted); font-size: 13px; }
  .list .actions { text-align: left; padding-top: 6px; }
}

/* Connexion */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { margin-top: 0; text-align: center; }
.login-card h1 span, .topbar h1 span { color: var(--accent); }
.login-card .btn { width: 100%; }
.erreur { color: var(--danger); margin: 0 0 12px; }

/* Paramètres */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.settings .card { max-width: none; }
.settings h2 { margin-top: 0; }
.ok { color: #2e7d32; }
.users { list-style: none; padding: 0; margin: 0 0 12px; }
.users li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.topbar .btn { margin-left: auto; background: transparent; color: var(--header-text); border-color: rgba(255, 255, 255, .25); }
a.btn { text-decoration: none; display: inline-block; }
.card label.btn { display: inline-block; margin: 0; color: var(--text); font-size: 15px; }
.topbar .user { opacity: .7; font-size: 13px; }

/* Analyse : comparaison au profil */
.chip.have::before { content: "✓ "; color: #2e7d32; font-weight: 700; }
.match { font-size: 14px; margin: 0 0 10px; }
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--header); color: var(--header-text); padding: 10px 16px;
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 10; max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }
.fichier-actuel { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }

.lien-annonce { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 0; margin-bottom: 14px; }
.lien-annonce .row { flex-wrap: nowrap; }
@media (max-width: 700px) { .lien-annonce .row { flex-wrap: wrap; } .lien-annonce .btn { width: 100%; } }

/* Réponses reçues */
.reponses { list-style: none; padding: 0; margin: 0 0 12px; }
.reponses:empty::before { content: "Aucune réponse pour le moment."; color: var(--muted); font-size: 13px; }
.reponses li { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; }
.reponses .entete { display: flex; gap: 8px; align-items: center; }
.reponses .entete time { color: var(--muted); font-size: 13px; }
.reponses .entete button { margin-left: auto; border: none; background: none; color: var(--muted); cursor: pointer; }
.reponses .message { white-space: pre-wrap; font-size: 14px; margin: 6px 0 0; max-height: 220px; overflow: auto; }
.r-entretien { background: #e5dcef; color: #4b2d6e; }
.r-refus { background: #f2d6d2; color: #85281d; }
.r-offre { background: #d3ead9; color: #1f5a31; }
.r-autre { background: #e4e3df; color: #3d4144; }

/* Entretiens */
.sous-form { border: 1px dashed var(--border); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 8px; }
.sous-form legend { font-weight: 600; font-size: 14px; padding: 0 4px; }
.entretiens .details { font-size: 13px; color: var(--muted); margin-top: 4px; }
.entretiens .actions-ent { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.r-avenir { background: #f6e3a6; color: #6b4e00; }
.r-passe { background: #e4e3df; color: #3d4144; }
