:root {
  --navy-950: #06111f;
  --navy-900: #0a1f33;
  --navy-800: #0f2b47;
  --navy-700: #163a5c;
  --navy-600: #1f4d78;
  --gold: #c9a227;
  --gold-light: #e0c15c;
  --text: #e8edf2;
  --text-dim: #9fb3c8;
  --ok: #2ecc71;
  --warn: #f5a623;
  --crit: #e74c3c;
  --border: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at top, var(--navy-900), var(--navy-950) 70%);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: linear-gradient(160deg, var(--navy-800), var(--navy-900));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}
.login-card .badge {
  width: 84px; height: 84px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-light), var(--gold) 70%);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: var(--navy-950); font-weight: bold;
  overflow: hidden;
  box-shadow: 0 0 0 3px rgba(201,162,39,0.25);
}
.login-card .badge img,
.brand .badge img {
  width: 100%; height: 100%; object-fit: cover;
}
.login-card h1 {
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--gold-light);
  margin: 0 0 2px;
  text-transform: uppercase;
}
.login-card h2 {
  font-size: 20px;
  margin: 0 0 24px;
  color: var(--text);
  font-weight: 600;
}
.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;}
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--navy-950);
  color: var(--text);
  font-size: 14px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--gold); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(160deg, var(--gold-light), var(--gold));
  color: var(--navy-950);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .15s ease;
}
.btn:hover { box-shadow: 0 6px 18px rgba(201,162,39,0.35); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--navy-700); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--crit); color: white; }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 12px; }

.error-msg { color: var(--crit); font-size: 13px; margin-top: 10px; min-height: 18px; }
.hint { color: var(--text-dim); font-size: 12px; margin-top: 18px; }

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-900), var(--navy-950));
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .badge {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle, var(--gold-light), var(--gold) 70%);
  display: flex; align-items: center; justify-content: center;
  color: var(--navy-950); font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.brand .titles { line-height: 1.25; }
.brand .titles .t1 { font-size: 10px; letter-spacing: 1px; color: var(--gold-light); text-transform: uppercase; }
.brand .titles .t2 { font-size: 13px; font-weight: 700; }

.nav-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.nav-item.active, .nav-item:hover { background: var(--navy-700); color: var(--text); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.user-box {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.user-box .name { color: var(--text); font-weight: 600; font-size: 13px; margin-bottom: 8px;}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .sub { color: var(--text-dim); font-size: 12px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--navy-800);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 220px;
  flex: 1;
  max-width: 360px;
}
.search-box input {
  background: transparent; border: none; outline: none; color: var(--text);
  font-size: 13px; width: 100%;
}
.search-box svg { width: 16px; height: 16px; color: var(--text-dim); flex-shrink: 0; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.content {
  padding: 20px 24px;
  flex: 1;
  overflow: auto;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
}

.card {
  background: linear-gradient(160deg, var(--navy-800), var(--navy-900));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 14px; color: var(--gold-light); text-transform: uppercase; letter-spacing: .5px; }

#map, #map-visor, #map-nearby {
  height: 420px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.member-list { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow: auto; }
.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--navy-950);
  border: 1px solid var(--border);
  cursor: pointer;
}
.member-row:hover { border-color: var(--gold); }
.member-row .avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--navy-700);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  color: var(--gold-light); flex-shrink: 0;
}
.member-row .info { flex: 1; min-width: 0; }
.member-row .info .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-row .info .r { font-size: 11px; color: var(--text-dim); }

/* Variante apilada: nombre arriba (con avatar), rango + controles en su propia fila debajo — evita apretujar todo en una sola línea horizontal. */
.member-row.stacked { flex-direction: column; align-items: stretch; gap: 6px; }
.member-row.stacked .mr-head { display: flex; align-items: center; gap: 10px; }
.member-row.stacked .mr-name { font-size: 13px; font-weight: 600; line-height: 1.3; word-break: break-word; flex: 1; min-width: 0; }
.member-row.stacked .mr-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-left: 48px; }
.member-row.stacked .mr-rank { font-size: 11px; color: var(--text-dim); }
.member-row.stacked .mr-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.status-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.status-pill.normal { background: rgba(46,204,113,0.15); color: var(--ok); }
.status-pill.advertencia { background: rgba(245,166,35,0.15); color: var(--warn); }
.status-pill.critico { background: rgba(231,76,60,0.18); color: var(--crit); }

.sleep-pill {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--navy-700); color: var(--gold-light);
}
.sleep-pill svg { width: 14px; height: 14px; }

.vitals-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.vital-box {
  background: var(--navy-950);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.vital-box .label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; }
.vital-box .value { font-size: 18px; font-weight: 700; margin: 4px 0; }
.vital-box .range { font-size: 10px; color: var(--text-dim); }

/* ---------- Telemetría gráfica (signos vitales) ---------- */
.detail-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  background: var(--navy-950);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.detail-top .meta { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.detail-top .meta b { color: var(--text); font-weight: 600; }
.state-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--navy-700); font-size: 12px; color: var(--text);
}
.state-chip svg { width: 14px; height: 14px; }

.telemetry-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.vital-tile {
  display: flex; align-items: center; gap: 10px;
  background: var(--navy-950);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.vital-tile .vt-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.05);
}
.vital-tile .vt-icon svg { width: 20px; height: 20px; }
.vital-tile.normal .vt-icon { color: var(--ok); }
.vital-tile.advertencia .vt-icon { color: var(--warn); }
.vital-tile.critico .vt-icon { color: var(--crit); }
.vital-tile .vt-body { flex: 1; min-width: 0; }
.vital-tile .vt-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.vital-tile .vt-value { font-size: 17px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.vital-tile .vt-value .unit { font-size: 11px; color: var(--text-dim); font-weight: 500; margin-left: 3px; }
.vital-tile .vt-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.vital-tile.normal .vt-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.vital-tile.advertencia .vt-dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.vital-tile.critico .vt-dot { background: var(--crit); box-shadow: 0 0 8px var(--crit); animation: pulseDot 1s infinite; }
@keyframes pulseDot { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.status-gauge { display: flex; align-items: center; gap: 12px; }
.status-gauge .sg-ring {
  width: 50px; height: 50px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid; flex-shrink: 0;
}
.status-gauge .sg-ring svg { width: 22px; height: 22px; }
.status-gauge.normal .sg-ring { border-color: var(--ok); color: var(--ok); box-shadow: 0 0 16px rgba(46,204,113,0.35); }
.status-gauge.advertencia .sg-ring { border-color: var(--warn); color: var(--warn); box-shadow: 0 0 16px rgba(245,166,35,0.35); }
.status-gauge.critico .sg-ring { border-color: var(--crit); color: var(--crit); box-shadow: 0 0 16px rgba(231,76,60,0.4); animation: ringPulse 1.1s infinite; }
@keyframes ringPulse { 0%, 100% { box-shadow: 0 0 16px rgba(231,76,60,0.4); } 50% { box-shadow: 0 0 26px rgba(231,76,60,0.75); } }
.status-gauge .sg-label { font-weight: 700; font-size: 14px; }

.coords-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
  margin-top: 10px;
}
.coords-row svg { width: 15px; height: 15px; flex-shrink: 0; }
.copy-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  background: var(--navy-700); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; padding: 0;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.copy-btn:hover { background: var(--navy-600); color: var(--text); }
.copy-btn svg { width: 13px; height: 13px; }
.copy-btn.copied { background: rgba(46,204,113,0.18); color: var(--ok); border-color: rgba(46,204,113,0.4); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.range-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center;}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal {
  background: linear-gradient(160deg, var(--navy-800), var(--navy-900));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
}
.modal h3 { margin-top: 0; color: var(--gold-light); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.pick-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.pick-status { font-size: 12px; margin-top: 4px; color: var(--gold-light); display: flex; align-items: center; gap: 5px; }
.pick-status svg { width: 13px; height: 13px; }

.hamburger { display: none; }

.badge-count {
  background: var(--gold); color: var(--navy-950); border-radius: 999px;
  font-size: 10px; padding: 1px 7px; font-weight: 800;
}

@media (max-width: 880px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 900;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 20px 0 40px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--navy-700); border: 1px solid var(--border);
    color: var(--text); cursor: pointer; font-size: 18px;
  }
  .hamburger svg { width: 19px; height: 19px; }
  .topbar { padding: 12px 14px; }
  .topbar h2 { font-size: 15px; }
  .content { padding: 14px; }
  #map, #map-visor, #map-nearby { height: 300px; }
  .vitals-row { grid-template-columns: repeat(2, 1fr); }
  .telemetry-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-top { flex-direction: column; align-items: flex-start; }
  .card { padding: 14px; }
  .modal { padding: 16px; }

  /* Tabla de miembros -> tarjetas apiladas (evita scroll horizontal invisible) */
  #view-members table, #view-members thead, #view-members tbody, #view-members tr, #view-members td {
    display: block;
    width: 100%;
  }
  #view-members thead { display: none; }
  #view-members tr {
    background: var(--navy-950);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  #view-members tbody tr:last-child { margin-bottom: 0; }
  #view-members td {
    border: none;
    padding: 7px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
  }
  #view-members td::before {
    content: attr(data-label);
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .4px;
    font-weight: 700;
    flex-shrink: 0;
  }
  #view-members td[data-label="Nombre"] {
    font-size: 15px; font-weight: 700; color: var(--text);
    justify-content: flex-start;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
  }
  #view-members td[data-label="Nombre"]::before { content: none; }
  #view-members td[data-label="Acciones"] { justify-content: flex-end; }
}
