* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: Inter, Segoe UI, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  overflow: hidden;
}

.layout {
  display: flex;
  flex-direction: row;
  height: 100%;
  height: 100dvh;
  width: 100%;
}

.map-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#map {
  height: 100%;
  width: 100%;
  background: #1e293b;
}

.sidebar {
  width: 320px;
  max-width: 42vw;
  background: #111827;
  border-left: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}

.sidebar-header h1 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.sidebar-header p {
  margin: 0;
  color: #94a3b8;
  font-size: 0.88rem;
}

.sidebar-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.btn-hide-panel {
  flex-shrink: 0;
  padding: 8px 12px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #1f2937;
  color: #cbd5e1;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-hide-panel:hover {
  background: #334155;
  color: #fff;
}

.btn-live-inline,
.btn-show-panel {
  border: none;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.btn-live-inline {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  background: #16a34a;
  color: #fff;
  font-size: 0.9rem;
}

.btn-live-inline:hover { background: #15803d; }

.btn-show-panel {
  display: none;
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  right: 16px;
  z-index: 500;
  padding: 12px 16px;
  background: #2563eb;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.btn-show-panel:hover { background: #1d4ed8; }

body.panel-hidden .sidebar {
  display: none;
}

body.panel-hidden .map-wrap {
  flex: 1 1 100%;
  width: 100%;
  height: 100%;
  max-height: none;
}

body.panel-hidden .btn-show-panel {
  display: inline-block;
}

.route-actions {
  display: grid;
  gap: 8px;
}

.device-list {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.device-card {
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}

.device-card.active { border-color: #38bdf8; }
.device-card.offline { opacity: 0.65; }

.device-card h3 {
  margin: 0;
  font-size: 0.95rem;
}

.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.device-info {
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 10px;
  background: #0f172a;
  border: 1px solid #334155;
  display: grid;
  gap: 6px;
}

.info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-title {
  font-size: 0.72rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #1f2937;
  color: #cbd5e1;
  cursor: pointer;
  padding: 0;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}

.info-row span { color: #94a3b8; }
.info-row strong {
  color: #f8fafc;
  text-align: right;
  word-break: break-word;
}

.device-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #334155;
  display: grid;
  gap: 6px;
}

.device-form label {
  font-size: 0.72rem;
  color: #94a3b8;
  text-transform: uppercase;
}

.device-form input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 16px;
}

.device-form button {
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions button[type="submit"] { flex: 1; }

.btn-cancel {
  padding: 10px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  font-weight: 600;
  cursor: pointer;
}

.save-msg {
  min-height: 16px;
  font-size: 0.78rem;
  color: #94a3b8;
}

.save-msg.ok { color: #86efac; }
.save-msg.error { color: #fca5a5; }

.route-panel {
  margin: 8px 0;
  padding: 10px;
  border-radius: 10px;
  background: #0b1220;
  border: 1px solid #1e40af;
  display: grid;
  gap: 6px;
}

.route-panel select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 16px;
}

.route-info {
  font-size: 0.8rem;
  color: #93c5fd;
}

.meta {
  color: #94a3b8;
  font-size: 0.82rem;
  line-height: 1.45;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge.online { background: #14532d; color: #86efac; }
.badge.offline { background: #450a0a; color: #fca5a5; }

/* Celular: mapa arriba 42%, panel abajo scrollable */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .map-wrap {
    flex: 0 0 42dvh;
    min-height: 220px;
    max-height: 50dvh;
    width: 100%;
  }

  .sidebar {
    flex: 1;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    border-left: none;
    border-top: 1px solid #1f2937;
  }

  .sidebar-header {
    padding: 12px 14px;
  }

  .sidebar-header h1 {
    font-size: 1rem;
  }

  body.panel-hidden .map-wrap {
    flex: 1 1 100dvh;
    min-height: 100dvh;
    max-height: none;
  }
}
