/* --- CSS Custom Properties & Core Design System --- */
:root {
  --bg-primary: #0a0b0e;
  --bg-secondary: #12141c;
  --bg-card: rgba(22, 25, 35, 0.75);
  --bg-card-hover: rgba(28, 32, 45, 0.9);
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.3);
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.3);
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.3);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.15);
  
  --sidebar-width: 456px;
  --test-panel-width: 360px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.light-theme {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --border-color: rgba(0, 0, 0, 0.08);
  --border-highlight: rgba(0, 0, 0, 0.16);
  
  --accent-blue-glow: rgba(59, 130, 246, 0.15);
}

body.light-theme .custom-dialog-card,
body.light-theme .pac-container {
  background-color: #ffffff !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08) !important;
}

body.light-theme .custom-dialog-title {
  color: #0f172a !important;
}

body.light-theme .custom-dialog-message {
  color: #475569 !important;
}

body.light-theme .login-container,
body.light-theme .user-container {
  background: radial-gradient(circle at center, #f8fafc, #cbd5e1) !important;
}

body.light-theme .login-card,
body.light-theme .user-card {
  background-color: #ffffff !important;
  border-color: #cbd5e1 !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12) !important;
}

body.light-theme .login-header h2,
body.light-theme .user-header h2 {
  color: #0f172a !important;
}

body.light-theme .input-group label {
  color: #334155 !important;
  font-weight: 600;
}

body.light-theme .input-wrapper input {
  background-color: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #0f172a !important;
}

body.light-theme .input-wrapper input:focus {
  border-color: #3b82f6 !important;
  background-color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

body.light-theme .input-wrapper input::placeholder {
  color: #94a3b8 !important;
}

body.light-theme .input-wrapper i {
  color: #64748b !important;
}

body.light-theme .waypoint-item input,
body.light-theme .device-select {
  background-color: rgba(255, 255, 255, 0.9) !important;
  color: #0f172a !important;
}

/* Light Theme Dark Background for Delete / Clear Action Buttons */
body.light-theme .btn-remove-device-icon {
  background-color: #0f172a !important;
  border: 1px solid rgba(239, 68, 68, 0.7) !important;
  color: #f87171 !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .btn-remove-device-icon:hover {
  background-color: #ef4444 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
}

body.light-theme .btn-clear-route-icon {
  background-color: #0f172a !important;
  border: 1px solid rgba(245, 158, 11, 0.8) !important;
  color: #fbbf24 !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .btn-clear-route-icon:hover {
  background-color: #f59e0b !important;
  color: #ffffff !important;
  border-color: #d97706 !important;
}

body.light-theme .device-select option {
  background-color: #ffffff !important;
  color: #0f172a !important;
}

body.light-theme .device-select option:checked,
body.light-theme .device-select option:hover {
  background-color: #3b82f6 !important;
  color: #ffffff !important;
}

/* --- Base Reset --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* --- Layout --- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* --- Sidebar Style --- */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px;
  z-index: 10;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border-right: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden;
}

/* Stylized scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(59, 130, 246, 0.5);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.logo i {
  color: var(--accent-blue);
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px var(--accent-blue-glow));
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
}

.status-indicator.connected .dot {
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.status-indicator.disconnected .dot {
  background-color: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

.status-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-text {
  color: var(--text-secondary);
}

/* --- Card Styles (Glassmorphism) --- */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  transition: var(--transition-smooth);
}

.card:hover {
  border-color: var(--border-highlight);
  background: var(--bg-card-hover);
}

.card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.card h3 i {
  color: var(--accent-blue);
}

/* --- Input Groups --- */
.input-group {
  margin-bottom: 14px;
}

.input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper i {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.input-wrapper input {
  width: 100%;
  padding: 12px 14px 12px 38px;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition-smooth);
}

.input-wrapper input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px var(--accent-blue-glow);
  background-color: rgba(0, 0, 0, 0.4);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  outline: none;
  width: 100%;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--accent-blue);
  color: white;
}

.btn-primary:hover {
  background-color: #2563eb;
  box-shadow: 0 0 15px var(--accent-blue-glow);
  transform: translateY(-1px);
}

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

.btn-success:hover:not(:disabled) {
  background-color: #059669;
  box-shadow: 0 0 15px var(--accent-green-glow);
  transform: translateY(-1px);
}

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

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
  box-shadow: 0 0 15px var(--accent-red-glow);
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition-smooth);
}

.btn-icon:hover {
  color: var(--accent-red);
}

/* --- Devices List --- */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.panel-header h3 {
  margin-bottom: 0;
}

.devices-panel {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 250px;
}

.devices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Devices Toolbar (Search & Sort) */
.devices-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrapper i.fa-magnifying-glass {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.search-wrapper input {
  width: 100%;
  padding: 8px 30px 8px 32px !important;
  font-size: 0.8rem !important;
  background-color: rgba(0, 0, 0, 0.2) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.search-wrapper input:focus {
  border-color: var(--accent-blue);
  background-color: rgba(0, 0, 0, 0.3) !important;
}

.btn-clear-search {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: color 0.2s ease;
}

.btn-clear-search:hover {
  color: var(--accent-red);
}

.sort-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.sort-wrapper i.fa-arrow-down-short-wide {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 2;
}

.sort-wrapper select {
  width: 100%;
  padding: 7px 12px 7px 32px !important;
  font-size: 0.75rem !important;
  background-color: rgba(0, 0, 0, 0.2) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.sort-wrapper select:focus {
  border-color: var(--accent-blue);
}

/* Device Filter Notice Banner */
.device-filter-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  margin-bottom: 10px;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--accent-blue);
  animation: fadeIn 0.2s ease;
}

.btn-show-all {
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-show-all:hover {
  background: var(--accent-blue);
}

.empty-list {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 30px 0;
  border: 1px dashed rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
}

/* Device Item Card */
.device-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.device-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.15);
}

.device-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.device-item-id {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.device-item-tag {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 12px;
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.device-item-tag.simulated {
  background-color: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border-color: rgba(139, 92, 246, 0.2);
}

.device-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.device-badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.device-badge-status.normal {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.device-badge-status.deviated {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.2);
  animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* --- Map Container --- */
.map-container {
  flex-grow: 1;
  height: 100%;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* --- Floating Button --- */
.btn-floating {
  position: absolute;
  top: 100px;
  right: 20px;
  width: auto;
  z-index: 10;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 18px;
}

.btn-floating:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-blue);
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.25);
  transform: translateY(-2px);
}

/* --- Simulation Test Panel (Drawer Style) --- */
.test-panel {
  position: absolute;
  top: 160px;
  right: 20px;
  width: var(--test-panel-width);
  background: rgba(18, 20, 28, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.test-panel.hidden {
  opacity: 0;
  transform: translateY(-20px) scale(0.95);
  pointer-events: none;
}

.test-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
}

.test-panel-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.test-panel-header h3 i {
  color: var(--accent-green);
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-close:hover {
  color: var(--text-primary);
}

.test-panel-content {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.test-panel-content .description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-row .input-group input {
  width: 100%;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
}

.input-row .input-group input:focus {
  border-color: var(--accent-green);
}

/* Switch Toggle Button */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  user-select: none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
}

input:checked + .slider {
  background-color: var(--accent-green);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--accent-green);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

.device-disable-telegram-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
}

.device-disable-telegram-toggle:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.device-disable-telegram-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.switch.switch-sm {
  width: 32px;
  height: 18px;
}

.switch.switch-sm .slider:before {
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
}

.switch.switch-sm input:checked + .slider {
  background-color: #ef4444;
}

.switch.switch-sm input:checked + .slider:before {
  transform: translateX(14px);
}

.test-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 6px;
}

/* Simulated devices mini-panel */
.simulated-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.simulated-list-container h4 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.simulated-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.simulated-list::-webkit-scrollbar {
  width: 3px;
}

.simulated-list::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.05);
}

.simulated-device-item {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.simulated-device-name {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.simulated-device-actions {
  display: flex;
  gap: 6px;
}

.btn-pill-action {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.btn-pill-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-pill-action.deviated {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-pill-action.deviated:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Custom device select styles for better visualization */
.device-select {
  width: 100%;
  padding: 12px 38px 12px 38px;
  background-color: rgba(0, 0, 0, 0.3) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
}

.device-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px var(--accent-blue-glow);
}

.device-select option {
  background-color: #1a1e2e !important;
  color: #cbd5e1 !important;
  padding: 12px !important;
}

.device-select option:checked,
.device-select option:hover {
  background-color: #2563eb !important;
  color: #ffffff !important;
}

/* Google Places Autocomplete dropdown dark styles */
.pac-container {
  background-color: #12141c !important; /* Dark background */
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 10px !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6) !important;
  font-family: 'Inter', sans-serif !important;
  z-index: 999999 !important; /* Ensure it draws on top of panels */
  margin-top: 4px !important;
}

.pac-item {
  border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
  padding: 10px 14px !important;
  color: #9ca3af !important; /* --text-secondary */
  cursor: pointer !important;
  font-size: 0.85rem !important;
}

.pac-item:hover, .pac-item-selected {
  background-color: rgba(28, 32, 45, 0.9) !important; /* Hover card bg */
}

.pac-item-query {
  color: #f3f4f6 !important; /* --text-primary */
  font-size: 0.85rem !important;
}

.pac-matched {
  color: #3b82f6 !important; /* --accent-blue */
  font-weight: 600 !important;
}

.pac-icon {
  display: none !important; /* Hide generic icons for cleaner aesthetic */
}

/* Waypoint items styles */
.waypoint-item {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.waypoint-item input {
  flex-grow: 1;
  padding: 10px 12px 10px 34px !important; /* Margin for icon */
  background-color: rgba(0, 0, 0, 0.2) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.825rem;
  outline: none;
}

.waypoint-item input:focus {
  border-color: var(--accent-blue);
}

.btn-remove-waypoint {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 6px;
  transition: var(--transition-smooth);
}

.btn-remove-waypoint:hover {
  color: var(--accent-red);
}

/* Custom Dialog Overlay and Card Styles */
.custom-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100000000 !important; /* Above everything including Google Maps overlays */
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.2s ease;
}

.custom-dialog-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.custom-dialog-card {
  background-color: #12141c; /* matches --bg-secondary */
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
  animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.custom-dialog-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #f3f4f6;
  margin-bottom: 12px;
}

.custom-dialog-message {
  font-size: 0.9rem;
  color: #9ca3af;
  line-height: 1.5;
  margin-bottom: 24px;
}

.custom-dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.custom-dialog-buttons .btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  font-weight: 500;
  transition: var(--transition-smooth);
}

.custom-dialog-buttons .btn-primary {
  background-color: #3b82f6;
  color: #ffffff;
}

.custom-dialog-buttons .btn-primary:hover {
  background-color: #2563eb;
}

.custom-dialog-buttons .btn-secondary {
  background-color: rgba(255, 255, 255, 0.05);
  color: #9ca3af;
}

.custom-dialog-buttons .btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #f3f4f6;
}

.custom-dialog-buttons .hidden {
  display: none !important;
}

/* --- LOGIN & USER VIEWS --- */
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, #141722, #0d0f17);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20000;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  border-radius: 12px;
  padding: 32px 24px;
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 12px;
}

/* User Container (USR) */
.user-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, #141722, #0d0f17);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 15000;
  padding: 16px;
}

.user-card {
  width: 100%;
  max-width: 480px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  border-radius: 12px;
  padding: 24px;
}

.user-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 16px;
}

.user-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.user-role-badge {
  font-size: 0.7rem;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

/* Web Tracker Status */
.web-tracker-status.active {
  color: #10b981;
}
.web-tracker-status.active .status-dot {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}
.web-tracker-status.inactive {
  color: #ef4444;
}
.web-tracker-status.inactive .status-dot {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* User Items List for Admin */
.user-list-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition-smooth);
}

.user-list-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.user-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-item-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: #fff;
}

.user-item-details {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.user-item-role {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.user-item-role.adm {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.user-item-role.usr {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.user-actions {
  display: flex;
  gap: 6px;
}

.user-actions button {
  padding: 6px;
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

/* --- USR Operator Logout Styling --- */
#btn-user-logout {
  background: none !important;
  border: 1px solid rgba(239, 68, 68, 0.2) !important;
  color: #ef4444 !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  padding: 6px 12px !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  border-radius: var(--radius-sm) !important;
  transition: var(--transition-smooth) !important;
  align-self: center !important;
  width: auto !important;
}

#btn-user-logout:hover {
  background-color: rgba(239, 68, 68, 0.1) !important;
  border-color: #ef4444 !important;
  box-shadow: none !important;
}

/* --- Responsive Layout for Mobile/Tablet --- */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column !important;
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
    position: relative !important;
  }
  
  /* El botón circular flotante sobre el mapa se oculta en móviles; el botón de colapso está en el encabezado */
  .btn-toggle-sidebar {
    display: none !important;
  }

  .sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 62vh !important;
    max-height: 62dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-color) !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25) !important;
    z-index: 20 !important;
  }

  /* Encabezado SIEMPRE FIJO arriba en pantallas pequeñas */
  .sidebar-header {
    flex-shrink: 0 !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 30 !important;
    background: var(--bg-secondary) !important;
    padding: 10px 14px !important;
    margin-bottom: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
    min-height: 52px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  /* El contenido se desplaza debajo del encabezado fijo */
  #sidebar-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 12px 14px 16px 14px !important;
    max-height: calc(62vh - 52px) !important;
    max-height: calc(62dvh - 52px) !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* En móviles, al colapsar: el encabezado con título y botones QUEDA VISIBLE Y FIJO */
  .sidebar.collapsed {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 52px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
    border-right: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    overflow: hidden !important;
  }

  .sidebar.collapsed .sidebar-header {
    border-bottom: none !important;
    margin-bottom: 0 !important;
  }

  .sidebar.collapsed #sidebar-body {
    display: none !important;
  }
  
  .map-container {
    width: 100% !important;
    flex: 1 1 auto !important;
    height: calc(100vh - 52px) !important;
    height: calc(100dvh - 52px) !important;
    min-height: 200px !important;
    flex-grow: 1 !important;
    flex-shrink: 1 !important;
    position: relative !important;
  }

  #map {
    width: 100% !important;
    height: 100% !important;
  }
  
  .test-panel {
    width: 92% !important;
    right: 4% !important;
    left: 4% !important;
    bottom: 20px !important;
    top: auto !important;
    max-height: 80vh !important;
  }
}

@media (max-width: 440px) {
  .sidebar-header .logo {
    font-size: 1.05rem !important;
    gap: 6px !important;
  }
  .sidebar-header .logo span {
    font-size: 0.95rem !important;
  }
  .sidebar-header > div:last-child {
    gap: 5px !important;
  }
  .sidebar-header button {
    padding: 5px 8px !important;
    height: 30px !important;
    font-size: 0.8rem !important;
  }
}

/* --- PWA Install Widget Style (Mobile Floating Button) --- */
.pwa-install-widget {
  position: fixed;
  bottom: 24px;
  left: 16px;
  right: auto;
  z-index: 99999999;
  font-family: 'Inter', sans-serif;
  display: none; /* Hidden on desktop */
}

#btn-pwa-install {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pwa-btn-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 2;
}

.pwa-btn-text {
  background: var(--accent-blue);
  color: white;
  padding: 8px 18px 8px 24px;
  border-radius: 0 20px 20px 0;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.3);
  margin-left: -15px;
  margin-right: 0;
  position: relative;
  z-index: 1;
}

#btn-pwa-install:hover {
  transform: scale(1.06);
}

#btn-pwa-install:hover .pwa-btn-text,
#btn-pwa-install:hover .pwa-btn-icon {
  background: #2563eb;
}

/* Show only on small screens (mobile/tablet) */
@media (max-width: 768px) {
  .pwa-install-widget {
    display: block;
  }
}

/* Device Item Selected State */
.device-item.selected-active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.05);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Device Route Details in Sidebar Card */
.device-route-details {
  margin-top: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid var(--accent-blue);
  border-radius: 4px;
  font-size: 0.8rem;
  animation: fadeInDown 0.25s ease-out;
}

.device-route-details.empty {
  border-left-color: var(--text-muted);
  color: var(--text-muted);
  text-align: center;
  padding: 8px;
}

.route-details-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 4px;
}

.route-details-row {
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.route-details-row strong {
  color: var(--text-muted);
  flex-shrink: 0;
}

.route-details-row span {
  color: #fff;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-details-waypoints-container {
  margin-top: 6px;
  margin-bottom: 6px;
}

.route-details-waypoints-container strong {
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.route-details-waypoints {
  list-style: none;
  padding-left: 8px;
  margin: 0;
}

.route-details-waypoints li {
  margin-bottom: 3px;
  color: #fff;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.route-details-waypoints li i {
  font-size: 0.5rem;
  color: var(--accent-blue);
}

.route-details-no-waypoints {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.75rem;
  padding-left: 8px;
}

.route-details-row.route-distance {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 6px;
  margin-top: 6px;
}

.route-details-row.route-distance span {
  color: var(--accent-blue);
  font-weight: 600;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn-input-icon:hover:not(:disabled) {
  color: var(--accent-blue) !important;
  transform: translateY(-50%) scale(1.15) !important;
}

/* Highly Translucent Frosted Glass InfoWindow (Google Maps override) */
.gm-style .gm-style-iw-c,
.gm-style-iw-c {
  background-color: rgba(15, 23, 42, 0.42) !important;
  backdrop-filter: blur(12px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(12px) saturate(180%) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37) !important;
  padding: 10px 14px !important;
  border-radius: 12px !important;
  width: 280px !important;
  max-width: 290px !important;
  min-width: 250px !important;
  box-sizing: border-box !important;
}

.gm-style .gm-style-iw-d,
.gm-style-iw-d {
  overflow: hidden !important;
  max-width: 270px !important;
  max-height: 380px !important;
  box-sizing: border-box !important;
}

.gm-style .gm-style-iw-t::after,
.gm-style-iw-t::after {
  background: rgba(15, 23, 42, 0.38) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
  border-right: 1px solid rgba(255, 255, 255, 0.22) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.22) !important;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2) !important;
}

.gm-ui-hover-effect {
  top: 4px !important;
  right: 4px !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border-radius: 50% !important;
  width: 22px !important;
  height: 22px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
}

.gm-ui-hover-effect span {
  background-color: #e2e8f0 !important;
  margin: 0 !important;
}

.gm-ui-hover-effect:hover {
  background: rgba(239, 68, 68, 0.8) !important;
}

.gm-ui-hover-effect:hover span {
  background-color: #fff !important;
}

.map-infowindow {
  color: #f8fafc !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.8rem !important;
  line-height: 1.45 !important;
  text-align: left !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85) !important;
  pointer-events: auto !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
}

.map-infowindow * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
}

.map-infowindow-drag-header {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  font-size: 0.85rem !important;
  font-weight: 700 !important;
  color: #60a5fa !important;
  padding-bottom: 4px !important;
  margin-bottom: 6px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
  cursor: grab !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.map-infowindow-drag-header:active {
  cursor: grabbing !important;
}

.map-infowindow-drag-header i {
  opacity: 0.7 !important;
  font-size: 0.75rem !important;
}

.map-infowindow strong {
  color: #60a5fa !important; /* Brighter blue for high contrast on translucent background */
  font-weight: 600 !important;
}

.map-iw-val {
  color: #f1f5f9 !important;
}

.map-iw-muted {
  color: #94a3b8 !important;
}

.map-iw-trip-box {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  background: rgba(59, 130, 246, 0.18) !important;
  border: 1px solid rgba(59, 130, 246, 0.35) !important;
  border-radius: 4px !important;
  padding: 3px 6px !important;
  margin: 4px 0 6px 0 !important;
}

.map-iw-trip-num {
  color: #60a5fa !important;
  font-weight: 700 !important;
}

.map-iw-trip-time {
  font-size: 0.68rem !important;
  color: #94a3b8 !important;
}

.map-iw-route-section {
  margin-top: 6px !important;
  padding-top: 6px !important;
  border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.map-iw-route-header-title {
  color: #a78bfa !important;
  font-size: 0.75rem !important;
  font-weight: 700 !important;
}

/* Light Theme InfoWindow */
body.light-theme .map-infowindow {
  color: #0f172a !important;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.9) !important;
}

body.light-theme .map-infowindow-drag-header {
  color: #1d4ed8 !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .map-infowindow strong {
  color: #1d4ed8 !important;
}

body.light-theme .map-iw-val {
  color: #0f172a !important;
  font-weight: 500 !important;
}

body.light-theme .map-iw-muted {
  color: #475569 !important;
}

body.light-theme .map-iw-trip-box {
  background: rgba(37, 99, 235, 0.12) !important;
  border: 1px solid rgba(37, 99, 235, 0.25) !important;
}

body.light-theme .map-iw-trip-num {
  color: #1d4ed8 !important;
}

body.light-theme .map-iw-trip-time {
  color: #475569 !important;
}

body.light-theme .map-iw-route-section {
  border-top: 1px solid rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .map-iw-route-header-title {
  color: #6d28d9 !important;
}

body.light-theme .gm-style .gm-style-iw-c,
body.light-theme .gm-style-iw-c {
  background-color: rgba(255, 255, 255, 0.45) !important;
  backdrop-filter: blur(10px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(10px) saturate(180%) !important;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .gm-style .gm-style-iw-t::after,
body.light-theme .gm-style-iw-t::after {
  background: rgba(255, 255, 255, 0.45) !important;
  border-right: 1px solid rgba(0, 0, 0, 0.15) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .gm-ui-hover-effect span {
  background-color: #334155 !important;
}

/* Floating Draggable Device Card on Map */
.map-device-floating-card {
  position: absolute;
  top: 75px;
  right: 20px;
  z-index: 1000;
  width: 290px;
  max-width: calc(100vw - 40px);
  background-color: rgba(15, 23, 42, 0.45) !important;
  backdrop-filter: blur(14px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(14px) saturate(180%) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  box-shadow: 0 10px 32px 0 rgba(0, 0, 0, 0.4) !important;
  border-radius: 12px !important;
  padding: 12px 14px !important;
  color: #f8fafc !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.8rem !important;
  line-height: 1.45 !important;
  box-sizing: border-box !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
  touch-action: none;
}

.map-device-floating-card.hidden {
  display: none !important;
}

.map-device-floating-card * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
}

.map-card-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding-bottom: 6px !important;
  margin-bottom: 8px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
  cursor: grab !important;
}

.map-card-header:active {
  cursor: grabbing !important;
}

.map-card-title {
  display: flex !important;
  align-items: center !important;
  gap: 7px !important;
  font-size: 0.88rem !important;
  font-weight: 700 !important;
  color: #60a5fa !important;
}

.map-card-title i {
  opacity: 0.7 !important;
}

.map-card-close-btn {
  background: rgba(255, 255, 255, 0.1) !important;
  border: none !important;
  color: #cbd5e1 !important;
  border-radius: 50% !important;
  width: 22px !important;
  height: 22px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
}

.map-card-close-btn:hover {
  background: rgba(239, 68, 68, 0.8) !important;
  color: #fff !important;
}

/* Light Theme Floating Card */
body.light-theme .map-device-floating-card {
  background-color: rgba(255, 255, 255, 0.55) !important;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  box-shadow: 0 10px 32px 0 rgba(0, 0, 0, 0.18) !important;
  color: #0f172a !important;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8) !important;
}

body.light-theme .map-card-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
}

body.light-theme .map-card-title {
  color: #1d4ed8 !important;
}

body.light-theme .map-card-close-btn {
  background: rgba(0, 0, 0, 0.08) !important;
  color: #334155 !important;
}

body.light-theme .map-card-close-btn:hover {
  background: rgba(239, 68, 68, 0.9) !important;
  color: #fff !important;
}

/* Floating Banner for Map Selection Mode */
#map-selection-banner {
  position: absolute;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 20, 28, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--accent-blue);
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  animation: bannerFadeInDown 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#map-selection-banner.hidden {
  display: none !important;
}

#map-selection-banner i {
  color: var(--accent-blue);
  font-size: 1rem;
}

#map-selection-banner button {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  transition: all 0.2s ease;
}

#map-selection-banner button:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

@keyframes bannerFadeInDown {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Small Border-Only Remove Device Icon Button */
.btn-remove-device-icon {
  background: transparent !important;
  border: 1px solid rgba(239, 68, 68, 0.3) !important;
  color: #ef4444 !important;
  padding: 5px 8px !important;
  border-radius: var(--radius-sm) !important;
  cursor: pointer !important;
  font-size: 0.8rem !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
}

.btn-remove-device-icon:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: #ef4444 !important;
  transform: scale(1.05);
}

/* Small Border-Only Clear Route Icon Button */
.btn-clear-route-icon {
  background: transparent !important;
  border: 1px solid rgba(245, 158, 11, 0.4) !important;
  color: #f59e0b !important;
  padding: 5px 8px !important;
  border-radius: var(--radius-sm) !important;
  cursor: pointer !important;
  font-size: 0.8rem !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
}

.btn-clear-route-icon:hover {
  background: rgba(245, 158, 11, 0.15) !important;
  border-color: #f59e0b !important;
  transform: scale(1.05);
}

/* Sidebar Tab Buttons - Dynamic Theme Compatible */
.tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  border-bottom: 2px solid var(--accent-blue) !important;
  color: var(--text-primary) !important;
}

/* --- Settings Modal Styles --- */
.settings-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
  animation: modalFadeIn 0.25s ease forwards;
}

.settings-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
}

.settings-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-modal-title i {
  color: var(--accent-blue);
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: all 0.2s ease;
}

.btn-close-modal:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.settings-modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Status Card */
.settings-status-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.status-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.status-connected {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.status-badge.status-polling {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-badge.status-stopped {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-badge.status-error,
.status-badge.status-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.settings-status-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.settings-status-details div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-status-details strong {
  color: var(--text-primary);
}

.settings-status-error {
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid #ef4444;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: #ef4444;
}

.settings-live-controls {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.settings-live-controls button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Settings Form */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-form-row.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.settings-form-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 500px) {
  .settings-form-row-2col {
    grid-template-columns: 1fr;
  }
}

.settings-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.btn-pwd-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-pwd-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.test-result-box {
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  line-height: 1.4;
  animation: fadeIn 0.2s ease;
}

.test-result-box.success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #22c55e;
}

.test-result-box.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

.settings-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

/* --- Botón Circular Flotante para Ocultar / Mostrar Panel Lateral --- */
.btn-toggle-sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 1rem;
}

.btn-toggle-sidebar:hover {
  background: var(--bg-secondary);
  color: var(--accent-blue);
  transform: scale(1.08);
  border-color: var(--accent-blue);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35);
}

.btn-toggle-sidebar:active {
  transform: scale(0.95);
}

/* --- Pill Flotante de Sincronización Inicial --- */
.sync-status-pill {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2500;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 8px 18px;
  border-radius: 30px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

@media (max-width: 768px) {
  .sync-status-pill {
    position: fixed;
    top: 62px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    white-space: nowrap;
    max-width: 92vw;
    font-size: 0.78rem;
    padding: 7px 14px;
  }
}

.sync-status-pill.fade-out {
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
}

.sync-status-pill.hidden {
  display: none !important;
}

.sync-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(59, 130, 246, 0.3);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: sync-spin 0.8s linear infinite;
}

@keyframes sync-spin {
  to { transform: rotate(360deg); }
}

/* --- Collapsible Panels & History Module --- */
.btn-collapse {
  transition: transform 0.25s ease, color 0.2s ease, background-color 0.2s ease;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

.btn-collapse:hover {
  color: var(--accent-blue) !important;
  background-color: rgba(59, 130, 246, 0.12);
}

.devices-panel.collapsed,
.devices-panel:has(.panel-collapsible-body.hidden) {
  min-height: auto;
  flex-grow: 0;
}

.panel-collapsible-body {
  transition: max-height 0.3s ease, opacity 0.25s ease;
  overflow: visible;
}

.panel-collapsible-body.hidden {
  display: none !important;
}

/* History Search Form & Inputs */
.routes-history-card {
  transition: all 0.25s ease;
}

.date-input {
  background: var(--bg-input, rgba(15, 23, 42, 0.6));
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.date-input:focus {
  border-color: var(--accent-blue);
}

/* Active History Mode Banner */
.history-active-banner {
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.history-badge-active {
  font-size: 0.75rem;
  font-weight: 700;
  color: #60a5fa;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-exit-history {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #ef4444;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-exit-history:hover {
  background: rgba(239, 68, 68, 0.8);
  color: #fff;
}

.history-summary-box {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.history-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-summary-val {
  font-weight: 600;
  color: var(--text-primary);
}

/* Incidents List & Cards */
.history-incidents-list::-webkit-scrollbar {
  width: 4px;
}
.history-incidents-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.incident-card {
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 0.73rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.incident-card:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(239, 68, 68, 0.4);
  transform: translateY(-1px);
}

.incident-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.incident-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.incident-badge.deviated {
  background: rgba(239, 68, 68, 0.25);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.incident-badge.returned {
  background: rgba(16, 185, 129, 0.25);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.45);
}

.incident-badge.overspeed {
  background: rgba(245, 158, 11, 0.25);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.45);
}

.incident-badge.overspeed-high {
  background: #ff7a00;
  color: #ffffff;
  border: 1px solid #e66e00;
  box-shadow: 0 1px 3px rgba(255, 122, 0, 0.4);
}

.incident-badge.overspeed-high i {
  color: #ffffff !important;
}

.incident-time {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.incident-desc {
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.3;
}

.incident-meta {
  display: flex;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Light Theme overrides for History Module */
body.light-theme .date-input {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: #0f172a;
}

body.light-theme .history-active-banner {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.25);
}

body.light-theme .history-badge-active {
  color: #1d4ed8;
}

body.light-theme .history-summary-box {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

body.light-theme .incident-card {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

body.light-theme .incident-card:hover {
  background: #ffffff;
  border-color: rgba(239, 68, 68, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

