:root {
  --blue: #0057d8;
  --blue-dark: #003f9e;
  --blue-soft: #e8f1ff;
  --black: #111827;
  --muted: #5b6472;
  --border: #d8dee8;
  --bg: #f4f7fb;
  --white: #ffffff;
  --success: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 10px 30px rgba(16, 40, 80, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(0, 87, 216, 0.08), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(0, 87, 216, 0.05), transparent 35%),
    var(--bg);
  color: var(--black);
  min-height: 100vh;
  line-height: 1.7;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

.container {
  width: min(1100px, calc(100% - 2rem));
  margin-inline: auto;
}

/* Header */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand img {
  height: 52px;
  width: auto;
  aspect-ratio: 200 / 52;
}

.brand-text h1 {
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  font-weight: 800;
  color: var(--blue);
  line-height: 1.3;
}

.brand-text p {
  font-size: 0.85rem;
  color: var(--muted);
}

.nav-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  font-family: inherit;
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.main-nav a {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--muted);
  transition: 0.2s ease;
}

.main-nav a:hover,
.main-nav a.active {
  background: var(--blue-soft);
  color: var(--blue);
}

/* Hero */
.hero {
  padding: 3.5rem 0 2.5rem;
  text-align: center;
}

.hero h2 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  margin-bottom: 0.6rem;
}

.hero p {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 560px;
  margin-inline: auto;
}

.rubrique-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  padding-bottom: 3rem;
}

.rubrique-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.rubrique-card:hover {
  transform: translateY(-3px);
  border-color: #a9c5f5;
}

.rubrique-card h3 {
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
}

.rubrique-card p {
  color: var(--muted);
  font-size: 0.92rem;
}

.rubrique-card .arrow {
  margin-top: 0.9rem;
  color: var(--blue);
  font-weight: 700;
  font-size: 0.92rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  background: var(--white);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Search page */
.search-panel {
  max-width: 720px;
  margin: 2.5rem auto 2rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.search-panel h2 {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
}

.search-panel .subtitle {
  color: var(--muted);
  margin-bottom: 1.4rem;
}

.search-form {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: stretch;
}

.search-inputs {
  flex: 1;
  display: grid;
  gap: 0.7rem;
  min-width: 200px;
}

.search-inputs.dual {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.search-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-form input:focus {
  border-color: var(--blue);
}

.search-form .btn {
  align-self: end;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.3rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
}

.btn-primary {
  background: var(--blue);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--blue-dark);
}

.btn-secondary {
  background: var(--blue-soft);
  color: var(--blue);
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.alert {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  font-weight: 600;
}

.alert-error {
  background: #fee2e2;
  color: var(--danger);
}

.alert-success {
  background: #d1fae5;
  color: var(--success);
}

.alert-info {
  background: var(--blue-soft);
  color: var(--blue);
}

.results {
  margin: 0 auto 3rem;
  max-width: 900px;
}

.results-compact {
  max-width: 1100px;
}

.result-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-bottom: 1rem;
  animation: fadeUp 0.35s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}

.result-item label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.result-item span {
  font-weight: 700;
  font-size: 1.02rem;
  word-break: break-word;
}

.result-item.highlight span {
  color: var(--blue);
}

.compact-wrap {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compact-hint {
  margin: 0;
  padding: 0.65rem 0.9rem;
  font-size: 0.88rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
}

.compact-scroll {
  max-height: min(62vh, 520px);
  overflow: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}

.results-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf2f8;
  color: var(--black);
  font-weight: 800;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: start;
}

.results-table tbody td {
  padding: 0.35rem 0.55rem;
  border-bottom: 1px solid #eef1f5;
  vertical-align: middle;
}

.results-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.results-table tbody tr:hover {
  background: #f5f8fc;
}

.results-table tbody tr.active {
  background: var(--blue-soft);
}

.results-table .row-num {
  width: 2.2rem;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.results-table th.is-key,
.results-table td.is-key {
  color: var(--blue);
  font-weight: 800;
}

.results-table .badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
}

.compact-detail {
  border-top: 1px solid var(--border);
  padding: 0.9rem;
  background: #fafbfd;
}

.compact-detail .result-card {
  box-shadow: none;
  margin: 0;
  padding: 0.9rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: #d1fae5;
  color: var(--success);
  font-weight: 700;
  font-size: 0.9rem;
}

.badge.fail {
  background: #fee2e2;
  color: var(--danger);
}

.result-actions {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.btn-bepc {
  width: 100%;
}

.bepc-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.bepc-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}

.bepc-modal-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(90vh, 800px);
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bepc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--blue-soft);
}

.bepc-modal-header h3 {
  margin: 0;
  color: var(--blue);
  font-size: 1.15rem;
}

.bepc-modal-close {
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}

.bepc-modal-body {
  padding: 1.2rem;
  overflow: auto;
}

.bepc-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.bepc-summary-item label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.bepc-summary-item span {
  font-weight: 700;
}

.bepc-notes-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.bepc-notes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.bepc-notes-table th,
.bepc-notes-table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: start;
}

.bepc-notes-table th {
  background: var(--blue-soft);
  color: var(--blue);
}

.bepc-loading {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

/* Admin */
.admin-body {
  background: #eef2f7;
}

.admin-wrap {
  width: min(920px, calc(100% - 2rem));
  margin: 2rem auto 3rem;
}

.admin-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem;
  margin-bottom: 1.2rem;
}

.admin-card h2,
.admin-card h3 {
  margin-bottom: 0.8rem;
}

.admin-card p.hint {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
}

.steps {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.step-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: #e5e7eb;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.step-pill.active {
  background: var(--blue);
  color: white;
}

.step-pill.done {
  background: #d1fae5;
  color: var(--success);
}

.column-list {
  display: grid;
  gap: 0.75rem;
}

.column-row {
  display: grid;
  grid-template-columns: auto 1fr 1.2fr auto auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 12px;
}

.column-row .col-order {
  display: flex;
  gap: 0.25rem;
}

.column-row .col-order .btn-sm {
  min-width: 2rem;
  padding: 0.35rem 0.45rem;
}

.column-row .btn-icon {
  border: none;
  background: #fee2e2;
  color: var(--danger);
  border-radius: 10px;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  font-family: inherit;
}

.column-row .btn-icon:hover {
  background: #fecaca;
}

.column-row .original {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.92rem;
  word-break: break-word;
}

.column-row input[type='radio'] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--blue);
}

.sample-table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.sample-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.sample-table th,
.sample-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  text-align: start;
  white-space: nowrap;
}

.sample-table th {
  background: var(--blue-soft);
  color: var(--blue);
}

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}

.rubrique-admin-list {
  display: grid;
  gap: 0.75rem;
}

.rubrique-admin-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border-radius: 12px;
}

.rubrique-admin-info {
  min-width: 0;
  flex: 1;
}

.rubrique-admin-item strong {
  display: block;
}

.rubrique-admin-item span {
  color: var(--muted);
  font-size: 0.9rem;
  display: block;
}

.rubrique-admin-item .meta-label {
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.rubrique-admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.btn-sm {
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
  border-radius: 10px;
}

.hidden {
  display: none !important;
}

.site-footer {
  text-align: center;
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Admin : pas de mise en page mobile (desktop uniquement) */
.admin-body {
  min-width: 960px;
  overflow-x: auto;
}

.admin-body .site-header .header-inner {
  flex-wrap: nowrap;
}

.admin-body .nav-toggle {
  display: none !important;
}

/* ========== Responsive site public uniquement ========== */
@media (max-width: 900px) {
  .public-body .container {
    width: min(1100px, calc(100% - 1.25rem));
  }

  .public-body .rubrique-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  .public-body .results,
  .public-body .results-compact {
    max-width: 100%;
  }

  .public-body .result-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.65rem;
  }
}

@media (max-width: 720px) {
  .public-body .header-inner {
    flex-wrap: wrap;
    padding: 0.7rem 0;
    gap: 0.65rem;
  }

  .public-body .brand {
    flex: 1;
    min-width: 0;
    gap: 0.65rem;
  }

  .public-body .brand img {
    height: 42px;
    flex-shrink: 0;
  }

  .public-body .brand-text {
    min-width: 0;
  }

  .public-body .brand-text h1 {
    font-size: 0.98rem;
  }

  .public-body .brand-text p {
    font-size: 0.78rem;
  }

  .public-body .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    min-height: 42px;
    font-size: 1.15rem;
  }

  .public-body .main-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding-bottom: 0.5rem;
  }

  .public-body .main-nav.open {
    display: flex;
  }

  .public-body .main-nav a {
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    background: var(--bg);
  }

  .public-body .hero {
    padding: 2rem 0 1.5rem;
  }

  .public-body .hero h2 {
    font-size: clamp(1.35rem, 6vw, 1.8rem);
  }

  .public-body .hero p {
    font-size: 0.95rem;
    padding-inline: 0.25rem;
  }

  .public-body .rubrique-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding-bottom: 2rem;
  }

  .public-body .rubrique-card {
    padding: 1.15rem 1rem;
  }

  .public-body .search-panel {
    margin: 1.25rem auto 1.25rem;
    padding: 1.15rem;
    border-radius: 12px;
  }

  .public-body .search-panel h2 {
    font-size: 1.25rem;
  }

  .public-body .search-panel .subtitle {
    font-size: 0.9rem;
    margin-bottom: 1rem;
  }

  .public-body .search-form {
    flex-direction: column;
  }

  .public-body .search-inputs {
    min-width: 0;
    width: 100%;
  }

  .public-body .search-inputs.dual {
    grid-template-columns: 1fr;
  }

  .public-body .search-form input {
    font-size: 16px; /* évite zoom iOS */
    padding: 0.8rem 0.9rem;
  }

  .public-body .search-form .btn {
    width: 100%;
    align-self: stretch;
  }

  .public-body .results {
    margin-bottom: 2rem;
  }

  .public-body .result-card {
    padding: 1rem;
  }

  .public-body .result-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
  }

  .public-body .result-item span {
    font-size: 0.95rem;
  }

  .public-body .compact-hint {
    font-size: 0.8rem;
    padding: 0.55rem 0.75rem;
  }

  .public-body .compact-scroll {
    max-height: min(55vh, 420px);
    -webkit-overflow-scrolling: touch;
  }

  .public-body .results-table {
    font-size: 0.75rem;
  }

  .public-body .results-table thead th,
  .public-body .results-table tbody td {
    padding: 0.4rem 0.45rem;
  }

  .public-body .compact-detail {
    padding: 0.7rem;
  }

  .public-body .site-footer {
    font-size: 0.82rem;
    padding: 1.25rem 0 1.5rem;
  }
}

@media (max-width: 420px) {
  .public-body .container {
    width: calc(100% - 0.9rem);
  }

  .public-body .brand-text h1 {
    font-size: 0.88rem;
    line-height: 1.35;
  }

  .public-body .result-grid {
    grid-template-columns: 1fr;
  }

  .public-body .empty-state {
    padding: 2rem 0.75rem;
    font-size: 0.92rem;
  }
}
