/* Transporte Control RD - Theme System */

/* ═══════════════════════════════════════════════
   DARK THEME (default)
   ═══════════════════════════════════════════════ */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1a2332;
  --bg-card: linear-gradient(145deg, #1e293b 0%, #1a2332 100%);
  --bg-card-hover: #1e293b;
  --bg-input: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-modal: #1a2332;
  --bg-header: rgba(15, 23, 42, 0.9);
  --bg-toast-success: #14532d;
  --bg-toast-error: #7f1d1d;
  --bg-toast-info: #1e3a5f;
  --bg-badge-green: #14532d;
  --bg-badge-yellow: #713f12;
  --bg-badge-red: #7f1d1d;
  --bg-badge-blue: #1e3a5f;
  --bg-badge-gray: #334155;
  --bg-thead: #1a2332;
  --bg-tooltip: #1e293b;

  --border-primary: #2d3a4f;
  --border-secondary: #334155;
  --border-hover: #3d4f6a;
  --border-sidebar: #1e293b;
  --border-header: #1e293b;
  --border-input: #334155;
  --border-toast-success: #22c55e;
  --border-toast-error: #ef4444;
  --border-toast-info: #3b82f6;
  --border-table: #2d3a4f;
  --border-tr: #1e293b;

  --text-primary: #f1f5f9;
  --text-secondary: #e2e8f0;
  --text-muted: #94a3b8;
  --text-muted-2: #64748b;
  --text-placeholder: #64748b;
  --text-sidebar: #94a3b8;
  --text-sidebar-hover: #e2e8f0;
  --text-sidebar-section: #475569;
  --text-link: #93c5fd;
  --text-badge-green: #86efac;
  --text-badge-yellow: #fde047;
  --text-badge-red: #fca5a5;
  --text-badge-blue: #93c5fd;
  --text-badge-gray: #cbd5e1;
  --text-toast-success: #86efac;
  --text-toast-error: #fca5a5;
  --text-toast-info: #93c5fd;
  --text-white: #ffffff;
  --text-black: #0f172a;

  --accent: #eab308;
  --accent-hover: #ca8a04;
  --accent-glow: rgba(234, 179, 8, 0.1);

  --btn-primary-bg: #eab308;
  --btn-primary-text: #0f172a;
  --btn-primary-hover: #ca8a04;
  --btn-secondary-bg: #334155;
  --btn-secondary-text: #e2e8f0;
  --btn-secondary-hover: #475569;
  --btn-danger-bg: #7f1d1d;
  --btn-danger-text: #fca5a5;
  --btn-danger-hover: #991b1b;
  --btn-success-bg: #14532d;
  --btn-success-text: #86efac;
  --btn-success-hover: #166534;

  --scrollbar-track: #1e293b;
  --scrollbar-thumb: #475569;
  --scrollbar-thumb-hover: #64748b;

  --shadow-card: 0 8px 25px rgba(0,0,0,0.3);
  --shadow-toast: 0 10px 40px rgba(0,0,0,0.5);
  --shadow-modal: rgba(0,0,0,0.7);

  --map-bg: #1a1f2e;
  --stat-icon-bg: rgba(255,255,255,0.1);
}

/* ═══════════════════════════════════════════════
   LIGHT THEME
   ═══════════════════════════════════════════════ */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-modal: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.95);
  --bg-toast-success: #f0fdf4;
  --bg-toast-error: #fef2f2;
  --bg-toast-info: #eff6ff;
  --bg-badge-green: #dcfce7;
  --bg-badge-yellow: #fef9c3;
  --bg-badge-red: #fee2e2;
  --bg-badge-blue: #dbeafe;
  --bg-badge-gray: #f1f5f9;
  --bg-thead: #f8fafc;
  --bg-tooltip: #ffffff;

  --border-primary: #e2e8f0;
  --border-secondary: #cbd5e1;
  --border-hover: #94a3b8;
  --border-sidebar: #e2e8f0;
  --border-header: #e2e8f0;
  --border-input: #cbd5e1;
  --border-toast-success: #22c55e;
  --border-toast-error: #ef4444;
  --border-toast-info: #3b82f6;
  --border-table: #e2e8f0;
  --border-tr: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #1e293b;
  --text-muted: #64748b;
  --text-muted-2: #94a3b8;
  --text-placeholder: #94a3b8;
  --text-sidebar: #64748b;
  --text-sidebar-hover: #0f172a;
  --text-sidebar-section: #94a3b8;
  --text-link: #2563eb;
  --text-badge-green: #166534;
  --text-badge-yellow: #854d0e;
  --text-badge-red: #991b1b;
  --text-badge-blue: #1e40af;
  --text-badge-gray: #475569;
  --text-toast-success: #166534;
  --text-toast-error: #991b1b;
  --text-toast-info: #1e40af;
  --text-white: #0f172a;
  --text-black: #ffffff;

  --accent: #eab308;
  --accent-hover: #ca8a04;
  --accent-glow: rgba(234, 179, 8, 0.15);

  --btn-primary-bg: #eab308;
  --btn-primary-text: #0f172a;
  --btn-primary-hover: #ca8a04;
  --btn-secondary-bg: #e2e8f0;
  --btn-secondary-text: #1e293b;
  --btn-secondary-hover: #cbd5e1;
  --btn-danger-bg: #fee2e2;
  --btn-danger-text: #991b1b;
  --btn-danger-hover: #fecaca;
  --btn-success-bg: #dcfce7;
  --btn-success-text: #166534;
  --btn-success-hover: #bbf7d0;

  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #cbd5e1;
  --scrollbar-thumb-hover: #94a3b8;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-toast: 0 10px 40px rgba(0,0,0,0.1);
  --shadow-modal: rgba(0,0,0,0.3);

  --map-bg: #e8edf2;
  --stat-icon-bg: rgba(0,0,0,0.05);
}

/* ═══════════════════════════════════════════════
   BASE STYLES
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Animations */
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.animate-slide-in { animation: slideIn 0.3s ease-out; }
.animate-slide-out { animation: slideOut 0.3s ease-in forwards; }
.animate-fade-in { animation: fadeIn 0.4s ease-out; }
.animate-pulse { animation: pulse 2s infinite; }
.animate-blink { animation: blink 1.5s infinite; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 16px;
  padding: 1.5rem;
  transition: all 0.2s;
}
.card:hover { border-color: var(--border-hover); }
.card-interactive { cursor: pointer; }
.card-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }

/* Stats cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 16px;
  padding: 1.25rem;
  transition: all 0.2s;
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 12px; border: none;
  font-size: 0.875rem; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); }
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn-danger { background: var(--btn-danger-bg); color: var(--btn-danger-text); }
.btn-danger:hover { background: var(--btn-danger-hover); }
.btn-success { background: var(--btn-success-bg); color: var(--btn-success-text); }
.btn-success:hover { background: var(--btn-success-hover); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; border-radius: 8px; }
.btn-lg { padding: 0.875rem 2rem; font-size: 1rem; border-radius: 14px; }

/* Theme Toggle Switch */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-secondary);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.25s;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}
.theme-toggle-icon {
  font-size: 14px;
}
.theme-toggle-label {
  white-space: nowrap;
}
[data-theme="light"] .theme-toggle-label::before { content: "Oscuro"; }
[data-theme="dark"] .theme-toggle-label::before { content: "Claro"; }
[data-theme="light"] .theme-toggle .fa-sun { color: #f59e0b; }

/* Forms */
.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.2s;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-input::placeholder { color: var(--text-placeholder); }
.form-label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.375rem; }
.form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.875rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25rem;
}

/* Tables */
.table-container { overflow-x: auto; border-radius: 16px; border: 1px solid var(--border-table); }
table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
thead { background: var(--bg-thead); }
th { padding: 0.75rem 1rem; text-align: left; font-weight: 600; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
td { padding: 0.75rem 1rem; color: var(--text-secondary); border-top: 1px solid var(--border-tr); }
tr:hover td { background: var(--bg-card-hover); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.2rem 0.625rem;
  border-radius: 100px;
  font-size: 0.6875rem; font-weight: 600;
}
.badge-green { background: var(--bg-badge-green); color: var(--text-badge-green); }
.badge-yellow { background: var(--bg-badge-yellow); color: var(--text-badge-yellow); }
.badge-red { background: var(--bg-badge-red); color: var(--text-badge-red); }
.badge-blue { background: var(--bg-badge-blue); color: var(--text-badge-blue); }
.badge-gray { background: var(--bg-badge-gray); color: var(--text-badge-gray); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--shadow-modal);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s;
  transform: translateZ(0);       /* fuerza capa GPU — evita que Leaflet tiles la pisen en Chrome */
  will-change: transform;         /* promociona a capa composited propia */
}
.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-primary);
  border-radius: 20px;
  width: 100%; max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fadeIn 0.3s ease-out;
  box-shadow: var(--shadow-card);
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-primary);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-primary);
  display: flex; justify-content: flex-end; gap: 0.75rem;
}
.modal-lg { max-width: 700px; }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  padding: 1rem 1.25rem;
  border-radius: 14px;
  font-size: 0.875rem; font-weight: 500;
  z-index: 10000;
  animation: slideIn 0.3s ease-out;
  max-width: 400px;
  box-shadow: var(--shadow-toast);
}
.toast-success { background: var(--bg-toast-success); border: 1px solid var(--border-toast-success); color: var(--text-toast-success); }
.toast-error { background: var(--bg-toast-error); border: 1px solid var(--border-toast-error); color: var(--text-toast-error); }
.toast-info { background: var(--bg-toast-info); border: 1px solid var(--border-toast-info); color: var(--text-toast-info); }

/* Sidebar */
.sidebar {
  width: 260px; height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-sidebar);
  position: sticky; top: 0; overflow-y: auto;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 1rem;
  margin: 0.125rem 0.5rem;
  border-radius: 10px;
  color: var(--text-sidebar);
  font-size: 0.8125rem; font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
}
.sidebar-link:hover { background: var(--bg-card-hover); color: var(--text-sidebar-hover); }
.sidebar-link.active { background: var(--accent); color: var(--text-black); font-weight: 600; }
.sidebar-section { padding: 0.375rem 1rem; font-size: 0.6875rem; font-weight: 700; color: var(--text-sidebar-section); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 1rem; }

/* Header */
.app-header {
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-header);
}

/* Map container */
.map-container {
  background: var(--map-bg);
  position: relative;
  z-index: 0;
}

@media (max-width: 768px) {
  .sidebar { position: fixed; left: -280px; top: 0; z-index: 50; transition: left 0.3s; }
  .sidebar.open { left: 0; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 49; display: none; }
  .sidebar-overlay.open { display: block; }
  .modal { max-width: 95vw; margin: 1rem; }
  .modal-lg { max-width: 95vw; }
  th, td { padding: 0.5rem 0.75rem; }
}

@media (max-width: 640px) {
  .card { padding: 1rem; }
  .stat-card { padding: 0.875rem; }
  th, td { font-size: 0.7rem; padding: 0.4rem 0.5rem; }
}

/* Print */
@media print {
  .sidebar, .no-print { display: none !important; }
  body { background: white; color: black; }
  .card, .stat-card { border: 1px solid #ddd; box-shadow: none; }
}

/* Tailwind dark mode overrides */
[data-theme="light"] .bg-gray-950 { background: var(--bg-primary) !important; }
[data-theme="light"] .text-gray-100 { color: var(--text-primary) !important; }
[data-theme="light"] .bg-gray-950\/90 { background: var(--bg-header) !important; }
[data-theme="light"] .text-white { color: #0f172a !important; }
[data-theme="light"] .text-gray-500 { color: #64748b !important; }
[data-theme="light"] .text-gray-400 { color: #475569 !important; }
[data-theme="light"] .text-gray-300 { color: #334155 !important; }
[data-theme="light"] .text-gray-600 { color: #94a3b8 !important; }
[data-theme="light"] .border-gray-800 { border-color: var(--border-primary) !important; }
[data-theme="light"] .border-gray-700 { border-color: var(--border-secondary) !important; }
[data-theme="light"] .border-gray-700\/50 { border-color: rgba(203, 213, 225, 0.5) !important; }
[data-theme="light"] .bg-gray-800 { background: var(--bg-card-hover) !important; }
[data-theme="light"] .bg-gray-800\/50 { background: rgba(241, 245, 249, 0.5) !important; }
[data-theme="light"] .bg-gray-800\/70 { background: rgba(241, 245, 249, 0.7) !important; }
[data-theme="light"] .bg-gray-800\/90 { background: rgba(241, 245, 249, 0.9) !important; }
[data-theme="light"] .bg-gray-900 { background: #e2e8f0 !important; }
[data-theme="light"] .bg-gray-700 { background: #cbd5e1 !important; color: #334155 !important; }
[data-theme="light"] .hover\:bg-gray-800\/50:hover { background: rgba(241, 245, 249, 0.5) !important; }
[data-theme="light"] .text-gray-900 { color: #0f172a !important; }
