:root {
  --bg-primary: #0F172A;
  --bg-secondary: #1E293B;
  --bg-card: rgba(30, 41, 59, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --color-primary: #6366F1;
  --color-secondary: #06B6D4;
  --color-success: #10B981;
  --color-danger: #EF4444;
  --color-warning: #F59E0B;
  --font-sans: 'Inter', sans-serif;
  --font-display: 'Outfit', sans-serif;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --glass-effect: rgba(15, 23, 42, 0.35);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  width: 100vw;
}

/* Sidebar Styling */
.sidebar {
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  z-index: 1000;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.shield-icon {
  width: 36px;
  height: 36px;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.gradient-text {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 1px;
}

/* Sidebar Scrollable Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

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

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.4;
}

/* Connected Devices List */
.devices-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-placeholder {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 0.02);
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
}

.device-item:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.1);
}

.device-item.active-item {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.05));
  border-color: var(--color-primary);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 70%;
}

.device-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-last-seen {
  font-size: 11px;
  color: var(--text-secondary);
}

.device-status-indicator {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

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

.status-badge.online {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.offline {
  background-color: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

/* Battery Indicator styling inside list */
.battery-small {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.battery-small-icon {
  width: 14px;
  height: 8px;
  border: 1px solid var(--text-secondary);
  border-radius: 2px;
  padding: 1px;
  position: relative;
}

.battery-small-icon::after {
  content: '';
  position: absolute;
  right: -2px;
  top: 2px;
  width: 1px;
  height: 2px;
  background-color: var(--text-secondary);
  border-radius: 0 1px 1px 0;
}

.battery-small-level {
  height: 100%;
  border-radius: 1px;
}

.level-high { background-color: var(--color-success); }
.level-medium { background-color: var(--color-warning); }
.level-low { background-color: var(--color-danger); }

/* Detailed Card */
.device-details-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(10px);
  animation: slideIn 0.3s ease;
}

.hidden {
  display: none !important;
}

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

.device-meta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.detail-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

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

.info-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.info-value {
  font-size: 14px;
  font-weight: 600;
}

.battery-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.battery-shell {
  width: 32px;
  height: 16px;
  border: 1.5px solid var(--text-secondary);
  border-radius: 3px;
  padding: 1px;
  position: relative;
}

.battery-shell::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 4px;
  width: 2.5px;
  height: 5px;
  background-color: var(--text-secondary);
  border-radius: 0 1px 1px 0;
}

.battery-bar {
  height: 100%;
  border-radius: 1px;
  transition: width 0.3s ease;
}

/* Button UI */
.action-buttons {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-icon {
  width: 14px;
  height: 14px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), #4338CA);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.btn-secondary.active-toggle {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--color-secondary);
  color: var(--color-secondary);
}

.btn-small {
  padding: 6px 12px;
  font-size: 11px;
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  width: 100%;
}

.btn-small:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Geofence */
.geofence-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(10px);
}

.geofence-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.switch-label {
  font-size: 13px;
  font-weight: 500;
}

.switch-container input {
  display: none;
}

.slider {
  width: 36px;
  height: 20px;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  position: relative;
  transition: background-color 0.2s ease;
}

.slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch-container input:checked + .slider {
  background-color: var(--color-primary);
}

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

.geofence-inputs {
  animation: slideIn 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 11px;
  color: var(--text-secondary);
}

.input-group input {
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  color: white;
  font-size: 13px;
  outline: none;
}

.input-group input:focus {
  border-color: var(--color-primary);
}

.geofence-alert {
  margin-top: 12px;
  background-color: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--color-danger);
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  animation: pulse 2s infinite;
}

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

.alert-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.footer-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--color-success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--color-success);
}

.btn-refresh {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.btn-refresh:hover {
  color: white;
  background-color: rgba(255, 255, 255, 0.05);
}

.refresh-icon {
  width: 14px;
  height: 14px;
}

.refreshing {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Map Container Styling */
.map-container {
  height: 100vh;
  width: 100%;
}

#map {
  height: 100%;
  width: 100%;
  background-color: #1a1e2a;
}

/* Custom dark styling for Leaflet controls */
.leaflet-bar {
  box-shadow: var(--shadow-lg) !important;
  border: none !important;
}

.leaflet-bar a {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-color) !important;
  transition: background-color 0.2s ease;
}

.leaflet-bar a:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

.leaflet-bar a:first-child {
  border-top-left-radius: 8px !important;
  border-top-right-radius: 8px !important;
}

.leaflet-bar a:last-child {
  border-bottom-left-radius: 8px !important;
  border-bottom-right-radius: 8px !important;
  border-bottom: none !important;
}

/* Leaflet Popup styling */
.leaflet-popup-content-wrapper {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-tip {
  background-color: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
}

.map-popup-card {
  font-family: var(--font-sans);
  padding: 4px;
}

.map-popup-card h4 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.map-popup-card p {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.map-popup-card p strong {
  color: var(--text-primary);
}

/* Responsive adjustment */
@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  
  .sidebar {
    height: auto;
    max-height: 50vh;
  }
  
  .map-container {
    height: 50vh;
  }
}

/* Inline icon buttons */
.icon-btn-inline:hover {
  color: white !important;
  background-color: rgba(255, 255, 255, 0.1) !important;
  transform: scale(1.1);
}
.icon-btn-inline[title="Remover do Painel"]:hover {
  color: var(--color-danger) !important;
  background-color: rgba(239, 68, 68, 0.15) !important;
}

/* Color selector dots */
.color-dot-opt:hover {
  transform: scale(1.2);
}
.color-dot-opt.active {
  border-color: white !important;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

/* Pulsating Pin Keyframes & Class */
@keyframes mapPulse {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.5);
  }
  70% {
    transform: scale(1.15);
    box-shadow: 0 0 0 10px rgba(6, 182, 212, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(6, 182, 212, 0);
  }
}

.pulsating-pin-glow {
  animation: mapPulse 2s infinite ease-in-out;
}

/* Telemetry Sparklines CSS */
.chart-container svg {
  width: 100%;
}
.chart-line-battery {
  stroke: var(--color-success);
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(16, 185, 129, 0.3));
}
.chart-line-speed {
  stroke: var(--color-secondary);
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(6, 182, 212, 0.3));
}
.chart-fill-battery {
  fill: url(#battery-grad);
  opacity: 0.15;
}
.chart-fill-speed {
  fill: url(#speed-grad);
  opacity: 0.15;
}
.chart-grid-line {
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 1;
  stroke-dasharray: 2, 4;
}

/* Playback Slider Styling */
#playback-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-secondary);
  box-shadow: 0 0 6px var(--color-secondary);
  cursor: pointer;
  transition: transform 0.1s ease;
}
#playback-slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

/* Glassmorphism Refinements */
.sidebar, .device-details-card, .geofence-card {
  backdrop-filter: blur(14px) !important;
  -webkit-backdrop-filter: blur(14px) !important;
}

.device-item.active-item {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.08)) !important;
  border-color: var(--color-secondary) !important;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.15) 0%, transparent 80%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: opacity 0.3s ease;
}

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

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-card .input-group {
  margin-bottom: 20px;
  text-align: left;
}

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

.login-card .input-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.login-card .input-group input:focus {
  border-color: var(--color-primary);
}

.login-card .btn {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: var(--text-primary);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}

.login-card .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.login-error-msg {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--color-danger);
  color: #f87171;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  margin-bottom: 20px;
  text-align: left;
  line-height: 1.4;
}

.login-error-hidden {
  display: none;
}

