:root {
  --bg-dark: #14171c;
  --bg-panel: #1c2028;
  --border: #2a2f3a;
  --text: #e8e6d4;
  --text-dim: #8b8d94;
  --gold: #c9a24d;
  --gold-dim: #a3812f;
  --online: #2ecc71;
  --moving: #3498db;
  --offline: #e74c3c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
}

.accent { color: var(--gold); }

/* ---- Login ---- */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 320px;
}

.login-box h1 {
  margin: 0 0 24px;
  font-weight: 300;
  font-size: 24px;
  text-align: center;
}

.login-box label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

.login-box input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.login-box input:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.login-box button {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  color: #14171c;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.login-box button:hover { background: var(--gold-dim); }
.login-box button:disabled { opacity: 0.6; cursor: default; }

.error {
  color: var(--offline);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

/* ---- App layout ---- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  font-weight: 300;
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-dim);
}

.topbar-right button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}

.conn-status {
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(46, 204, 113, 0.15);
  color: var(--online);
}

.layout {
  display: flex;
  height: calc(100vh - 56px);
  position: relative;
}

.sidebar {
  width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar-header {
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.search-box {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(201, 162, 77, 0.06);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.group-header:hover { background: rgba(201, 162, 77, 0.12); }

.group-toggle { width: 10px; color: var(--text-dim); }
.group-name { flex: 1; }
.group-count {
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  padding: 1px 7px;
  border-radius: 10px;
}

.device-list { padding: 4px; }

.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

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

.device-name { color: var(--text); display: flex; flex-direction: column; }

.device-imei {
  font-size: 10px;
  color: var(--text-dim);
  font-family: monospace;
}

.detail-imei {
  font-size: 11px;
  color: var(--text-dim);
  font-family: monospace;
  margin-left: auto;
}

.device-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}

.status-online .device-status { background: rgba(46, 204, 113, 0.15); color: var(--online); }
.status-moving .device-status { background: rgba(52, 152, 219, 0.15); color: var(--moving); }
.status-offline .device-status { background: rgba(231, 76, 60, 0.15); color: var(--offline); }

#map {
  flex: 1;
  background: #0d0f13;
}

/* ---- Panel de detalle ---- */
.detail-panel {
  position: absolute;
  bottom: 16px;
  left: 316px;
  right: 16px;
  max-width: 720px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 16px;
  z-index: 1000;
}

.detail-panel.hidden { display: none; }

.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.detail-close:hover { color: var(--text); }

.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-right: 24px;
}

.detail-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.detail-card-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--gold);
  margin-bottom: 8px;
}

.detail-address {
  font-size: 13px;
  line-height: 1.4;
}

.detail-time {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

.detail-sensors {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.sensor-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.sensor-row span:first-child { color: var(--text-dim); }
.sensor-empty { color: var(--text-dim); font-style: italic; justify-content: flex-start; }

.status-inline-online { color: var(--online); }
.status-inline-moving { color: var(--moving); }
.status-inline-offline { color: var(--offline); }
