/* ============================================================
   RAGAR — Panel de monitoreo
   Tokens
   ============================================================ */
:root {
  --bg: #0b1016;
  --surface: #141b24;
  --surface-raised: #1c2531;
  --line: #2a3542;
  --text: #e7ecf2;
  --text-muted: #8d99a8;
  --text-faint: #5c6775;

  --amber: #d98e34;
  --amber-soft: rgba(217, 142, 52, 0.16);
  --red: #c9524a;
  --red-soft: rgba(201, 82, 74, 0.16);
  --teal: #5b8a8e;
  --teal-soft: rgba(91, 138, 142, 0.16);

  --font-ui: 'IBM Plex Sans Condensed', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* Blindaje: nuestras reglas de layout (display: flex, etc.) tienen la
   misma especificidad que [hidden], así que sin esto el atributo
   `hidden` no ocultaría estos contenedores. */
[hidden] { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================================================
   Pantalla de login
   ============================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(217, 142, 52, 0.08), transparent 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.login-eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--amber);
}

.login-title {
  font-size: 22px;
  margin-bottom: 4px;
}

.login-sub {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--text-muted);
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
}

.field input:focus {
  border-color: var(--amber);
}

.login-error {
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: #f0b8b4;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius);
  margin: 0 0 16px;
}

.btn-primary {
  width: 100%;
  background: var(--amber);
  border: none;
  border-radius: var(--radius);
  color: #1a1206;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 11px;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 12px;
}

.btn-ghost:hover { border-color: var(--text-faint); color: var(--text); }

/* ============================================================
   Layout general del panel
   ============================================================ */
.dashboard {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.topbar-mark {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--amber);
  letter-spacing: 0.04em;
}

.topbar-name {
  font-size: 15px;
  color: var(--text-muted);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.conn-dot.ok { background: var(--teal); }
.conn-dot.error { background: var(--red); }

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  min-height: 0;
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-map { border-right: 1px solid var(--line); padding: 0; }
.panel-incidents { border-right: none; }

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}

.panel-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-raised);
  border-radius: var(--radius);
  padding: 2px 7px;
}

.scroll-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.empty-state {
  color: var(--text-faint);
  font-size: 13px;
  padding: 16px;
  margin: 0;
}

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

/* ============================================================
   Lista de guardias
   ============================================================ */
.guard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--text-faint);
}

.status-dot.online {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--amber-soft); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.guard-info {
  min-width: 0;
  flex: 1;
}

.guard-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guard-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ============================================================
   Marcador de guardia en el mapa
   ============================================================ */
.guard-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid #1a1206;
  box-shadow: 0 0 0 4px var(--amber-soft);
  animation: pulse-map 2.2s ease-in-out infinite;
}

@keyframes pulse-map {
  0%, 100% { box-shadow: 0 0 0 4px var(--amber-soft); }
  50% { box-shadow: 0 0 0 9px transparent; }
}

.map-popup {
  font-family: var(--font-ui);
}

.map-popup .popup-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.map-popup .popup-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ============================================================
   Incidentes
   ============================================================ */
.incident-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid var(--text-faint);
}

.incident-row.severity-baja { border-left-color: var(--teal); }
.incident-row.severity-media { border-left-color: var(--amber); }
.incident-row.severity-alta,
.incident-row.severity-critica { border-left-color: var(--red); }

.incident-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.incident-title {
  font-size: 13px;
  color: var(--text);
}

.incident-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: lowercase;
  color: var(--text-faint);
  flex: none;
}

.incident-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ============================================================
   Rondas del día
   ============================================================ */
.panel-rounds {
  flex: none;
  height: 128px;
  border-top: 1px solid var(--line);
  border-right: none;
}

.rounds-strip {
  flex: 1;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 0 16px 14px;
}

.round-card {
  flex: none;
  width: 220px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.round-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.round-guard {
  font-size: 13px;
  color: var(--text);
}

.round-status {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius);
}

.round-status.pendiente { color: var(--text-muted); background: var(--surface); }
.round-status.en_progreso { color: var(--amber); background: var(--amber-soft); }
.round-status.completada { color: var(--teal); background: var(--teal-soft); }
.round-status.incompleta { color: var(--red); background: var(--red-soft); }

.round-route {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.round-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 50vh auto;
    overflow-y: auto;
  }

  .panel-guards, .panel-incidents {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }
}
