:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2230;
  --text-muted: #6b7280;
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* 2026-08-17 : sans ce !important, [hidden] perd contre .login-screen/.app-shell
   (display: flex) à spécificité égale — le JS pose bien hidden=true/false mais
   l'écran de connexion restait visible à l'écran (bug réel, vu en capture
   d'écran WebKit : élément marqué hidden en DOM, toujours affiché visuellement). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0 0 0.4em; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.login-card .subtitle {
  margin: -0.6rem 0 0.4rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Inputs / buttons ---------- */
input, select, textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
}

.primary-btn {
  background: var(--primary);
  color: white;
}
.primary-btn:hover { background: var(--primary-hover); }

.secondary-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.secondary-btn:hover { background: var(--bg); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  padding: 0.2rem 0;
  text-decoration: none;
  font-weight: 500;
}
.link-btn:hover { text-decoration: underline; }

button.small, .link-btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.error-text { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-weight: 700; }

.tabs { display: flex; gap: 0.25rem; flex: 1; }

.tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
}
.tab-btn.active { background: var(--bg); color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }
.whoami { font-size: 0.85rem; color: var(--text-muted); }

main { padding: 1.5rem; flex: 1; }

.tab-panel[hidden] { display: none; }

/* ---------- Organisations ---------- */
.panel-columns { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; align-items: start; }

.panel-list, .panel-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel-list-header { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.panel-list-header input { flex: 1; min-width: 0; }

.org-list { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.org-list li {
  padding: 0.6rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.org-list li:hover { background: var(--bg); }
.org-list li.selected { background: #eef2ff; }
.org-list .org-name { font-weight: 600; }
.org-list .org-email { display: block; font-size: 0.8rem; color: var(--text-muted); }

.empty-state { color: var(--text-muted); padding: 2rem; text-align: center; }

.meta-line { color: var(--text-muted); font-size: 0.9rem; margin-top: 0; }

.detail-section { margin-top: 1.5rem; }
.detail-section-header { display: flex; align-items: center; justify-content: space-between; }

.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 0.6rem 0;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 6px;
}
.inline-form[hidden] { display: none; }
.inline-form input, .inline-form select { flex: 1; min-width: 140px; }
.inline-form textarea { flex-basis: 100%; resize: vertical; font-family: inherit; }
.inline-form .checkbox-label { flex-basis: 100%; display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.inline-form .checkbox-label input { flex: none; width: auto; }

.data-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9rem; }
.data-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
}
.data-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table td.actions-cell { text-align: right; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-ok { background: #ecfdf5; color: var(--success); }
.badge-warn { background: #fffbeb; color: #b45309; }
.badge-bad { background: var(--danger-bg); color: var(--danger); }

.text-danger { color: var(--danger); }

.favoris-fa-user { margin-bottom: 1.5rem; }
.favoris-fa-user:last-child { margin-bottom: 0; }
.favoris-fa-user .badge { display: block; width: fit-content; margin-bottom: 0.5rem; }

/* ---------- Tarification (aperçu tel qu'affiché sur /tarifs) ---------- */
.pricing-group { margin-bottom: 2rem; }

.pricing-group-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.pricing-group-header h3 { margin: 0; }
.pricing-group-count { color: var(--text-muted); font-size: 0.85rem; }

.pricing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.pricing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pricing-card-title { font-weight: 600; }
.pricing-card-subtitle { color: var(--text-muted); font-size: 0.85rem; margin: 0; }
.pricing-card-price { font-weight: 700; color: var(--primary); }

.pricing-card-features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  flex: 1;
}
.pricing-card-features li { padding-left: 1.1em; position: relative; }
.pricing-card-features li::before { content: "✓"; position: absolute; left: 0; color: var(--success); }
.pricing-card-features-empty { color: var(--text-muted); font-size: 0.85rem; font-style: italic; }

.pricing-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.pricing-card-actions { display: flex; gap: 0.75rem; }

/* ---------- Audit ---------- */
.audit-filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; justify-content: center; }
.pagination span { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Dialog ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
dialog::backdrop { background: rgba(15, 18, 25, 0.4); }
dialog form { display: flex; flex-direction: column; gap: 0.75rem; }
dialog label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ---------- Demandes de connexion ---------- */
.tab-badge { margin-left: 0.4rem; }

.request-detail-dialog {
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.request-detail-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.9rem;
}
.request-detail-grid > span:nth-child(odd) { color: var(--text-muted); }

.document-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.document-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.document-list .document-meta { color: var(--text-muted); font-size: 0.8rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.toast.toast-error { background: var(--danger); }
.toast[hidden] { display: none; }

@media (max-width: 800px) {
  .panel-columns { grid-template-columns: 1fr; }
}
