/* ============================================================
   Charte BH Environnement — application Fiches de Migration
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@200..800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --paper: #1A2A2E;
  --paper-soft: #233438;
  --paper-warm: #2B3D42;
  --ink: #D5DDDA;
  --ink-soft: #AEBBB7;
  --muted: #7A8A86;
  --line: #344549;
  --accent: #7DC59C;
  --accent-soft: #2F4F45;
  --highlight: #3FA77A;
  --logo-chevron: #5bcd90;

  --danger: #D97766;
  --danger-soft: #4A2A26;
  --warn: #E0B66B;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);

  --font-sans: 'Manrope', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--ink); }

h1, h2, h3, h4 { font-family: var(--font-sans); font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin: 0 0 .6em 0; }
h1 { font-size: 1.85rem; font-weight: 700; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }

.accent { color: var(--accent); }
.muted  { color: var(--muted); }
.soft   { color: var(--ink-soft); }
.mono   { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: 0.02em; }
.eyebrow { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted); }

/* ----- Layout ----- */

.page { min-height: 100vh; display: flex; flex-direction: column; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; width: 100%; }
.container-narrow { max-width: 720px; margin: 0 auto; padding: 0 24px; width: 100%; }

header.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  padding: 14px 0;
  position: sticky; top: 0; z-index: 10;
}
.topbar .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.topbar nav a { color: var(--ink-soft); font-weight: 500; }
.topbar nav a:hover { color: var(--accent); }
.topbar nav form { display: inline-flex; margin: 0; }

.logo {
  display: inline-flex; align-items: center; gap: 12px; color: var(--ink); font-weight: 700; letter-spacing: 0.04em;
}
.logo .chev { color: var(--logo-chevron); font-family: var(--font-mono); font-weight: 600; font-size: 1.1rem; }
.logo .name { font-family: var(--font-sans); font-size: 0.95rem; }

main { flex: 1; padding: 32px 0 64px; }

footer.footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 18px 0;
}
footer .footer-row { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; }

.inline-add { margin-top: 18px; }

.section-title {
  margin: 32px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}

/* ----- Cards ----- */

.card {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.card.warm { background: var(--paper-warm); }
.card.callout { background: var(--accent-soft); border-color: var(--accent); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }

.kv-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 0.95rem; }
.kv-grid dt { color: var(--muted); font-family: var(--font-mono); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.1em; padding-top: 3px; }
.kv-grid dd { margin: 0; color: var(--ink); }

/* ----- Forms ----- */

label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

/* Tous les inputs textuels (couvre type=text, email, password, number, tel,
   search, url, date, time, datetime-local, ainsi que les <input> sans attribut
   type qui retombent sur 'text') */
input:not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]),
select,
textarea {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 0 12px;
  height: 42px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
textarea {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  min-height: 140px;
  height: auto;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(125, 197, 156, 0.18);
}
input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--paper-soft);
  color: var(--muted);
  cursor: not-allowed;
}

/* Custom chevron pour <select> (SVG inline, teinté --muted) */
select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.5 L6 6.5 L11 1.5' fill='none' stroke='%237A8A86' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}
select:focus { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.5 L6 6.5 L11 1.5' fill='none' stroke='%237DC59C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>"); }
select option { background: var(--paper-soft); color: var(--ink); }

/* Hide number spinners — la charte est sobre */
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Style spécifique du PIN (police mono, espacement large) */
input.pin-input {
  height: 56px;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 0;
}

.field { margin-bottom: 14px; }
.field-error { color: var(--danger); font-size: 0.85rem; margin-top: 4px; font-family: var(--font-mono); }
.row-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-fields-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.row-fields-4 { display: grid; grid-template-columns: 1.2fr 1.2fr 2fr 1fr; gap: 12px; align-items: start; }
.row-fields .field, .row-fields-3 .field, .row-fields-4 .field { margin-bottom: 0; }
@media (max-width: 720px) { .row-fields, .row-fields-3, .row-fields-4 { grid-template-columns: 1fr; } }

.help { font-size: 0.82rem; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* ----- Buttons ----- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: var(--radius);
  font: inherit; font-weight: 600; font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--highlight); color: #fff;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--accent); color: var(--paper); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(125, 197, 156, 0.28); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn:disabled:hover { background: var(--highlight); color: #fff; }

.btn-secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-soft); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper-soft); color: var(--ink); border-color: var(--ink-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--ink); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 0.82rem; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button-row form { display: inline-flex; margin: 0; }

/* Espace entre une grille de champs et la rangée de boutons qui suit */
.row-fields + .button-row,
.row-fields-3 + .button-row,
.row-fields-4 + .button-row,
.field + .button-row {
  margin-top: 18px;
}

/* ----- Tables ----- */

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 0.94rem; }
table th { font-family: var(--font-mono); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; }
table tbody tr:hover { background: rgba(125, 197, 156, 0.05); }
table tr.row-error { background: rgba(217, 119, 102, 0.08); }
table tr.row-warn  { background: rgba(224, 182, 107, 0.08); }
table .row-status { font-family: var(--font-mono); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
table .row-status.ok   { color: var(--accent); }
table .row-status.err  { color: var(--danger); }
table .row-status.warn { color: var(--warn); }

/* ----- Status pill ----- */

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; border: 1px solid var(--line); color: var(--ink-soft); background: var(--paper-soft); }
.pill.draft { color: var(--muted); }
.pill.sent  { color: var(--warn); border-color: rgba(224, 182, 107, 0.4); }
.pill.client_validated { color: var(--accent); border-color: rgba(125, 197, 156, 0.4); background: rgba(63, 167, 122, 0.12); }
.pill.archived { color: var(--muted); opacity: 0.7; }

/* ----- Segmented control (rôle ADMIN / NON_ADMIN) ----- */

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
  height: 32px;
}
.segmented form { display: inline-flex; }
.segmented form + form { border-left: 1px solid var(--line); }
.segmented button {
  background: transparent;
  color: var(--ink-soft);
  border: none;
  height: 100%;
  padding: 0 14px;
  cursor: pointer;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  transition: background .12s, color .12s;
}
.segmented button.active { background: var(--accent); color: var(--paper); font-weight: 600; }
.segmented button:hover:not(.active) { background: var(--paper-warm); color: var(--ink); }

/* ----- Misc ----- */

.alert { padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 14px; font-size: 0.92rem; }
.alert-error { color: var(--danger); border-color: rgba(217, 119, 102, 0.4); background: rgba(217, 119, 102, 0.08); }
.alert-warn  { color: var(--warn); border-color: rgba(224, 182, 107, 0.4); background: rgba(224, 182, 107, 0.08); }
.alert-ok    { color: var(--accent); border-color: rgba(125, 197, 156, 0.4); background: rgba(63, 167, 122, 0.1); }

.counter { font-family: var(--font-mono); font-size: 0.88rem; color: var(--muted); letter-spacing: 0.04em; }
.counter .n { color: var(--accent); font-weight: 600; font-size: 1.02rem; }

/* ----- <details> / <summary> harmonisé ----- */

details.disclosure {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  overflow: hidden;
  transition: border-color .15s;
}
details.disclosure[open] { border-color: rgba(125, 197, 156, 0.35); }
details.disclosure > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  transition: background .15s, color .15s;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(-45deg) translate(-1px, 1px);
  transition: transform .2s ease;
}
details.disclosure[open] > summary::before { transform: rotate(45deg) translate(-2px, -2px); }
details.disclosure > summary:hover { background: var(--paper-soft); color: var(--ink); }
details.disclosure > summary:hover::before { border-color: var(--ink); }
details.disclosure .disclosure-body { padding: 4px 16px 18px; border-top: 1px solid var(--line); }

.copy-row { display: flex; align-items: stretch; gap: 8px; }
.copy-row code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  background: var(--paper);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  flex: 1;
  min-width: 0;
  word-break: break-all;
  line-height: 1.5;
  display: flex;
  align-items: center;
}
.copy-row .btn { flex-shrink: 0; }

.pin-box { font-family: var(--font-mono); font-size: 2rem; letter-spacing: 0.4em; padding: 14px 22px; background: var(--paper); border: 1px dashed var(--accent); color: var(--accent); border-radius: var(--radius); text-align: center; }

/* ----- Centered auth + PIN ----- */

.auth-shell { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 420px; padding: 32px; }

/* ----- Utilitaires (remplacent les style="..." inline) ----- */

.divider { border: none; border-top: 1px solid var(--line); margin: 22px 0; }
.stack-md > * + * { margin-top: 14px; }
.stack-lg > * + * { margin-top: 22px; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.toolbar .field { flex: 1; min-width: 200px; margin-bottom: 0; }
.toolbar .field.field-fixed { flex: 0 0 220px; }
@media (max-width: 720px) { .toolbar .field.field-fixed { flex: 1; } }
.table-empty { text-align: center; padding: 26px 16px; color: var(--muted); font-style: italic; }
.card-flush { padding: 0; overflow: hidden; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted-mono { color: var(--muted); font-family: var(--font-mono); font-size: 0.82rem; letter-spacing: 0.04em; }

/* ----- Mobile-first tweaks pour l'espace client ----- */

@media (max-width: 720px) {
  main { padding: 16px 0 48px; }
  .card { padding: 16px 18px; }
  h1 { font-size: 1.45rem; }
  .auth-card { padding: 22px; }
}

.paste-preview-slot:empty { display: none; }
.paste-preview-slot { margin-top: 14px; }

/* ----- HTMX swap indicator ----- */

.htmx-indicator { opacity: 0; transition: opacity .15s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }
