:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #f8fafc;
  --muted: #94a3b8;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-light);
  flex-wrap: wrap;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active,
.tab-btn:hover {
  background: var(--surface-light);
  color: var(--text);
}

.auth-zone {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.badge-role {
  background: var(--primary);
  color: #0f172a;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Buttons & Inputs */
button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  transition: 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #0f172a;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: white;
}

.btn-secondary {
  background: var(--surface-light);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.full-width {
  width: 100%;
  margin-top: 0.5rem;
}

input,
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--surface-light);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  width: 100%;
}

/* Main Container */
.container {
  flex: 1;
  padding: 1.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* 3D Layout */
.layout-3d {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.5rem;
  height: calc(100vh - 110px);
  min-height: 520px;
}

.canvas-wrapper {
  position: relative;
  background: #090d16;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--surface-light);
}

#scene-container {
  width: 100%;
  height: 100%;
}

.hint-3d {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15, 23, 42, 0.85);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  pointer-events: none;
}

.zone-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Filters & Cards */
.filters-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.admin-sort-bar input[type="search"] {
  flex: 1;
  min-width: 180px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.filters-bar input,
.filters-bar select {
  width: auto;
  min-width: 170px;
  flex: 1;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.cards-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.voie-card,
.card {
  background: var(--surface);
  border: 1px solid var(--surface-light);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.zone-panel .voie-card {
  background: var(--bg);
}

.voie-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.cotation-badge {
  background: var(--primary);
  color: #0f172a;
  font-weight: 800;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

/* Étiquettes d'information (non cliquables) */
.meta-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: default;
  user-select: none;
}

/* Boutons d'action cliquables (À faire / Fait / Voir) */
.statut-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.statut-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  border: 2px solid #475569;
  font-size: 0.82rem;
  padding: 0.38rem 0.75rem;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.statut-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.statut-btn:active {
  transform: translateY(0);
}

/* Contour orange pour "À faire" */
.statut-btn[data-statut="todo"] {
  border-color: var(--warning);
  background: rgba(245, 158, 11, 0.12);
}

.statut-btn[data-statut="todo"]:hover {
  background: rgba(245, 158, 11, 0.25);
}

/* Contour vert pour "Fait" */
.statut-btn[data-statut="done"] {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.12);
}

.statut-btn[data-statut="done"]:hover {
  background: rgba(34, 197, 94, 0.25);
}

/* Contour bleu cyan pour "Voir" */
.btn-voir-3d {
  border-color: var(--primary);
  background: rgba(56, 189, 248, 0.12);
  color: var(--primary);
}

.btn-voir-3d:hover {
  background: rgba(56, 189, 248, 0.28);
  color: #ffffff;
}

/* États actifs (fond plein quand sélectionné) */
.statut-btn.active-todo {
  background: var(--warning);
  border-color: #fbbf24;
  color: #0f172a;
}

.statut-btn.active-done {
  background: var(--success);
  border-color: #4ade80;
  color: #0f172a;
}

/* Bouton "Voir" : teinte bleue pour la navigation vers la 3D */
.btn-voir-3d {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.55);
  color: var(--primary);
}

.btn-voir-3d:hover {
  background: rgba(56, 189, 248, 0.28);
  border-color: var(--primary);
  color: #ffffff;
}

/* États actifs */
.statut-btn.active-todo {
  background: var(--warning);
  border-color: #fbbf24;
  color: #0f172a;
}

.statut-btn.active-done {
  background: var(--success);
  border-color: #4ade80;
  color: #0f172a;
}

/* Remarques */
.remarques-box {
  border-top: 1px solid var(--surface-light);
  padding-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.remarque-item {
  background: rgba(255, 255, 255, 0.04);
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.remarque-top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.remarque-actions button {
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  margin-left: 0.25rem;
}

.add-remarque-form {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

/* Admin */
.admin-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  align-items: start;
}

#admin-voie-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

#admin-voie-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
}

.admin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--surface-light);
}

/* Tri et séparation Voies / Blocs (Admin) */
.admin-sort-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--surface-light);
}

.admin-sort-bar label {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.admin-sort-bar select {
  width: auto;
  min-width: 190px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.admin-group {
  margin-bottom: 1.25rem;
}

.admin-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.group-voie .admin-group-header {
  background: rgba(56, 189, 248, 0.12);
  color: var(--primary);
  border-left: 3px solid var(--primary);
}

.group-bloc .admin-group-header {
  background: rgba(245, 158, 11, 0.12);
  color: var(--warning);
  border-left: 3px solid var(--warning);
}

.admin-group-count {
  background: rgba(15, 23, 42, 0.6);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.badge-type {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  margin-left: 0.3rem;
  vertical-align: middle;
}

.badge-voie {
  background: rgba(56, 189, 248, 0.18);
  color: var(--primary);
}

.badge-bloc {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
}

.modal-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.modal-tabs button {
  flex: 1;
  background: var(--bg);
  color: var(--muted);
}

.modal-tabs button.active {
  background: var(--primary);
  color: #0f172a;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.1rem;
}

@media (max-width: 900px) {

  .layout-3d,
  .admin-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .canvas-wrapper {
    height: 380px;
  }
}

/* === MODE CLAIR === */
:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-light: #cbd5e1;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #0f172a;
  --muted: #475569;
}

/* Ajustements des éléments qui avaient un fond sombre fixe */
[data-theme="light"] .btn-primary,
[data-theme="light"] .badge-role,
[data-theme="light"] .cotation-badge,
[data-theme="light"] .modal-tabs button.active {
  color: #ffffff;
}

[data-theme="light"] .canvas-wrapper {
  background: #e2e8f0;
}

[data-theme="light"] .hint-3d {
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  border: 1px solid var(--surface-light);
}

[data-theme="light"] .tag {
  background: rgba(15, 23, 42, 0.05);
  border-color: rgba(71, 85, 105, 0.3);
}

[data-theme="light"] .statut-btn {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .statut-btn.active-todo,
[data-theme="light"] .statut-btn.active-todo:hover {
  background: var(--warning);
  border-color: var(--warning);
  color: #ffffff;
}

[data-theme="light"] .statut-btn.active-done,
[data-theme="light"] .statut-btn.active-done:hover {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

[data-theme="light"] .btn-voir-3d {
  background: rgba(2, 132, 199, 0.1);
  color: var(--primary);
}

[data-theme="light"] .btn-voir-3d:hover {
  background: var(--primary);
  color: #ffffff;
}

[data-theme="light"] .remarque-item {
  background: rgba(15, 23, 42, 0.04);
}

[data-theme="light"] .admin-group-count {
  background: rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .voie-card,
[data-theme="light"] .card,
[data-theme="light"] .zone-panel {
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

/* Bouton de bascule clair / sombre dans la navbar */
.btn-theme-toggle {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface-light);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-theme-toggle:hover {
  border-color: var(--primary);
}