:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-d: #1d4ed8;
  --danger: #dc2626;
  --topbar-h: 52px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #f1f5f9;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

/* -------- login -------- */
.login-wrap {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b, var(--bg));
  padding: 20px;
}
.login-card {
  background: var(--panel); border-radius: 16px; padding: 28px 24px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input {
  width: 100%; padding: 11px 12px; margin-top: 14px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px;
}
.login-card button {
  width: 100%; margin-top: 14px; padding: 11px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: var(--accent-d); }

/* -------- app shell -------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--bg); color: #fff;
}
.brand { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }
.icon-btn {
  background: transparent; border: 0; color: #fff; font-size: 18px; cursor: pointer;
  padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
#btn-menu { display: none; }

.body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
}
.sidebar-head h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.mini-btn {
  border: 1px solid var(--accent); color: var(--accent); background: #fff;
  border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.mini-btn:hover { background: #eff6ff; }
.hint { padding: 4px 16px 16px; }

.device-list { padding: 4px 10px; }
.device {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0;
}
.device-top { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.device-name { font-weight: 600; font-size: 14px; flex: 1; }
.device-meta { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.device-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line); background: #f8fafc; border-radius: 999px;
  padding: 3px 9px; font-size: 12px; cursor: pointer; color: var(--text);
}
.chip:hover { background: #eef2f7; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.danger { color: var(--danger); border-color: #fecaca; }
.chip.danger:hover { background: #fef2f2; }
.device input[type=checkbox] { width: 16px; height: 16px; }

#map { flex: 1; min-width: 0; height: 100%; background: #e5e7eb; }

/* -------- modal -------- */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000;
}
.modal {
  background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 440px;
  position: relative; box-shadow: 0 20px 50px rgba(0,0,0,.4); max-height: 90vh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 10px; right: 12px; border: 0; background: transparent;
  font-size: 18px; cursor: pointer; color: var(--muted);
}
.modal h3 { margin: 0 0 12px; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.modal input[type=text], .modal input[type=color] {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px;
}
.modal input[type=color] { height: 42px; padding: 4px; }
.modal .row { display: flex; gap: 10px; align-items: flex-end; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; background: var(--accent); color: #fff; margin-top: 16px;
}
.btn:hover { background: var(--accent-d); }
.btn.ghost { background: #f1f5f9; color: var(--text); }
.kv {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-top: 8px; font-size: 13px; word-break: break-all;
}
.kv b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.warn {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px;
}

/* -------- responsive -------- */
@media (max-width: 720px) {
  #btn-menu { display: inline-block; }
  #user-email { display: none; }        /* el email largo empujaba los botones fuera */
  .icon-btn { padding: 6px 6px; font-size: 20px; }
  .sidebar {
    position: absolute; top: var(--topbar-h); bottom: 0; left: 0; z-index: 500;
    width: 84%; max-width: 320px; box-shadow: 4px 0 24px rgba(0,0,0,.25);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
}

/* leaflet popup */
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content b { font-size: 14px; }
