/* ===== VARIABLES & RESET ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.04);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== NAVIGATION ===== */
.navbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.navbar h1 .icon { font-size: 1.5rem; }
.navbar nav { display: flex; gap: .5rem; }
.navbar nav a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  transition: all .2s;
}
.navbar nav a:hover,
.navbar nav a.active {
  background: rgba(255,255,255,.2);
  color: white;
}

/* ===== LAYOUT ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.container-wide {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ===== CARDS & SECTIONS ===== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.card-header {
  padding: 1rem 1.5rem;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: white;
}
.card-header .icon { font-size: 1.1rem; }
.card-body { padding: 1.5rem; }

/* Category colors */
.card-header.cat-general    { background: var(--primary); }
.card-header.cat-palette    { background: #7c3aed; }
.card-header.cat-dates      { background: #0891b2; }
.card-header.cat-vehicule   { background: #ea580c; }
.card-header.cat-besoins    { background: #16a34a; }
.card-header.cat-adresses   { background: #be185d; }

/* ===== FORM ELEMENTS ===== */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.form-row:last-child { margin-bottom: 0; }

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: .6rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--gray-800);
  transition: border-color .2s, box-shadow .2s;
  background: white;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input[type="number"] { max-width: 150px; }

/* Toggle switch for OUI/NON */
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: .5rem;
}
.toggle-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--gray-50);
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-200);
  min-width: 180px;
}
.toggle-item .toggle-label,
.toggle-item > label:not(.switch) {
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  flex: 1;
}
.switch {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.slider {
  position: absolute; inset: 0;
  background: var(--gray-300);
  border-radius: 24px;
  cursor: pointer;
  transition: .3s;
}
.slider::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .3s;
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* Palette table */
.palette-table {
  width: 100%;
  border-collapse: collapse;
}
.palette-table th,
.palette-table td {
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  font-size: .875rem;
}
.palette-table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .03em;
}
.palette-table input {
  width: 100%;
  padding: .4rem .5rem;
  border: 1.5px solid var(--gray-300);
  border-radius: 6px;
  font-size: .875rem;
  text-align: center;
}
.palette-table input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
  background: white;
  color: var(--gray-700);
  border: 1.5px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: .4rem .75rem; font-size: .8rem; }
.btn-lg { padding: .85rem 2rem; font-size: 1rem; }

.form-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
}

/* ===== ADMIN TABLE ===== */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.admin-header h2 {
  font-size: 1.5rem;
  color: var(--gray-800);
}

.filters {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
}
.filters input,
.filters select {
  padding: .5rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .85rem;
  font-family: inherit;
}
.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th,
.data-table td {
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  font-size: .85rem;
}
.data-table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .03em;
}
.data-table tr:hover td { background: var(--primary-light); }
.data-table .actions { display: flex; gap: .35rem; }

/* Status badges */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-nouveau    { background: var(--info-light); color: var(--info); }
.badge-en-cours   { background: var(--warning-light); color: #b45309; }
.badge-valide     { background: var(--primary-light); color: var(--primary); }
.badge-livre      { background: var(--success-light); color: var(--success); }
.badge-annule     { background: var(--danger-light); color: var(--danger); }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding: 3rem 1rem;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 700px;
  animation: slideIn .25s ease;
}
@keyframes slideIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
  line-height: 1;
}
.modal-close:hover { color: var(--gray-800); }
.modal-body { padding: 1.5rem; max-height: 70vh; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Detail grid in modal */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.detail-item {
  padding: .5rem;
  background: var(--gray-50);
  border-radius: 6px;
}
.detail-item .label {
  font-size: .7rem;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--gray-500);
  letter-spacing: .03em;
  margin-bottom: .15rem;
}
.detail-item .value {
  font-size: .9rem;
  color: var(--gray-800);
  font-weight: 500;
}
.detail-item.full { grid-column: 1 / -1; }

.detail-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}
.detail-section h4 {
  font-size: .85rem;
  color: var(--gray-600);
  margin-bottom: .75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* ===== STATS ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .number {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}
.stat-card .label {
  font-size: .8rem;
  color: var(--gray-500);
  margin-top: .35rem;
  text-transform: uppercase;
  font-weight: 600;
}
.stat-card.stat-total .number { color: var(--gray-800); }
.stat-card.stat-nouveau .number { color: var(--info); }
.stat-card.stat-en-cours .number { color: var(--warning); }
.stat-card.stat-valide .number { color: var(--primary); }
.stat-card.stat-livre .number { color: var(--success); }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  color: white;
  font-weight: 500;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease, toastOut .3s ease 2.7s forwards;
  max-width: 350px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; }

/* ===== REQUIRED FIELDS ===== */
.required { color: var(--danger); font-weight: 700; }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--gray-200);
}
.tab {
  padding: .75rem 1.5rem;
  background: none;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
  font-family: inherit;
}
.tab:hover { color: var(--gray-700); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== AGENCE ROWS ===== */
.agence-row {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}
.agence-row input {
  flex: 1;
  padding: .5rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: inherit;
}
.agence-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== URGENCE ROW HIGHLIGHTS ===== */
.row-urgente td { background: var(--warning-light) !important; }
.row-critique td { background: var(--danger-light) !important; }
.row-urgente:hover td { background: #fde68a !important; }
.row-critique:hover td { background: #fecaca !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .navbar { padding: 0 1rem; }
  .navbar h1 { font-size: 1rem; }
  .container, .container-wide { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .admin-header { flex-direction: column; align-items: flex-start; }
  .data-table { font-size: .8rem; }
  .data-table th, .data-table td { padding: .5rem; }
}

/* ===== PRINT ===== */
@media print {
  .navbar, .form-actions, .filters, .actions, .toast-container { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid var(--gray-300); }
}
