/* ==========================================================================
   CHARTE GRAPHIQUE COMMUNE ET RESPONSIVE - ATNV (Optimisée multi-écrans)
   ========================================================================== */

:root {
  --primary: #1e293b;
  --primary-hover: #0f172a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #059669;
  --success-hover: #047857;
  --warning: #f59e0b;
  --danger: #dc2626;
  --bg-main: #f4f6f9;
  --bg-card: #ffffff;
  --text-main: #334155;
  --border-color: #cbd5e1;
}

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

/* Gestion du viewport */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-main);
}

/* Body réinitialisé sans marges/padding externes pour coller aux bords */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main) !important;
  color: var(--text-main);
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.5;
}

/* --- CONTENEUR PRINCIPAL --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--bg-card);
  padding: clamp(15px, 3vw, 30px);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  position: relative;
  z-index: 1; /* Reste sous la sidebar mobile */
}

/* Page de connexion centrée */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  padding: clamp(20px, 4vw, 30px);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* --- TYPOGRAPHIE RESPONSIVE --- */
h1, h2, h3 {
  color: var(--primary);
  margin-bottom: 15px;
  font-weight: 700;
}

h1 {
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  text-align: center;
  text-transform: uppercase;
}

h2 {
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  border-bottom: 2px solid var(--bg-main);
  padding-bottom: 6px;
  margin-top: 20px;
}

/* --- FORMULAIRES ET INPUTS --- */
.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 44px; /* Zone tactile optimale sur smartphone */
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1rem;
  background-color: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Inputs en lecture seule ou calculés */
input[readonly] {
  background-color: #f1f5f9;
  color: #64748b;
}

input.has-missing {
  background-color: #fef2f2;
  color: var(--danger);
  font-weight: bold;
}

/* --- BOUTONS --- */
.btn, button, input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px; /* Taille optimale pour le clic tactile */
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s, transform 0.1s;
  touch-action: manipulation;
}

.btn:active, button:active {
  transform: scale(0.98);
}

.btn-primary, button[type="submit"] { background-color: var(--accent); color: white; }
.btn-primary:hover, button[type="submit"]:hover { background-color: var(--accent-hover); }

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

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

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

.btn-secondary { background-color: #e2e8f0; color: #334155; }
.btn-secondary:hover { background-color: #cbd5e1; }

.btn-full { width: 100%; }

/* --- DISPOSITION GRILLE --- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 15px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* --- TABLEAUX --- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 15px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  position: relative;
  z-index: 1; /* Force le tableau à rester sous le menu */
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

/* Application du fond sombre uniquement aux en-têtes réels de tableaux */
thead th {
  background-color: var(--primary);
  color: white;
  font-weight: 600;
  white-space: nowrap;
}

/* Correctif pour les cartes/fiches verticales de l'espace Patron */
tbody th {
  background-color: #f8fafc;
  color: var(--primary);
  font-weight: 600;
}

tr:hover { background-color: #f8fafc; }

table.mat-table input, table.ctrl-table input {
  padding: 6px;
  font-size: 0.85rem;
  min-height: 36px;
}

/* --- BADGES & PASTILLES --- */
.badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 700;
  white-space: nowrap;
}
.badge-ambu { background-color: #dbeafe; color: #1e40af; }
.badge-vsl { background-color: #fef3c7; color: #92400e; }

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-red { background-color: var(--danger); }
.dot-orange { background-color: var(--warning); }
.dot-green { background-color: var(--success); }

/* ==========================================================================
   MEDIA QUERIES (Règles spécifiques par appareil)
   ========================================================================== */

/* 1. SMARTPHONES (Moins de 576px) */
@media (max-width: 575.98px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .action-btns {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .action-btns .btn {
    width: 100%;
  }

  /* Transformation des tableaux en fiches pour petits écrans */
  .table-responsive-cards table, 
  .table-responsive-cards tbody, 
  .table-responsive-cards tr, 
  .table-responsive-cards td {
    display: block;
    width: 100%;
  }

  .table-responsive-cards thead {
    display: none;
  }

  .table-responsive-cards tr {
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
  }

  .table-responsive-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
    padding: 8px;
    text-align: right;
  }

  .table-responsive-cards td::before {
    content: attr(data-label);
    font-weight: bold;
    color: var(--primary);
    text-align: left;
    padding-right: 10px;
  }
}

/* 2. TABLETTES (Entre 576px et 1024px) */
@media (min-width: 576px) and (max-width: 1024px) {
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .action-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* 3. ORDINATEURS (1025px et plus) */
@media (min-width: 1025px) {
  .btn:hover {
    transform: translateY(-1px);
  }
}

/* ==========================================================================\n   MODE SOMBRE AUTOMATIQUE — ATNV\n   Visuel uniquement : aucune logique PHP/JS ou fonctionnalité modifiée.\n   Le thème suit automatiquement le réglage clair/sombre du système.\n   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --text-main: #e2e8f0;
    --primary: #e2e8f0;
    --border-color: #475569;
  }

  html, body {
    background-color: #0f172a !important;
    color: #e2e8f0 !important;
  }

  .container, .login-card {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    box-shadow: 0 4px 16px rgba(0,0,0,.35) !important;
  }

  h1, h2, h3 {
    color: #f8fafc !important;
  }

  h2 { border-bottom-color: #334155 !important; }

  label { color: #cbd5e1 !important; }

  input[type="text"], input[type="email"], input[type="password"],
  input[type="date"], input[type="time"], input[type="number"],
  select, textarea {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-color: #475569 !important;
  }

  input::placeholder, textarea::placeholder { color: #94a3b8 !important; }

  input[readonly] {
    background-color: #334155 !important;
    color: #cbd5e1 !important;
  }

  input.has-missing {
    background-color: #450a0a !important;
    color: #fecaca !important;
  }

  .btn-secondary {
    background-color: #334155 !important;
    color: #f1f5f9 !important;
    border-color: #475569 !important;
  }
  .btn-secondary:hover { background-color: #475569 !important; }

  .table-wrapper { border-color: #475569 !important; }
  table { background-color: #1e293b !important; color: #e2e8f0 !important; }
  th, td { border-bottom-color: #334155 !important; }
  tbody th { background-color: #263449 !important; color: #f1f5f9 !important; }
  tr:hover { background-color: #263449 !important; }

  .badge-ambu { background-color: #1e3a5f !important; color: #bfdbfe !important; }
  .badge-vsl { background-color: #4a3410 !important; color: #fde68a !important; }

  a:not(.btn) { color: #93c5fd; }

  /* Styles inline présents dans certaines pages PHP */
  [style*="background: #fff"], [style*="background:#fff"],
  [style*="background: #ffffff"], [style*="background:#ffffff"],
  [style*="background-color: #fff"], [style*="background-color:#fff"],
  [style*="background-color: #ffffff"], [style*="background-color:#ffffff"] {
    background-color: #1e293b !important;
  }

  [style*="background: #f8fafc"], [style*="background-color: #f8fafc"],
  [style*="background: #f1f5f9"], [style*="background-color: #f1f5f9"],
  [style*="background: #e2e8f0"], [style*="background-color: #e2e8f0"] {
    background-color: #334155 !important;
  }

  [style*="border-color: #cbd5e1"], [style*="border: 1px solid #cbd5e1"] {
    border-color: #475569 !important;
  }

  [style*="color: #0f172a"], [style*="color:#0f172a"],
  [style*="color: #1e293b"], [style*="color:#1e293b"],
  [style*="color: #334155"], [style*="color:#334155"],
  [style*="color: #475569"], [style*="color:#475569"] {
    color: #e2e8f0 !important;
  }

  [style*="color: #64748b"], [style*="color:#64748b"] {
    color: #94a3b8 !important;
  }

  /* Alertes pastel : conserver leur sens visuel mais les assombrir */
  [style*="background: #fef3c7"], [style*="background-color: #fef3c7"],
  [style*="background: #fef2f2"], [style*="background-color: #fef2f2"],
  [style*="background: #fde8e8"], [style*="background-color: #fde8e8"],
  [style*="background: #e8f8f5"], [style*="background-color: #e8f8f5"],
  [style*="background: #dbeafe"], [style*="background-color: #dbeafe"] {
    filter: brightness(.72) saturate(.9);
  }
}

/* ==================================================================
   MODE SOMBRE — CORRECTION DES CARTES ET STYLES INLINE
   ================================================================== */
@media (prefers-color-scheme: dark) {
  .table-responsive-cards tr,
  .table-responsive-cards tbody tr {
    background: #1e293b !important;
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #475569 !important;
  }
  .table-responsive-cards td {
    background: transparent !important;
    color: #e2e8f0 !important;
    border-bottom-color: #334155 !important;
  }
  .table-responsive-cards td::before { color: #94a3b8 !important; }
  .table-responsive-cards strong { color: #f8fafc !important; }
  [style*="background: white"], [style*="background:white"],
  [style*="background: #fff"], [style*="background:#fff"],
  [style*="background: #ffffff"], [style*="background:#ffffff"],
  [style*="background-color: white"], [style*="background-color:white"],
  [style*="background-color: #fff"], [style*="background-color:#fff"],
  [style*="background-color: #ffffff"], [style*="background-color:#ffffff"] {
    background: #1e293b !important;
    background-color: #1e293b !important;
  }
}

/* ATNV V3 - FINAL DARK OVERRIDE FOR MOBILE VEHICLE CARDS */
@media (prefers-color-scheme: dark) {
  html, body { background-color:#0b1220 !important; color:#f1f5f9 !important; }
  .main-content.container { background-color:#0b1220 !important; color:#f1f5f9 !important; }
  .table-wrapper.table-responsive-cards { background:transparent !important; box-shadow:none !important; }
  .table-wrapper.table-responsive-cards table { background:transparent !important; }
  .table-wrapper.table-responsive-cards tbody tr,
  .table-wrapper.table-responsive-cards tbody tr.type-ambu,
  .table-wrapper.table-responsive-cards tbody tr.type-vsl,
  .table-wrapper.table-responsive-cards tbody tr.in-progress {
    background:#172033 !important;
    background-color:#172033 !important;
    color:#f8fafc !important;
    border:1px solid #475569 !important;
    box-shadow:0 2px 10px rgba(0,0,0,.45) !important;
  }
  .table-wrapper.table-responsive-cards tbody td {
    background:transparent !important;
    background-color:transparent !important;
    color:#f1f5f9 !important;
    border-bottom:1px solid #334155 !important;
  }
  .table-wrapper.table-responsive-cards tbody td::before { color:#94a3b8 !important; }
  .table-wrapper.table-responsive-cards strong { color:#ffffff !important; }
  .fleet-toolbar { background:#172033 !important; border-color:#475569 !important; }
  .fleet-search, .fleet-filter { background:#0f172a !important; color:#f8fafc !important; border-color:#475569 !important; }
  .fleet-result-count { background:#0c4a6e !important; color:#bae6fd !important; border-color:#38bdf8 !important; }
}
