/* Monitor de tempo real (#20). Usa os tokens de bina.css; classes escopadas em .monitor com prefixo mon-.
   Classes sem prefixo (event-item, call-row, portal-button, empty-state, event-list) são ganchos da lógica JS. */

.monitor [hidden], .mon-toast[hidden] { display: none !important; }
.monitor h2 { font-size: var(--bn-text-lg); }

/* ---------- Faixa de conexão (fixa sob o cabeçalho do shell) ---------- */
.mon-statusbar {
  position: sticky; top: calc(var(--bn-topbar-height) + var(--bn-space-2)); z-index: 800;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--bn-space-3);
  margin-bottom: var(--bn-space-4); padding: var(--bn-space-2) var(--bn-space-2) var(--bn-space-2) var(--bn-space-4);
  background: var(--bn-surface); border: 1px solid var(--bn-border); border-left: 6px solid var(--mon-status-color, var(--bn-ink-300));
  border-radius: var(--bn-radius); box-shadow: var(--bn-shadow);
}
.mon-connection { display: flex; align-items: center; gap: var(--bn-space-3); flex: 1; min-width: 0; min-height: 40px; }
.mon-connection__dot { width: 12px; height: 12px; flex: none; border-radius: 50%; background: var(--mon-status-color, var(--bn-ink-300)); }
.mon-connection__text { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--bn-space-2); min-width: 0; font-size: var(--bn-text-sm); }
.mon-connection__title { font-size: var(--bn-text-md); font-weight: 650; color: var(--mon-status-text, var(--bn-text)); }
.mon-connection__detail { color: var(--bn-text-muted); }
.mon-connection[data-state="connecting"],
.mon-connection[data-state="reconnecting"] { --mon-status-text: var(--bn-ringing-700); }
.mon-connection[data-state="connected"] { --mon-status-text: var(--bn-success-700); }
.mon-connection[data-state="lost"] { --mon-status-text: var(--bn-danger-700); }
.mon-statusbar:has([data-state="connecting"]), .mon-statusbar:has([data-state="reconnecting"]) { --mon-status-color: var(--bn-ringing-400); }
.mon-statusbar:has([data-state="connected"]) { --mon-status-color: var(--bn-success-700); }
.mon-statusbar:has([data-state="lost"]) { --mon-status-color: var(--bn-danger-700); background: var(--bn-danger-100); }
.mon-connection[data-state="connecting"] .mon-connection__dot,
.mon-connection[data-state="reconnecting"] .mon-connection__dot { animation: mon-blink 1.2s ease-in-out infinite; }
@keyframes mon-blink { 50% { opacity: .3; } }

/* ---------- Layout ---------- */
.mon-layout { display: grid; gap: var(--bn-space-4); grid-template-columns: minmax(0, 1fr); align-items: start; }
.mon-main, .mon-aside { display: grid; gap: var(--bn-space-4); min-width: 0; }
.mon-main > .bn-card + .bn-card, .mon-aside > .bn-card + .bn-card { margin-top: 0; }
@media (min-width: 1240px) {
  .mon-layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .mon-aside { position: sticky; top: calc(var(--bn-topbar-height) + 88px); }
}
.mon-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--bn-space-2) var(--bn-space-3); margin-bottom: var(--bn-space-4); }
.mon-card-head h2 { margin: 0 !important; display: flex; align-items: center; gap: var(--bn-space-2); }
.mon-card-head h2 .bn-icon { color: var(--bn-brand-600); }
.mon-card-head__end { margin-left: auto; display: flex; align-items: center; gap: var(--bn-space-2); }
.mon-eyebrow { margin: 0 0 var(--bn-space-3) !important; font-size: var(--bn-text-xs) !important; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--bn-text-muted); }

/* ---------- Ligação em destaque ---------- */
.mon-spotlight { position: relative; overflow: hidden; border-left: 8px solid var(--mon-tone, var(--bn-ink-200)); }
.mon-spotlight[data-tone="ringing"] { --mon-tone: var(--bn-ringing-400); background: linear-gradient(var(--bn-ringing-100), var(--bn-surface) 70%); }
.mon-spotlight[data-tone="answered"] { --mon-tone: var(--bn-success-700); }
.mon-spotlight[data-tone="missed"] { --mon-tone: var(--bn-danger-700); }
.mon-spotlight[data-tone="ended"] { --mon-tone: var(--bn-ink-300); }
.mon-spotlight__top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--bn-space-2) var(--bn-space-3); }
.mon-spotlight__top .bn-badge { font-size: var(--bn-text-sm); padding: 4px var(--bn-space-3); }
.mon-spotlight__source { font-weight: 650; }
.mon-spotlight__number {
  margin: var(--bn-space-2) 0 var(--bn-space-3) !important;
  font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: clamp(1.75rem, 0.6rem + 6vw, 4.5rem); line-height: 1.05; letter-spacing: -0.01em; color: var(--bn-ink-950);
  overflow-wrap: break-word;
}
.mon-spotlight__number--hidden { font-family: var(--bn-font); font-size: clamp(1.375rem, 1rem + 1.6vw, 2rem); font-weight: 650; color: var(--bn-ink-600); }
.mon-spotlight__footer { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--bn-space-3); }
.mon-spotlight .bn-btn { min-height: 48px; padding-inline: var(--bn-space-5); font-size: var(--bn-text-md); }
.mon-spotlight__empty { display: flex; align-items: center; gap: var(--bn-space-4); color: var(--bn-text-muted); }
.mon-spotlight__empty .bn-state__icon { margin: 0; flex: none; }
.mon-spotlight__empty p { margin: 0 !important; }
.mon-spotlight__empty strong { display: block; color: var(--bn-text); font-size: var(--bn-text-lg); }

/* Fatos da ligação (horário e durações) */
.mon-facts { display: flex; flex-wrap: wrap; gap: var(--bn-space-1) var(--bn-space-5); margin: 0; }
.mon-facts > div { display: flex; flex-direction: column; }
.mon-facts dt { font-size: var(--bn-text-xs); color: var(--bn-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.mon-facts dd { margin: 0; font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.mon-facts dd.is-unavailable { font-family: var(--bn-font); font-weight: 500; font-style: italic; color: var(--bn-text-muted); }

/* ---------- Fila de ligações ---------- */
.mon-queue { display: grid; gap: var(--bn-space-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); color: var(--bn-text-muted); }
.call-row {
  display: flex; flex-direction: column; gap: var(--bn-space-2);
  padding: var(--bn-space-4); border: 1px solid var(--bn-border); border-top: 4px solid var(--mon-tone, var(--bn-ink-200));
  border-radius: var(--bn-radius); background: var(--bn-surface); color: var(--bn-text);
}
.call-row p { margin: 0 !important; }
.call-row[data-state="ringing"] { --mon-tone: var(--bn-ringing-400); background: var(--bn-ringing-100); border-color: #f3d79f; border-top-color: var(--bn-ringing-400); }
.call-row[data-state="answered"] { --mon-tone: var(--bn-success-700); }
.call-row[data-state="missed"] { --mon-tone: var(--bn-danger-700); }
.call-row[data-state="ended"] { --mon-tone: var(--bn-ink-300); }
.mon-call__head { display: flex; align-items: center; justify-content: space-between; gap: var(--bn-space-2); }
.mon-call__time { font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-size: var(--bn-text-sm); color: var(--bn-ink-600); }
.mon-call__number { font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-size: var(--bn-text-xl); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.mon-call__number--hidden { font-family: var(--bn-font); font-size: var(--bn-text-md); font-weight: 600; color: var(--bn-ink-600); }
.mon-call__source { font-size: var(--bn-text-sm); color: var(--bn-ink-600); }
.call-row .mon-facts { font-size: var(--bn-text-sm); gap: var(--bn-space-1) var(--bn-space-4); }
.mon-call__feedback { font-size: var(--bn-text-sm); }
.mon-call__feedback--opened { color: var(--bn-success-700); }
.mon-call__feedback--warning { color: var(--bn-ringing-700); font-weight: 600; }
.call-row .bn-btn { align-self: flex-start; margin-top: auto; }
.call-row .bn-cliente { padding: var(--bn-space-2) 0; border-top: 1px dashed var(--bn-ink-200); border-bottom: 1px dashed var(--bn-ink-200); }
.call-row .bn-cliente .bn-btn { margin-top: 0; }
.mon-spotlight__cliente { margin-bottom: var(--bn-space-3); font-size: var(--bn-text-md); }
.mon-spotlight__cliente .bn-cliente__name { font-size: var(--bn-text-xl); }
.mon-spotlight .bn-cliente .bn-btn { min-height: 40px; font-size: var(--bn-text-sm); padding-inline: var(--bn-space-4); }

/* ---------- Eventos recentes ---------- */
.mon-filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--bn-space-2) var(--bn-space-3); margin-bottom: var(--bn-space-4); }
.mon-filter__field { flex: 1 1 260px; display: flex; flex-direction: column; gap: var(--bn-space-1); }
.mon-filter label { font-size: var(--bn-text-sm); font-weight: 600; }
.mon-filter small { color: var(--bn-text-muted); font-size: var(--bn-text-xs); }
.mon-input, .mon-select {
  display: block; width: 100%; padding: var(--bn-space-2) var(--bn-space-3);
  font: inherit; font-size: var(--bn-text-sm); color: var(--bn-text);
  background: var(--bn-surface); border: 1px solid var(--bn-ink-300); border-radius: var(--bn-radius-sm);
}
.mon-select option { padding: 4px var(--bn-space-2); border-radius: 4px; }
.mon-select option:checked { background: var(--bn-brand-100); color: var(--bn-brand-700); }
.mon-input:hover, .mon-select:hover { border-color: var(--bn-ink-500); }

.event-list { display: grid; gap: var(--bn-space-2); max-height: min(70vh, 720px); overflow-y: auto; padding: 2px; margin: -2px; }
.event-item {
  display: flex; align-items: flex-start; gap: var(--bn-space-3);
  padding: var(--bn-space-3) var(--bn-space-4); border: 1px solid var(--bn-border); border-left: 4px solid var(--mon-tone, var(--bn-ink-200));
  border-radius: var(--bn-radius-sm); background: var(--bn-surface);
}
.event-item[data-tone="received"] { --mon-tone: var(--bn-info-700); }
.event-item[data-tone="answered"] { --mon-tone: var(--bn-success-700); }
.event-item[data-tone="missed"] { --mon-tone: var(--bn-danger-700); }
.event-item[data-tone="ended"] { --mon-tone: var(--bn-ink-300); }
.event-item.realtime { background: var(--bn-brand-50); }
.mon-event__body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.event-item p { margin: 0 !important; }
.mon-event__line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--bn-space-1) var(--bn-space-3); }
.mon-event__line .bn-badge { font-size: var(--bn-text-xs); }
.mon-event__number { font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-weight: 650; font-size: var(--bn-text-md); }
.mon-event__number--hidden { font-family: var(--bn-font); font-weight: 500; color: var(--bn-ink-600); }
.event-time { font-family: var(--bn-font-mono); font-variant-numeric: tabular-nums; font-size: var(--bn-text-sm); color: var(--bn-ink-600); }
.mon-event__meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--bn-space-3); font-size: var(--bn-text-sm); color: var(--bn-ink-600); }
.mon-event__meta details summary { cursor: pointer; color: var(--bn-ink-600); }
.mon-event__meta details[open] summary { margin-bottom: 2px; }
.mon-event__since { font-size: var(--bn-text-sm); color: var(--bn-info-700); }
.portal-button { flex: none; }
.empty-state { margin: var(--bn-space-5) auto !important; text-align: center; color: var(--bn-text-muted); }

/* ---------- Abertura do portal (preferências deste navegador) ---------- */
.mon-settings p { font-size: var(--bn-text-sm); color: var(--bn-text-muted); }
.mon-settings legend { font-size: var(--bn-text-sm); font-weight: 650; margin-bottom: var(--bn-space-2); color: var(--bn-text); }
.mon-sources { display: grid; gap: var(--bn-space-1); margin-bottom: var(--bn-space-4) !important; }
.mon-check {
  display: flex; align-items: center; gap: var(--bn-space-3); min-height: 40px; padding: var(--bn-space-1) var(--bn-space-3);
  border: 1px solid var(--bn-border); border-radius: var(--bn-radius-sm); cursor: pointer; font-size: var(--bn-text-sm);
}
.mon-check:hover { border-color: var(--bn-brand-600); }
.mon-check:has(input:checked) { background: var(--bn-brand-50); border-color: var(--bn-brand-600); font-weight: 600; }
.mon-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--bn-brand-600); }
.mon-settings label[for="portalTemplate"] { display: block; font-size: var(--bn-text-sm); font-weight: 650; margin-bottom: var(--bn-space-1); }
.mon-settings .mon-input { font-family: var(--bn-font-mono); font-size: var(--bn-text-xs); margin-bottom: var(--bn-space-3); }
.mon-settings .bn-btn { width: 100%; }
#portalSettingsStatus { margin: var(--bn-space-3) 0 0 !important; }
#portalPending:empty { display: none; }
#portalPending { display: grid; gap: var(--bn-space-2); }
#portalPending .bn-alert { margin: 0; }

/* ---------- Aviso flutuante de novo evento ---------- */
.mon-toast {
  position: fixed; z-index: 1001; top: calc(var(--bn-topbar-height) + var(--bn-space-3)); right: var(--bn-space-4);
  display: flex; gap: var(--bn-space-3); align-items: flex-start; max-width: min(400px, calc(100vw - 2rem));
  padding: var(--bn-space-3) var(--bn-space-4); border-radius: var(--bn-radius); border: 1px solid var(--bn-border);
  border-left: 4px solid var(--bn-brand-600); background: var(--bn-surface); box-shadow: var(--bn-shadow-lg);
}
.mon-toast strong { display: block; }
.mon-toast small { font-size: var(--bn-text-sm); color: var(--bn-ink-600); }
.mon-toast .bn-icon { color: var(--bn-brand-600); margin-top: 2px; }
.mon-toast--warning { border-left-color: var(--bn-ringing-400); }
.mon-toast--warning .bn-icon { color: var(--bn-ringing-700); }
.mon-toast--error { border-left-color: var(--bn-danger-700); }
.mon-toast--error .bn-icon { color: var(--bn-danger-700); }

@media (max-width: 960px) {
  .mon-statusbar { top: calc(var(--bn-topbar-height) + var(--bn-space-1)); }
}
@media (max-width: 480px) {
  .mon-statusbar { padding-left: var(--bn-space-3); }
  .mon-statusbar .bn-btn { width: 100%; }
  .event-item { flex-wrap: wrap; }
  .mon-spotlight .bn-btn { width: 100%; }
}
