:root {
  --bg: #081018;
  --bg-soft: #0f1a24;
  --bg-card: #111f2b;
  --bg-card-2: #0c1720;
  --text: #edf7ff;
  --muted: #91a4b7;
  --line: rgba(255, 255, 255, 0.1);
  --ok: #1f9d61;
  --ok-soft: rgba(31, 157, 97, 0.16);
  --warning: #d6a21b;
  --warning-soft: rgba(214, 162, 27, 0.18);
  --risk: #e26d22;
  --risk-soft: rgba(226, 109, 34, 0.18);
  --critical: #e33434;
  --critical-soft: rgba(227, 52, 52, 0.22);
  --blue: #3ea2ff;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(62, 162, 255, 0.14), transparent 32%),
    radial-gradient(circle at bottom right, rgba(227, 52, 52, 0.10), transparent 36%),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.page-shell {
  width: min(1920px, 100%);
  margin: 0 auto;
  padding: 8px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  background: rgba(9, 19, 28, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 6px;
  z-index: 20;
  backdrop-filter: blur(14px);
  min-height: 50px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 230px;
}

h1 {
  font-size: 17px;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

#panelSubtitle {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.topbar-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-action,
.primary-btn,
.ghost-btn,
.sound-btn,
.ghost-link,
.icon-btn,
.filter-btn,
.summary-card {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border-radius: 999px;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-action {
  width: 40px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-weight: 800;
  font-size: 18px;
  background: rgba(31, 43, 61, 0.82);
}

.icon-action.text-action {
  width: auto;
  min-width: 74px;
  padding: 0 11px;
  font-size: 12px;
}

.primary-btn,
.ghost-btn,
.sound-btn,
.ghost-link,
.filter-btn,
.summary-card {
  padding: 8px 11px;
}

.primary-btn {
  background: linear-gradient(135deg, rgba(62, 162, 255, 0.92), rgba(62, 162, 255, 0.5));
  border-color: rgba(62, 162, 255, 0.55);
}

.sound-btn.enabled {
  background: var(--ok-soft);
  border-color: rgba(31, 157, 97, 0.6);
}

.icon-action:hover,
.ghost-btn:hover,
.ghost-link:hover,
.primary-btn:hover,
.sound-btn:hover,
.filter-btn:hover,
.summary-card:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.1);
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(6, minmax(95px, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.summary-panel.collapsed,
.toolbar.collapsed { display: none; }

.summary-card {
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  min-height: 48px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.055);
}

.summary-card strong { font-size: 23px; }

.summary-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-card.ok { border-color: rgba(31, 157, 97, 0.42); background: var(--ok-soft); }
.summary-card.warning { border-color: rgba(214, 162, 27, 0.45); background: var(--warning-soft); }
.summary-card.risk { border-color: rgba(226, 109, 34, 0.48); background: var(--risk-soft); }
.summary-card.critical { border-color: rgba(227, 52, 52, 0.55); background: var(--critical-soft); }
.summary-card.muted { opacity: 0.88; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 7px;
  background: rgba(9, 19, 28, 0.76);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.search-box,
.select-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 13px;
}

.search-box input,
.select-box select {
  background: transparent;
  color: var(--text);
  border: 0;
  outline: 0;
}

.search-box input { width: min(320px, 55vw); }
.select-box select option { background: #0d1722; }

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  padding: 7px 10px;
  font-size: 13px;
}

.filter-btn.active {
  background: rgba(62, 162, 255, 0.22);
  border-color: rgba(62, 162, 255, 0.55);
}

.status-strip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11px;
  padding: 7px 4px 2px;
}

.connection-state.ok { color: #63d891; }
.connection-state.error { color: #ff7878; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 9px;
  margin-top: 6px;
}

.cards-grid.compact { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.cards-grid.ultra { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 6px; }

.pair-card {
  background: linear-gradient(180deg, rgba(17, 31, 43, 0.98), rgba(9, 17, 25, 0.98));
  border: 1px solid var(--line);
  border-left: 6px solid var(--ok);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  overflow: hidden;
  position: relative;
  min-height: 158px;
}

.cards-grid.ultra .pair-card {
  min-height: 78px;
  border-left-width: 4px;
  border-radius: 11px;
}

.pair-card[data-status="warning"] { border-left-color: var(--warning); }
.pair-card[data-status="risk"] { border-left-color: var(--risk); }
.pair-card[data-status="critical"] {
  border-left-color: var(--critical);
  box-shadow: 0 0 0 1px rgba(227, 52, 52, 0.22), 0 16px 34px rgba(227, 52, 52, 0.16);
}

.pair-card[data-status="critical"]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(227, 52, 52, 0.13), transparent 38%);
  animation: criticalPulse 1.8s ease-in-out infinite;
}

@keyframes criticalPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.card-button {
  width: 100%;
  min-height: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 11px;
}

.cards-grid.compact .card-button { padding: 10px; gap: 7px; }
.cards-grid.ultra .card-button { padding: 7px 8px; gap: 3px; min-height: 78px; }

.card-top,
.ultra-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.distance-block strong {
  font-size: 21px;
  display: block;
}

.cards-grid.compact .distance-block strong { font-size: 18px; }

.distance-block span,
.card-meta,
.person-line .meta,
.reason-list,
.ultra-meta,
.ultra-reason {
  color: var(--muted);
  font-size: 11px;
}

.status-chip,
.status-pill,
.ultra-status-dot {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  white-space: nowrap;
}

.status-chip.ok,
.status-pill.ok,
.ultra-status-dot.ok { background: var(--ok-soft); border-color: rgba(31, 157, 97, 0.52); }
.status-chip.warning,
.status-pill.warning,
.ultra-status-dot.warning { background: var(--warning-soft); border-color: rgba(214, 162, 27, 0.52); }
.status-chip.risk,
.status-pill.risk,
.ultra-status-dot.risk { background: var(--risk-soft); border-color: rgba(226, 109, 34, 0.55); }
.status-chip.critical,
.status-pill.critical,
.ultra-status-dot.critical { background: var(--critical-soft); border-color: rgba(227, 52, 52, 0.6); }

.person-block {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.person-line {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 7px;
  background: rgba(255, 255, 255, 0.042);
}

.person-line.warning { background: var(--warning-soft); border-color: rgba(214, 162, 27, 0.38); }
.person-line.risk { background: var(--risk-soft); border-color: rgba(226, 109, 34, 0.42); }
.person-line.critical { background: var(--critical-soft); border-color: rgba(227, 52, 52, 0.48); }

.person-line .name-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  font-size: 13px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.22);
  color: #dbe9f4;
  font-size: 10px;
}

.reason-list { padding-top: 2px; line-height: 1.25; }

.ultra-title {
  font-weight: 850;
  font-size: 12px;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.ultra-distance {
  font-weight: 900;
  font-size: 13px;
  white-space: nowrap;
}

.ultra-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  font-size: 10px;
  line-height: 1.2;
  color: #dbe9f4;
}

.ultra-person {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ultra-person.warning { color: #ffd670; }
.ultra-person.risk { color: #ffaf75; }
.ultra-person.critical { color: #ff8d8d; }

.ultra-status-dot {
  width: 9px;
  height: 9px;
  padding: 0;
  flex: 0 0 auto;
}

.ultra-reason {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.empty-state {
  text-align: center;
  margin: 80px auto;
  color: var(--muted);
}

/* Respeta el atributo hidden. */
[hidden],
.modal-overlay[hidden] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}

.detail-panel {
  width: min(620px, 96vw);
  height: 100vh;
  background: #0b1620;
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: auto;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.detail-header h2 { margin-top: 8px; }
#detailSubtitle { margin-top: 3px; color: var(--muted); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.detail-body {
  display: grid;
  gap: 12px;
  padding: 14px 0;
}

.detail-section {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-field {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding-top: 7px;
}

.detail-field span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-field strong {
  display: block;
  margin-top: 3px;
  word-break: break-word;
}

.alert-list { display: grid; gap: 8px; }

.alert-item {
  border: 1px solid rgba(227, 52, 52, 0.35);
  background: var(--critical-soft);
  border-radius: 12px;
  padding: 10px;
}

.alert-item small { color: var(--muted); display: block; margin: 3px 0 6px; }

.toast-container {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 80;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 360px;
  background: #101d28;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.toast.critical { border-left-color: var(--critical); }
.toast.error { border-left-color: var(--critical); }
.toast.ok { border-left-color: var(--ok); }

body.monitor-fullscreen {
  background: #02070c;
  overflow: hidden;
}

body.monitor-fullscreen .page-shell {
  width: 100%;
  height: 100vh;
  padding: 4px;
}

body.monitor-fullscreen .topbar,
body.monitor-fullscreen .summary-panel,
body.monitor-fullscreen .toolbar,
body.monitor-fullscreen .status-strip,
body.monitor-fullscreen .empty-state:not([hidden]) {
  display: none !important;
}

body.monitor-fullscreen .cards-grid {
  margin-top: 0;
  height: calc(100vh - 8px);
  align-content: start;
  overflow: auto;
  padding: 0;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 5px;
}

body.monitor-fullscreen .cards-grid:not(.ultra) {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

body.monitor-fullscreen .cards-grid.ultra .pair-card { min-height: 70px; }
body.monitor-fullscreen .cards-grid.ultra .card-button { min-height: 70px; padding: 6px 7px; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .summary-panel { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .cards-grid,
  .cards-grid.compact,
  .cards-grid.ultra { grid-template-columns: 1fr; }
}

/* Fase 3: acciones operativas del detalle */
.detail-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  align-items: stretch;
}

.detail-actions-grid .primary-btn,
.detail-actions-grid .ghost-btn {
  width: 100%;
  justify-content: center;
}

.warning-action {
  border-color: rgba(214, 162, 27, 0.45);
  background: rgba(214, 162, 27, 0.12);
}

.danger-action {
  border-color: rgba(227, 52, 52, 0.5);
  background: rgba(227, 52, 52, 0.12);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none !important;
}

.alert-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tiny-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1;
}

.tiny-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.tiny-btn.danger {
  border-color: rgba(227, 52, 52, 0.45);
  background: rgba(227, 52, 52, 0.14);
}

.alert-item.muted-alert {
  border-color: rgba(145, 164, 183, 0.25);
  background: rgba(145, 164, 183, 0.08);
}

.alert-item.muted-alert p,
.alert-item.muted-alert strong {
  opacity: 0.78;
}

/* Fix Fase 3.1: identificación de persona y procesamiento con detalle */
.alert-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.alert-subject-badge,
.subject-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  background: rgba(255, 255, 255, 0.08);
  color: #e9f3ff;
}

.alert-subject-badge.victim,
.subject-pill.victim {
  border-color: rgba(71, 154, 255, 0.45);
  background: rgba(71, 154, 255, 0.14);
}

.alert-subject-badge.aggressor,
.subject-pill.aggressor {
  border-color: rgba(226, 109, 34, 0.48);
  background: rgba(226, 109, 34, 0.16);
}

.alert-subject-badge.pair,
.subject-pill.pair {
  border-color: rgba(227, 52, 52, 0.55);
  background: rgba(227, 52, 52, 0.18);
}

.center-overlay {
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.alert-process-modal {
  width: min(720px, 96vw);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: #101a28;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.alert-process-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.alert-process-header h2 {
  margin: 10px 0 4px;
}

#alertProcessSubtitle {
  color: var(--muted);
  margin: 0;
}

.alert-process-body {
  display: grid;
  gap: 12px;
  padding: 14px 0;
}

.alert-process-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.alert-process-section {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  padding: 12px;
}

.alert-process-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.alert-process-detail {
  margin: 0;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.process-comment-block {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.process-comment-block textarea {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  border: 1px solid rgba(145, 164, 183, 0.42);
  background: #070d19;
  color: var(--text);
  border-radius: 13px;
  padding: 12px;
  font: inherit;
}

.alert-process-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.alert-process-actions .primary-btn,
.alert-process-actions .ghost-btn {
  width: 100%;
  justify-content: center;
}

@media (max-width: 720px) {
  .alert-process-grid,
  .alert-process-actions {
    grid-template-columns: 1fr;
  }
}
