/* ============ RESET & BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --sidebar-w: 260px;
  --header-h: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.25);
  --transition: 0.2s ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ============ LOGIN ============ */
#loginScreen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1e3a8a 0%, #0f172a 45%, #020617 100%);
  z-index: 1000;
}

#loginScreen::before {
  content: ''; position: absolute; inset: 0;
  background-image: 
    linear-gradient(rgba(59,130,246,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.06) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 70%);
}

.login-box {
  position: relative;
  width: 100%; max-width: 420px;
  background: rgba(30, 41, 59, 0.7);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(59,130,246,0.1);
}

.login-logo {
  display: flex; align-items: center; gap: 12px;
  justify-content: center; margin-bottom: 8px;
}

.login-logo i {
  font-size: 32px; color: var(--accent);
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.login-logo h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.login-logo span { color: var(--accent); }

.login-subtitle {
  text-align: center; color: var(--text-secondary);
  margin-bottom: 32px; font-size: 13px;
}

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

.input-wrapper { position: relative; }
.input-wrapper i {
  position: absolute; left: 14px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted);
  font-size: 14px; pointer-events: none;
}

.form-group input, .form-group select {
  width: 100%; padding: 12px 14px 12px 42px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px; outline: none;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  transition: var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.login-footer {
  text-align: center; margin-top: 24px;
  color: var(--text-muted); font-size: 12px;
}

/* ============ APP SHELL ============ */
#app { display: none; height: 100vh; }
#app.active { display: flex; }

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header i {
  font-size: 22px; color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.sidebar-header h2 {
  font-size: 17px; font-weight: 800; letter-spacing: -0.3px;
}
.sidebar-header span { color: var(--accent); }

.sidebar-nav {
  flex: 1; padding: 16px 12px; overflow-y: auto;
}

.nav-section-title {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 12px 12px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 500;
  cursor: pointer; transition: var(--transition);
  margin-bottom: 2px; position: relative;
}

.nav-item:hover {
  background: var(--bg-hover); color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(59,130,246,0.15), transparent);
  color: var(--accent);
}

.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 20%; height: 60%;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}

.nav-item i { width: 18px; text-align: center; font-size: 15px; }

.nav-badge {
  margin-left: auto; background: var(--accent);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 10px;
}

.sidebar-footer {
  padding: 12px; border-top: 1px solid var(--border);
}

.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
}

.user-card:hover { background: var(--bg-hover); }

.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: white;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-info .role { font-size: 11px; color: var(--text-muted); }

/* ============ MAIN ============ */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}

/* ============ TOPBAR ============ */
.topbar {
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
  z-index: 50;
}

.menu-toggle {
  display: none; font-size: 20px; color: var(--text-secondary);
  padding: 8px;
}

.page-title { font-size: 16px; font-weight: 700; }

.topbar-search {
  flex: 1; max-width: 380px; margin-left: 16px;
  position: relative;
}

.topbar-search i {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted); font-size: 13px;
}

.topbar-search input {
  width: 100%; padding: 9px 12px 9px 36px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 13px;
  outline: none; transition: var(--transition);
}

.topbar-search input:focus { border-color: var(--accent); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: 15px;
  transition: var(--transition); position: relative;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.icon-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; background: var(--danger);
  border-radius: 50%; border: 2px solid var(--bg-secondary);
}

.status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: rgba(16,185,129,0.1);
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 20px; font-size: 12px; font-weight: 600;
  color: var(--success);
}

.status-pill .pulse {
  width: 7px; height: 7px; background: var(--success);
  border-radius: 50%; animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

/* ============ CONTENT ============ */
.content {
  flex: 1; overflow: hidden; position: relative;
}

.view {
  display: none; height: 100%; overflow-y: auto;
}
.view.active { display: block; }
.view.map-view { overflow: hidden; }

/* ============ MAP LAYOUT ============ */
.map-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

.device-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 16px; border-bottom: 1px solid var(--border);
}

.panel-header h3 {
  font-size: 14px; font-weight: 700; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}

.panel-header h3 .count {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-primary); padding: 3px 8px; border-radius: 10px;
}

.filter-tabs {
  display: flex; gap: 4px; background: var(--bg-primary);
  padding: 4px; border-radius: var(--radius-sm);
}

.filter-tabs button {
  flex: 1; padding: 6px 8px; font-size: 11px; font-weight: 600;
  border-radius: 6px; color: var(--text-muted); transition: var(--transition);
}

.filter-tabs button.active {
  background: var(--bg-tertiary); color: var(--text-primary);
}

.device-list { flex: 1; overflow-y: auto; padding: 8px; }

.device-card {
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg-primary); margin-bottom: 8px;
  cursor: pointer; transition: var(--transition);
  border: 1px solid transparent; position: relative;
}

.device-card:hover {
  border-color: var(--border); transform: translateX(2px);
}

.device-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 12px var(--accent-glow);
}

.device-card-top {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}

.device-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}

.device-icon.moving { background: rgba(16,185,129,0.15); color: var(--success); }
.device-icon.idle { background: rgba(245,158,11,0.15); color: var(--warning); }
.device-icon.offline { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.device-icon.alert { background: rgba(239,68,68,0.15); color: var(--danger); }

.device-meta { flex: 1; min-width: 0; }
.device-name {
  font-size: 13px; font-weight: 600; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-sub { font-size: 11px; color: var(--text-muted); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.moving { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.idle { background: var(--warning); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.alert { background: var(--danger); animation: pulse 1.2s infinite; }

.device-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 8px; padding-top: 8px; border-top: 1px solid var(--border);
}

.device-stat { text-align: center; }
.device-stat .val { font-size: 12px; font-weight: 700; }
.device-stat .lbl { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ============ MAPA ============ */
.map-container { position: relative; }

#map { width: 100%; height: 100%; background: var(--bg-primary); }

.leaflet-container { background: #0f172a; font-family: inherit; }

/* Leaflet dark theme adjustments */
.leaflet-tile { filter: brightness(0.85) contrast(1.05) saturate(0.9); }
.leaflet-control-zoom {
  border: none !important; box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  width: 34px !important; height: 34px !important;
  line-height: 34px !important; font-size: 16px !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-hover) !important; }
.leaflet-control-attribution {
  background: rgba(15,23,42,0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

.map-overlay-top {
  position: absolute; top: 16px; left: 16px; right: 16px;
  display: flex; justify-content: space-between;
  align-items: flex-start; pointer-events: none; z-index: 400;
}

.map-overlay-top > * { pointer-events: auto; }

.map-stats {
  display: flex; gap: 8px;
}

.stat-chip {
  background: rgba(30,41,59,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
}

.stat-chip i { font-size: 13px; }
.stat-chip .num { font-size: 15px; font-weight: 700; }
.stat-chip .txt { font-size: 11px; color: var(--text-muted); }

.map-tools {
  display: flex; gap: 6px;
}

.tool-btn {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: rgba(30,41,59,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition); box-shadow: var(--shadow);
}

.tool-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tool-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.map-overlay-bottom {
  position: absolute; bottom: 16px; left: 16px; right: 16px;
  display: flex; justify-content: space-between;
  align-items: flex-end; pointer-events: none; z-index: 400;
}

.map-overlay-bottom > * { pointer-events: auto; }

.legend {
  background: rgba(30,41,59,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px; box-shadow: var(--shadow);
  display: flex; gap: 16px;
}

.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-secondary);
}

.legend-item .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ============ DETAIL PANEL ============ */
.detail-panel {
  position: absolute; top: 70px; right: 16px;
  width: 300px;
  background: rgba(30,41,59,0.96);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 450; overflow: hidden;
  transform: translateX(calc(100% + 24px));
  transition: transform 0.3s ease;
  max-height: calc(100% - 100px);
  display: flex; flex-direction: column;
}

.detail-panel.open { transform: translateX(0); }

.detail-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

.detail-header .close-btn {
  margin-left: auto; color: var(--text-muted);
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.detail-header .close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.detail-body { padding: 16px; overflow-y: auto; }

.detail-row {
  display: flex; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid rgba(51,65,85,0.5);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--text-muted); }
.detail-row .v { font-weight: 600; text-align: right; }

.detail-actions {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 16px;
}

.btn-secondary {
  padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--bg-primary); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 12px; font-weight: 600;
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger-soft {
  padding: 9px 12px; border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger); font-size: 12px; font-weight: 600;
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-danger-soft:hover { background: rgba(239,68,68,0.2); }

/* ============ DASHBOARD VIEW ============ */
.dashboard { padding: 24px; }

.section-title {
  font-size: 15px; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: var(--transition);
  position: relative; overflow: hidden;
}

.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.stat-card::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 80px; height: 80px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  transform: translate(30%, -30%); opacity: 0.5;
}

.stat-card .icon {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; margin-bottom: 12px;
}

.stat-card .value { font-size: 28px; font-weight: 800; margin-bottom: 4px; letter-spacing: -1px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-card .trend {
  font-size: 11px; font-weight: 600; margin-top: 8px;
  display: flex; align-items: center; gap: 4px;
}
.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

.icon.blue { background: rgba(59,130,246,0.15); color: var(--accent); }
.icon.green { background: rgba(16,185,129,0.15); color: var(--success); }
.icon.orange { background: rgba(245,158,11,0.15); color: var(--warning); }
.icon.purple { background: rgba(139,92,246,0.15); color: var(--purple); }

.dashboard-grid {
  display: grid; grid-template-columns: 2fr 1fr; gap: 16px;
}

@media (max-width: 1024px) { .dashboard-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.card-header h4 { font-size: 14px; font-weight: 700; }

.activity-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid rgba(51,65,85,0.5);
}
.activity-item:last-child { border-bottom: none; }

.activity-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
}

.activity-body { flex: 1; min-width: 0; }
.activity-body .t { font-size: 13px; font-weight: 500; }
.activity-body .s { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.activity-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ============ TABLE VIEW ============ */
.table-view { padding: 24px; }

.table-toolbar {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 16px; gap: 12px;
  flex-wrap: wrap;
}

.table-toolbar .left { display: flex; gap: 8px; align-items: center; }

.btn {
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  transition: var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
}

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

.btn-ghost {
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.search-input {
  position: relative;
}
.search-input i {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted); font-size: 13px;
}
.search-input input {
  padding: 9px 12px 9px 36px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 13px;
  outline: none; width: 260px; transition: var(--transition);
}
.search-input input:focus { border-color: var(--accent); }

.data-table {
  width: 100%; background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--bg-primary);
}

.data-table th {
  padding: 12px 16px; text-align: left;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 14px 16px; font-size: 13px;
  border-bottom: 1px solid rgba(51,65,85,0.5);
}

.data-table tbody tr { transition: var(--transition); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}

.badge.green { background: rgba(16,185,129,0.15); color: var(--success); }
.badge.orange { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge.red { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge.gray { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.badge.blue { background: rgba(59,130,246,0.15); color: var(--accent); }

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============ HISTORY VIEW ============ */
.history-view { padding: 24px; }

.history-filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}

.history-filters .form-group { margin: 0; }
.history-filters label {
  display: block; margin-bottom: 6px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.history-filters input, .history-filters select {
  width: 100%; padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 13px; outline: none;
}
.history-filters input:focus, .history-filters select:focus { border-color: var(--accent); }

.timeline { position: relative; padding-left: 32px; }
.timeline::before {
  content: ''; position: absolute; left: 11px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}

.timeline-item {
  position: relative; padding: 12px 0 12px 4px;
  border-bottom: 1px solid rgba(51,65,85,0.4);
}
.timeline-item:last-child { border-bottom: none; }

.timeline-item::before {
  content: ''; position: absolute; left: -26px; top: 18px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-secondary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

.timeline-item .head {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 4px;
}
.timeline-item .head .title { font-size: 13px; font-weight: 600; }
.timeline-item .head .time { font-size: 11px; color: var(--text-muted); }
.timeline-item .body { font-size: 12px; color: var(--text-secondary); }

/* ============ USERS VIEW ============ */
.users-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.user-card-lg {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.user-card-lg:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.user-card-lg .top {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
}

.user-avatar-lg {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: white;
}

.user-card-lg .name { font-size: 15px; font-weight: 700; }
.user-card-lg .email { font-size: 12px; color: var(--text-muted); }

.user-card-lg .meta {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.user-card-lg .meta .item .lbl {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px;
}
.user-card-lg .meta .item .val { font-size: 13px; font-weight: 600; }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
  .menu-toggle { display: flex; }
  .map-layout { grid-template-columns: 1fr; }
  .device-panel {
    position: absolute; top: 0; left: 0; bottom: 0;
    width: 300px; z-index: 500;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .device-panel.open { transform: translateX(0); }
  .topbar-search { display: none; }
}

@media (max-width: 600px) {
  .detail-panel { width: calc(100% - 32px); right: 16px; }
  .map-stats { flex-wrap: wrap; }
  .stat-chip { padding: 6px 10px; }
  .stat-chip .num { font-size: 13px; }
  .stat-chip .txt { display: none; }
  .dashboard { padding: 16px; }
  .table-view, .history-view { padding: 16px; }
}

/* ============ ANIMATIONS ============ */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============ CUSTOM MARKER ============ */
.marker-wrap {
  position: relative; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}

.marker-dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 12px;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  position: relative; z-index: 2;
}

.marker-pulse {
  position: absolute; inset: 0;
  border-radius: 50%;
  animation: markerPulse 2s infinite;
}

@keyframes markerPulse {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}

.marker-dot.moving { background: #10b981; }
.marker-pulse.moving { background: rgba(16,185,129,0.4); }
.marker-dot.idle { background: #f59e0b; }
.marker-pulse.idle { background: rgba(245,158,11,0.4); }
.marker-dot.offline { background: #64748b; }
.marker-pulse.offline { background: rgba(100,116,139,0.3); animation: none; }
.marker-dot.alert { background: #ef4444; }
.marker-pulse.alert { background: rgba(239,68,68,0.5); }
