/* =========================================
   1. RESET GLOBAL Y VARIABLES
   ========================================= */
* {
    box-sizing: border-box; /* VITAL: Evita que los inputs se salgan de las cajas */
}

/* =========================================
   2. MOTOR DE REJILLA (PRIORIDAD ALTA)
   Esto arregla el formulario para que no se vea todo vertical
   ========================================= */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -5px;
    margin-left: -5px;
}

.g-2 > * {
    padding-right: 5px;
    padding-left: 5px;
    margin-bottom: 10px;
}

/* Definición de anchos para Escritorio (PC) */
@media (min-width: 768px) {
    .col-md-2 { flex: 0 0 auto; width: 16.666667%; }
    .col-md-3 { flex: 0 0 auto; width: 25%; }
    .col-md-4 { flex: 0 0 auto; width: 33.333333%; }
    .col-md-5 { flex: 0 0 auto; width: 41.666667%; }
    .col-md-6 { flex: 0 0 auto; width: 50%; }
    .col-md-7 { flex: 0 0 auto; width: 58.333333%; }
    .col-md-8 { flex: 0 0 auto; width: 66.666667%; }
    .col-md-12 { flex: 0 0 auto; width: 100%; }
    .col-6 { flex: 0 0 auto; width: 25%; } /* Botones condición */
}

/* Definición para Móviles */
@media (max-width: 767px) {
    .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8 {
        width: 100% !important; /* En celular, todo ancho completo */
    }
    .col-6 { width: 50% !important; flex: 0 0 50%; } /* Botones de a 2 */
}

/* =========================================
   3. VARIABLES DE COLORES
   ========================================= */
:root {
    /* MODO CLARO (Día) */
    --bg-color: #f4f7f6;
    --text-color: #333333;
    --card-bg: rgba(255, 255, 255, 0.95);
    --input-bg: #ffffff;
    --border-color: #c9d6de;
    --title-color: #1a5b8a;
    --block-bg: rgba(239, 243, 246, 0.9);
    --nav-bg: transparent;
    --nav-text: #333333;
    --table-hover: rgba(0, 0, 0, 0.05);
}

/* MODO OSCURO (Noche) */
body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: rgba(30, 30, 30, 0.95);
    --input-bg: #2d2d2d;
    --border-color: #444444;
    --title-color: #90caf9;
    --block-bg: rgba(255, 255, 255, 0.05);
    --nav-bg: transparent;
    --nav-text: #e0e0e0;
    --table-hover: rgba(255, 255, 255, 0.1);
}

/* =========================================
   4. CONFIGURACIÓN DEL FONDO
   ========================================= */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    position: relative; 
    z-index: 1;
    transition: background-color 0.3s, color 0.3s;
}

body::before {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1; 
    background-image: url('Logo.png'); 
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 40%; 
    opacity: 0.15; 
    pointer-events: none;
}

/* =========================================
   5. CONTENEDORES (DISEÑO PLANO)
   ========================================= */
.container, .card, fieldset, .search-panel, .modal-content, .card-seccion {
    background-color: var(--card-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--border-color) !important;
    border-radius: 8px;
    box-shadow: none !important; /* Sin sombra */
    border: 1px solid var(--border-color);
}

.container {
    padding: 30px;
    max-width: 1200px;
    width: 100%;
}

/* =========================================
   6. HEADER
   ========================================= */
.header-controls, .top-bar {
    background-color: var(--nav-bg) !important;
    color: var(--nav-text) !important;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; 
    gap: 15px;
}

.user-info, .user-welcome {
    color: var(--nav-text) !important; 
    font-weight: bold;
    display: flex; align-items: center; gap: 8px;
}

h1, h2 { color: var(--title-color); text-align: center; margin-bottom: 20px; border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }
legend { font-size: 1.2em; font-weight: bold; color: var(--title-color); padding: 0 10px; }
label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: bold; }

/* =========================================
   7. INPUTS
   ========================================= */
fieldset { border: 1px solid var(--border-color); padding: 20px; margin-bottom: 20px; }

input, select, textarea, .form-control {
    width: 100%; padding: 10px; margin-bottom: 10px;
    border: 1px solid var(--border-color); border-radius: 4px;
    background-color: var(--input-bg) !important; color: var(--text-color) !important;
    font-size: 16px;
}

/* Ajustes para diseño compacto */
.form-label { font-size: 0.75rem !important; margin-bottom: 2px !important; color: #666; font-weight: 700; text-transform: uppercase; }
.form-control-sm, .form-select-sm { padding: 6px 10px !important; font-size: 0.9rem !important; height: 34px !important; }

.grid-2-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: end; }
.checkbox-group { display: flex; gap: 20px; margin-bottom: 15px; flex-wrap: wrap; }
.checkbox-group input[type="checkbox"] { width: auto; margin-right: 5px; }

/* =========================================
   8. BOTONES
   ========================================= */
button, .btn, .btn-link, .logout-btn {
    display: inline-flex !important; align-items: center; justify-content: center;
    height: 42px !important; padding: 0 18px !important; margin: 0 !important;
    border: none; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: bold;
    text-decoration: none; color: white !important; transition: background 0.2s;
}
.btn-blue, button { background-color: #1a5b8a; }
.btn-red, .logout-btn { background-color: #dc3545; }
.btn-green { background-color: #198754; }
.btn-gray { background-color: #6c757d; }
.btn-orange { background-color: #fd7e14; }
.btn-add { background-color: transparent !important; border: 1px dashed var(--title-color) !important; color: var(--title-color) !important; width: 100%; }
button[type="submit"] { width: 100%; margin-top: 20px !important; height: auto !important; padding: 15px !important; background-color: #28a745; font-size: 1.1em; }

/* =========================================
   9. INTERRUPTOR MODO OSCURO (ORIGINAL RESTAURADO)
   ========================================= */
.theme-switch {
  --toggle-size: 12px;
  --container-width: 5.625em;
  --container-height: 2.5em;
  --container-radius: 6.25em;
  --container-light-bg: #3D7EAE;
  --container-night-bg: #1D1F2C;
  --circle-container-diameter: 3.375em;
  --sun-moon-diameter: 2.125em;
  --sun-bg: #ECCA2F;
  --moon-bg: #C4C9D1;
  --spot-color: #959DB1;
  --circle-container-offset: calc((var(--circle-container-diameter) - var(--container-height)) / 2 * -1);
  --stars-color: #fff;
  --clouds-color: #F3FDFF;
  --back-clouds-color: #AACADF;
  --transition: .5s cubic-bezier(0, -0.02, 0.4, 1.25);
  --circle-transition: .3s cubic-bezier(0, -0.02, 0.35, 1.17);
  display: inline-block;
  vertical-align: middle;
  cursor: pointer;
  margin-right: 10px;
}

.theme-switch, .theme-switch *, .theme-switch *::before, .theme-switch *::after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-size: var(--toggle-size);
}

.theme-switch__container {
  width: var(--container-width);
  height: var(--container-height);
  background-color: var(--container-light-bg);
  border-radius: var(--container-radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0em -0.062em 0.062em rgba(0, 0, 0, 0.25), 0em 0.062em 0.125em rgba(255, 255, 255, 0.94);
  transition: var(--transition);
  position: relative;
}

.theme-switch__container::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  box-shadow: 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset, 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset;
  border-radius: var(--container-radius)
}

.theme-switch__checkbox { display: none; }

.theme-switch__circle-container {
  width: var(--circle-container-diameter);
  height: var(--circle-container-diameter);
  background-color: rgba(255, 255, 255, 0.1);
  position: absolute;
  left: var(--circle-container-offset);
  top: var(--circle-container-offset);
  border-radius: var(--container-radius);
  box-shadow: inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), 0 0 0 0.625em rgba(255, 255, 255, 0.1), 0 0 0 1.25em rgba(255, 255, 255, 0.1);
  display: flex;
  transition: var(--circle-transition);
  pointer-events: none;
}

.theme-switch__sun-moon-container {
  pointer-events: auto;
  position: relative;
  z-index: 2;
  width: var(--sun-moon-diameter);
  height: var(--sun-moon-diameter);
  margin: auto;
  border-radius: var(--container-radius);
  background-color: var(--sun-bg);
  box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #a1872a inset;
  filter: drop-shadow(0.062em 0.125em 0.125em rgba(0, 0, 0, 0.25)) drop-shadow(0em 0.062em 0.125em rgba(0, 0, 0, 0.25));
  overflow: hidden;
  transition: var(--transition);
}

.theme-switch__moon {
  transform: translateX(100%);
  width: 100%;
  height: 100%;
  background-color: var(--moon-bg);
  border-radius: inherit;
  box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #969696 inset;
  transition: var(--transition);
  position: relative;
}

.theme-switch__spot {
  position: absolute;
  top: 0.75em;
  left: 0.312em;
  width: 0.75em;
  height: 0.75em;
  border-radius: var(--container-radius);
  background-color: var(--spot-color);
  box-shadow: 0em 0.0312em 0.062em rgba(0, 0, 0, 0.25) inset;
}

.theme-switch__spot:nth-of-type(2) {
  width: 0.375em;
  height: 0.375em;
  top: 0.937em;
  left: 1.375em;
}

.theme-switch__spot:nth-last-of-type(3) {
  width: 0.25em;
  height: 0.25em;
  top: 0.312em;
  left: 0.812em;
}

.theme-switch__clouds {
  width: 1.25em;
  height: 1.25em;
  background-color: var(--clouds-color);
  border-radius: var(--container-radius);
  position: absolute;
  bottom: -0.625em;
  left: 0.312em;
  box-shadow: 0.937em 0.312em var(--clouds-color), -0.312em -0.312em var(--back-clouds-color), 1.437em 0.375em var(--clouds-color), 0.5em -0.125em var(--back-clouds-color), 2.187em 0 var(--clouds-color), 1.25em -0.062em var(--back-clouds-color), 2.937em 0.312em var(--clouds-color), 2em -0.312em var(--back-clouds-color), 3.625em -0.062em var(--clouds-color), 2.625em 0em var(--back-clouds-color), 4.5em -0.312em var(--clouds-color), 3.375em -0.437em var(--back-clouds-color), 4.625em -1.75em 0 0.437em var(--clouds-color), 4em -0.625em var(--back-clouds-color), 4.125em -2.125em 0 0.437em var(--back-clouds-color);
  transition: 0.5s cubic-bezier(0, -0.02, 0.4, 1.25);
}

.theme-switch__stars-container {
  position: absolute;
  color: var(--stars-color);
  top: -100%;
  left: 0.312em;
  width: 2.75em;
  height: auto;
  transition: var(--transition);
}

.theme-switch__checkbox:checked + .theme-switch__container {
  background-color: var(--container-night-bg);
}
.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__circle-container {
  left: calc(100% - var(--circle-container-offset) - var(--circle-container-diameter));
}
.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__circle-container:hover {
  left: calc(100% - var(--circle-container-offset) - var(--circle-container-diameter) - 0.187em)
}
.theme-switch__circle-container:hover {
  left: calc(var(--circle-container-offset) + 0.187em);
}
.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__moon {
  transform: translate(0);
}
.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__clouds {
  bottom: -4.062em;
}
.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__stars-container {
  top: 50%;
  transform: translateY(-50%);
}

/* =========================================
   10. CHECKBOX & ELEMENTOS EXTRA
   ========================================= */
/* IMPORTANTE: Renombrado de .container a .custom-checkbox para evitar conflictos con el layout */
.custom-checkbox input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; }
.custom-checkbox { display: inline-flex; align-items: center; gap: 10px; position: relative; cursor: pointer; font-size: 14px; user-select: none; margin-bottom: 10px; margin-right: 20px; }
.checkmark { position: relative; top: 0; left: 0; height: 1.8em; width: 1.8em; background-color: #e0e0e0; border-radius: 50%; transition: .4s; box-shadow: inset 3px 3px 6px #bebebe, inset -3px -3px 6px #ffffff; }
.custom-checkbox:hover .checkmark { box-shadow: inset 2px 2px 5px #bebebe, inset -2px -2px 5px #ffffff; }
body.dark-mode .checkmark { background-color: #2d2d2d; box-shadow: inset 3px 3px 6px #1a1a1a, inset -3px -3px 6px #404040; }
body.dark-mode .custom-checkbox:hover .checkmark { box-shadow: inset 2px 2px 5px #1a1a1a, inset -2px -2px 5px #404040; }
.custom-checkbox input:checked ~ .checkmark { box-shadow: none; background-color: limegreen; transform: rotateX(360deg); }
.checkmark:after { content: ""; position: absolute; display: none; }
.custom-checkbox input:checked ~ .checkmark:after { display: block; }
.custom-checkbox .checkmark:after { left: 0.7em; top: 0.45em; width: 0.35em; height: 0.7em; border: solid white; border-width: 0 0.15em 0.15em 0; box-shadow: 0.1em 0.1em 0em 0 rgba(0,0,0,0.3); transform: rotate(45deg); }
.checkbox-label-text { font-weight: 500; color: var(--text-color); }

/* WIZARD */
.wizard-progress { display: flex; justify-content: space-between; margin-bottom: 30px; position: relative; max-width: 600px; margin-left: auto; margin-right: auto; }
.wizard-progress::before { content: ''; position: absolute; top: 15px; left: 0; width: 100%; height: 4px; background: var(--border-color); z-index: 0; transform: translateY(-50%); }
.step-indicator { position: relative; z-index: 1; background: var(--card-bg); width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border-color); display: flex; align-items: center; justify-content: center; font-weight: bold; color: var(--text-color); transition: all 0.3s ease; }
.step-label { position: absolute; top: 40px; left: 50%; transform: translateX(-50%); font-size: 0.85em; font-weight: 600; color: var(--text-color); white-space: nowrap; opacity: 0.6; }
.step-indicator.active { border-color: var(--title-color); background-color: var(--title-color); color: white; transform: scale(1.1); box-shadow: 0 0 10px rgba(26, 91, 138, 0.4); }
.step-indicator.active .step-label { opacity: 1; color: var(--title-color); }
.step-indicator.completed { border-color: #28a745; background-color: #28a745; color: white; }
.wizard-step { display: none; animation: fadeIn 0.4s ease-in-out; }
.wizard-step.active { display: block; }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border-color); }
#btn_guardar { display: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ELEMENTOS DINÁMICOS */
.card-seccion-header { background-color: var(--block-bg); padding: 10px 15px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.btn-check-custom { display: none; }
.btn-check-label { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px; border: 2px solid var(--border-color); border-radius: 10px; background: var(--card-bg); color: var(--text-color); font-weight: 600; cursor: pointer; transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1); user-select: none; position: relative; overflow: hidden; opacity: 0.7; }
.btn-check-label:hover { background: var(--block-bg); border-color: var(--title-color); opacity: 1; transform: translateY(-2px); }
.btn-check-custom:checked + .btn-check-label { background-color: var(--title-color); color: white; border-color: var(--title-color); box-shadow: 0 4px 10px rgba(26, 91, 138, 0.4); transform: translateY(-2px); opacity: 1; }
.btn-check-custom[value="Fallecidos"]:checked + .btn-check-label { background-color: #dc3545; border-color: #dc3545; box-shadow: 0 4px 10px rgba(220, 53, 69, 0.4); }
.btn-check-custom[value="Lesionados"]:checked + .btn-check-label { background-color: #fd7e14; border-color: #fd7e14; box-shadow: 0 4px 10px rgba(253, 126, 20, 0.4); }
.eliminar-conductor, .eliminar-persona { background-color: #dc3545; position: absolute; top: 15px; right: 15px; padding: 5px 10px !important; height: auto !important; font-size: 0.8em; }
.v-foto-aprehendido { font-size: 0.8rem; }

/* MÓVILES */
@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 15px; }
    .header-controls, .top-bar { flex-direction: column; gap: 15px; }
    .header-controls div[style*="display: flex"] { justify-content: center; width: 100%; flex-direction: column; gap: 10px; }
    .grid-2-cols { grid-template-columns: 1fr; gap: 0; }
    button, .btn, .btn-link, .logout-btn { width: 100% !important; margin-bottom: 5px !important; }
    .custom-table { display: block; width: 100%; }
    .custom-table tr { display: block; margin-bottom: 20px; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; box-shadow: none; }
    .custom-table td { display: flex; justify-content: space-between; text-align: right; padding: 12px; border-bottom: 1px solid var(--border-color); }
    .eliminar-conductor, .eliminar-persona { position: relative; top: auto; right: auto; width: 100% !important; margin-top: 10px !important; }
}