@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --ink: #16181d;
  --ink-soft: #4b5059;
  --muted: #868d99;
  --line: #e4e7ec;
  --line-soft: #eef0f3;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --teal: #1e6b5c;
  --teal-dark: #164f44;
  --teal-soft: #e5f2ef;
  --orange: #d9772a;
  --beige: #f3e4d6;
  --amber: #b4740a;
  --amber-soft: #fbf0dc;
  --red: #b3261e;
  --red-soft: #fbe9e8;
  --green: #0b8a3a;
  --green-soft: #e6f6ec;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .04), 0 8px 24px -12px rgba(16, 20, 28, .12);
  --shadow-lg: 0 24px 60px -20px rgba(16, 20, 28, .35);
}

* { box-sizing: border-box; }
/* ⚠️ Plusieurs règles ci-dessous (.view-app, .overlay, #modal-overlay…)
 * posent `display: flex` sans condition. Une règle AUTEUR de même origine
 * bat TOUJOURS la feuille par défaut du navigateur (`[hidden]{display:none}`)
 * — même à spécificité égale ou inférieure, l'origine prime sur la
 * spécificité. Sans ce correctif, l'attribut `hidden` est purement
 * décoratif : chaque panneau/overlay s'affichait dès le chargement de la
 * page, par-dessus l'écran de connexion. `!important` est la seule façon
 * fiable de rendre `hidden` prioritaire sur N'IMPORTE quelle règle de
 * ce fichier, présente ou future.
 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
table { border-collapse: collapse; width: 100%; }
svg { width: 16px; height: 16px; stroke-width: 2.1; vertical-align: -3px; }

/* ───────────────────────── Boutons ───────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #f6d7d5; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-icon { padding: 8px; }

/* ───────────────────────── Écran de connexion ───────────────────────── */
.view-login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1100px 500px at 15% -10%, #ecf5f2 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #fbf1e7 0%, transparent 55%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-brand-mark {
  width: 44px; height: 44px; border-radius: 10px; background: var(--ink);
  color: #fff; font-weight: 800; font-size: 15px; display: flex; align-items: center; justify-content: center;
  letter-spacing: -0.02em;
}
.login-brand-title { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.login-brand-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; font-size: 14.5px; color: var(--ink); background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft);
}
.error-text { color: var(--red); font-size: 13px; margin: -4px 0 14px; display: flex; gap: 6px; align-items: flex-start; }
.login-footnote { margin-top: 20px; font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ───────────────────────── Mise en page app ───────────────────────── */
.view-app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: none; background: var(--ink); color: #fff;
  display: flex; flex-direction: column; padding: 20px 14px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; }
.sidebar-brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--teal);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12.5px;
}
.sidebar-brand-title { font-weight: 800; font-size: 15px; letter-spacing: -0.02em; }
.sidebar-brand-sub { font-size: 10.5px; color: #aab0bd; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; background: transparent; border: none;
  color: #c3c8d4; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  text-align: left; transition: background .12s, color .12s;
}
.nav-item:hover { background: #22252d; color: #fff; }
.nav-item.active { background: var(--teal); color: #fff; }
.sidebar-user { border-top: 1px solid #2a2d36; padding-top: 14px; margin-top: 10px; }
.sidebar-user-name { font-size: 13.5px; font-weight: 700; }
.sidebar-user-role { font-size: 11.5px; color: #9aa0ad; margin: 2px 0 12px; }
.sidebar-user .btn-ghost { border-color: #343843; color: #c3c8d4; }
.sidebar-user .btn-ghost:hover { background: #22252d; color: #fff; }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.tab { display: none; }
.tab.active { display: block; }
.tab-header { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.tab-header h1 { font-size: 22px; font-weight: 800; }
.tab-sub { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.select {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 30px 9px 12px;
  font-size: 13.5px; color: var(--ink-soft); background: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23868d99' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

/* ───────────────────────── Table des fiches ───────────────────────── */
.fn-table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.fn-table { font-size: 13.5px; }
.fn-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: #fbfbfc;
}
.fn-table td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); color: var(--ink-soft); }
.fn-table tr:last-child td { border-bottom: none; }
.fn-table tbody tr { cursor: pointer; transition: background .1s; }
.fn-table tbody tr:hover { background: var(--teal-soft); }
.fn-table .ref-cell { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.empty-row { text-align: center; color: var(--muted); padding: 32px !important; cursor: default; }
.empty-row:hover { background: transparent !important; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-soumis { background: var(--amber-soft); color: var(--amber); }
.badge-a_mettre_a_jour { background: var(--red-soft); color: var(--red); }
.badge-valide { background: var(--green-soft); color: var(--green); }
.check-ok { color: var(--green); font-weight: 700; }
.check-pending { color: var(--muted); }

/* ───────────────────────── Gestion ───────────────────────── */
.gestion-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .gestion-grid { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-header h2 { font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.mini-table { font-size: 13px; }
.mini-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 18px; border-bottom: 1px solid var(--line); }
.mini-table td { padding: 11px 18px; border-bottom: 1px solid var(--line-soft); color: var(--ink-soft); }
.mini-table tr:last-child td { border-bottom: none; }
.link-btn { background: none; border: none; color: var(--teal); font-weight: 600; font-size: 12.5px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot-on { background: var(--green); }
.dot-off { background: var(--muted); }

/* ───────────────────────── Panneau latéral (détail fiche) ───────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(16, 20, 28, .45); backdrop-filter: blur(2px);
  display: flex; justify-content: flex-end; z-index: 50;
}
.panel {
  width: min(640px, 100%); height: 100%; background: var(--surface);
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.panel-ref { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.panel-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 24px 24px; }
.panel-footer { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; }

.fn-section { margin-top: 22px; }
.fn-section-title {
  font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
  color: var(--teal-dark); background: var(--beige); display: inline-block;
  padding: 3px 10px; border-radius: 999px; margin-bottom: 12px;
}
.fn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.fn-grid.full { grid-template-columns: 1fr; }
.fn-item-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 3px; }
.fn-item-value { font-size: 14px; color: var(--ink); line-height: 1.45; white-space: pre-wrap; }
.fn-item-value.empty { color: var(--muted); font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--teal-soft); color: var(--teal-dark); font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.status-row { display: flex; gap: 20px; margin-top: 4px; }
.status-pill { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; }

/* ───────────────────────── Modale ───────────────────────── */
.modal-overlay, #modal-overlay { position: fixed; inset: 0; background: rgba(16,20,28,.45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-header h3 { font-size: 15.5px; font-weight: 700; }
.modal-body { padding: 18px 20px 20px; overflow-y: auto; }
.modal-body .field { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.help-text { font-size: 11.5px; color: var(--muted); margin-top: -8px; margin-bottom: 14px; line-height: 1.5; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 100;
  display: flex; align-items: center; gap: 8px;
}
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--green); }

.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────── Responsive ───────────────────────── */
@media (max-width: 860px) {
  .view-app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; gap: 16px; }
  .sidebar-brand { padding: 0; flex: none; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .sidebar-user { border-top: none; border-left: 1px solid #2a2d36; padding: 0 0 0 16px; margin: 0; display: flex; align-items: center; gap: 10px; }
  .sidebar-user-name, .sidebar-user-role { display: none; }
  .sidebar-user .btn-ghost { width: auto; padding: 8px; }
  .sidebar-user .btn-ghost span { display: none; }
  .main { padding: 20px 16px 50px; }
  .fn-table { font-size: 12.5px; }
  .fn-table th:nth-child(3), .fn-table td:nth-child(3) { display: none; }
  .fn-grid { grid-template-columns: 1fr; }
  .panel { width: 100%; }
}
