/* ── RESET & VARS ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0c0f;
  --surface: #111418;
  --surface2: #181c22;
  --border: #222831;
  --border2: #2d3540;
  --accent: #00e676;
  --accent2: #00b0ff;
  --danger: #ff4444;
  --warn: #ffaa00;
  --text: #e8ecf0;
  --text2: #8899aa;
  --text3: #556677;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'Inter', sans-serif;
  --sidebar-w: 300px;
  --header-h: 56px;
  --radius: 6px;
  --transition: 200ms ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── HEADER ──────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

.header-brand { display: flex; align-items: center; gap: 12px; }
.header-logo { display: flex; align-items: center; }
.header-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.05em;
  color: var(--text);
}
.accent-text { color: var(--accent); }

.header-status { margin-left: auto; }

.conn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border2);
  border-radius: 20px;
  background: var(--surface2);
}
.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text3);
  transition: background var(--transition);
}
.conn-indicator.connected .conn-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.conn-indicator.error .conn-dot { background: var(--danger); }
.conn-label { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }

.header-actions { display: flex; gap: 8px; }

.btn-icon {
  width: 36px; height: 36px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon--danger:hover { border-color: var(--danger) !important; color: var(--danger) !important; }

/* ── LAYOUT ──────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

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

.sidebar-heading {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text3);
  margin-bottom: 12px;
}

/* ── DEVICE LIST ─────────────────────────────────────────────── */
.device-list { display: flex; flex-direction: column; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--text3);
}
.empty-icon { font-size: 32px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.empty-state small { font-size: 11px; color: var(--text3); }

.device-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.device-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--device-color, var(--accent));
}
.device-card:hover, .device-card.active {
  border-color: var(--border2);
  background: #1e2530;
}
.device-card.active { border-color: var(--accent); }

.device-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.device-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.device-status {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.status-online { background: rgba(0,230,118,0.15); color: var(--accent); }
.status-offline { background: rgba(255,68,68,0.1); color: var(--danger); }

.device-imei {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text3);
  margin-bottom: 6px;
}

.device-meta {
  display: flex;
  gap: 12px;
}
.device-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.device-meta-label {
  font-size: 9px;
  color: var(--text3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.device-meta-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text2);
}

/* ── DEVICE DETAIL ───────────────────────────────────────────── */
.device-detail { display: flex; flex-direction: column; gap: 8px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-key { font-size: 11px; color: var(--text3); }
.detail-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text2);
  text-align: right;
}
.detail-val.good { color: var(--accent); }
.detail-val.warn { color: var(--warn); }

/* ── HISTORY ─────────────────────────────────────────────────── */
.history-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.history-stats {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
  min-height: 16px;
}

/* ── MAP CONTROLS ────────────────────────────────────────────── */
.map-controls { display: flex; flex-direction: column; gap: 10px; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.toggle-row input { display: none; }
.toggle {
  width: 38px; height: 20px;
  background: var(--border2);
  border-radius: 10px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: var(--text3);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: all var(--transition);
}
.toggle-row input:checked + .toggle { background: rgba(0,230,118,0.3); }
.toggle-row input:checked + .toggle::after {
  left: 20px;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

/* ── MAP ─────────────────────────────────────────────────────── */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

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

/* Leaflet dark overrides */
.leaflet-tile-pane { filter: saturate(0.7) brightness(0.85); }
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface2) !important; }
.leaflet-popup-content-wrapper {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 16px; }

/* ── INFO CARD ───────────────────────────────────────────────── */
.info-card {
  position: absolute;
  bottom: 24px;
  right: 16px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 16px;
  z-index: 900;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
}
.info-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.info-device-name { font-weight: 600; font-size: 15px; }
.info-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
  letter-spacing: 0.08em;
}
.info-badge.online { background: rgba(0,230,118,0.15); color: var(--accent); }
.info-badge.offline { background: rgba(255,68,68,0.1); color: var(--danger); }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.info-item.full { grid-column: 1/-1; }
.info-label {
  font-size: 9px;
  color: var(--text3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.info-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}

/* ── LAYER SWITCHER ──────────────────────────────────────────── */
.layer-switcher {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  z-index: 900;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 4px;
}
.layer-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}
.layer-btn:hover { color: var(--text); }
.layer-btn.active { background: var(--surface2); color: var(--accent); }

/* ── INPUTS ──────────────────────────────────────────────────── */
.select-input, .text-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-body);
  transition: border-color var(--transition);
  outline: none;
}
.select-input:focus, .text-input:focus { border-color: var(--accent); }
.select-input { flex: 1; }
.text-input { width: 100%; }

.color-input {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: var(--surface2);
}

.btn-primary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary:hover { background: rgba(0,230,118,0.1); }

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-body h3 { font-size: 13px; color: var(--text2); font-family: var(--font-mono); }
.modal-divider { border: none; border-top: 1px solid var(--border); }

.config-item { display: flex; flex-direction: column; gap: 4px; }
.config-item label { font-size: 11px; color: var(--text3); letter-spacing: 0.08em; text-transform: uppercase; }
.config-item small { font-size: 11px; color: var(--text3); }
.config-value {
  font-size: 14px;
  color: var(--text2);
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
}
.config-value.mono { font-family: var(--font-mono); color: var(--accent2); }

.rename-form { display: flex; gap: 8px; flex-wrap: wrap; }
.rename-form .select-input { width: 100%; flex: none; }
.rename-form .text-input { flex: 1; }

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── CUSTOM MAP MARKERS ──────────────────────────────────────── */
.gps-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-pulse {
  width: 16px; height: 16px;
  border-radius: 50%;
  position: relative;
}
.marker-pulse::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid currentColor;
  animation: pulse 2s ease-out infinite;
  opacity: 0.5;
}
@keyframes pulse {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(2); opacity: 0; }
}

/* ── ANIMATIONS ──────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.device-card { animation: fadeIn 200ms ease; }

/* ── LOGIN PAGE ──────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
  background: var(--bg);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6);
  animation: fadeIn 250ms ease;
}

.login-logo {
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

.login-title {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 32px;
}

.login-form { text-align: left; }
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text3);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 230, 118, 0.12);
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 18px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.login-btn:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
.login-btn:active:not(:disabled) { transform: translateY(0); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
