/* =========================================================
   Sentinela Monitor — design tokens
   Conceito: sala de controle (NOC) — sinal de pulso ao vivo
   ========================================================= */

:root {
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(0,0,0,.24), 0 8px 24px -12px rgba(0,0,0,.35);
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #0B0F14;
  --surface: #131922;
  --surface-alt: #1B232F;
  --surface-hover: #202B39;
  --border: #232C38;
  --text: #E7ECF2;
  --text-dim: #8B98A9;
  --accent: #5EEAD4;
  --accent-dim: rgba(94, 234, 212, .14);
  --up: #34D399;
  --up-dim: rgba(52, 211, 153, .14);
  --down: #FB6F5C;
  --down-dim: rgba(251, 111, 92, .14);
  --warn: #FBBF24;
  --warn-dim: rgba(251, 191, 36, .14);
}

[data-theme="light"] {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface-alt: #EEF2F6;
  --surface-hover: #E5EAF0;
  --border: #E2E8F0;
  --text: #101828;
  --text-dim: #667085;
  --accent: #0F9B8E;
  --accent-dim: rgba(15, 155, 142, .10);
  --up: #059669;
  --up-dim: rgba(5, 150, 105, .10);
  --down: #DC2626;
  --down-dim: rgba(220, 38, 38, .10);
  --warn: #D97706;
  --warn-dim: rgba(217, 119, 6, .10);
  --shadow-card: 0 1px 2px rgba(16,24,40,.04), 0 6px 18px -10px rgba(16,24,40,.15);
}

* { box-sizing: border-box; }

/* Garante que [hidden] sempre vença, mesmo em elementos cuja classe define
   display:flex/grid (ex: .app, .auth-form, .qr-box, .user-dropdown) — sem isso,
   o atributo hidden é ignorado e vários blocos aparecem abertos ao mesmo tempo. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background var(--transition), color var(--transition);
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim);
  color: var(--accent);
}

.status-strip {
  display: flex;
  gap: 18px;
  margin-right: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.strip-item { display: flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-up { background: var(--up); box-shadow: 0 0 0 3px var(--up-dim); }
.dot-down { background: var(--down); box-shadow: 0 0 0 3px var(--down-dim); }
.dot-pending { background: var(--text-dim); box-shadow: 0 0 0 3px rgba(139,152,169,.14); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 80ms;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #06231F; }
[data-theme="light"] .btn-primary { color: #ffffff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-alt); }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------- Main / summary ---------- */

main { padding: 24px 28px 60px; max-width: 1320px; margin: 0 auto; width: 100%; }

.summary-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.summary-card .label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
}
.summary-card .value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
}
.summary-card.up .value { color: var(--up); }
.summary-card.down .value { color: var(--down); }

/* ---------- Monitor grid & card ---------- */

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.monitor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}
.monitor-card[data-status="down"] { border-color: var(--down); }
.monitor-card[data-status="down"]::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--down);
}
.monitor-card[data-status="up"]::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--up);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.card-title { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-title h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-target {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 100px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-badge.up { color: var(--up); background: var(--up-dim); }
.status-badge.down { color: var(--down); background: var(--down-dim); }
.status-badge.pending { color: var(--text-dim); background: var(--surface-alt); }
.status-badge .pulse-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.status-badge.up .pulse-dot { animation: pulseDot 1.6s infinite; }

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* sinal / sparkline */
.pulse-strip { width: 100%; height: 46px; }
.pulse-strip svg { width: 100%; height: 100%; display: block; }
.pulse-strip .line-up { stroke: var(--up); }
.pulse-strip .line-down { stroke: var(--down); }
.pulse-strip .line-pending { stroke: var(--text-dim); }
.pulse-strip .fill-up { fill: var(--up-dim); }
.pulse-strip .fill-down { fill: var(--down-dim); }

.card-stats {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}
.card-stats b { color: var(--text); font-weight: 600; }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: -2px;
}
.card-actions button {
  flex: 1;
  font-size: 12px;
  padding: 7px 10px;
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty-title { font-family: var(--font-display); font-size: 20px; color: var(--text); margin-bottom: 8px; }
.empty-sub { max-width: 420px; margin: 0 auto 20px; font-size: 14px; line-height: 1.5; }

/* ---------- Modals ---------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(480px, 92vw);
}
.modal::backdrop { background: rgba(4,7,10,.55); backdrop-filter: blur(2px); }

.modal-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-card h2 { font-family: var(--font-display); font-size: 18px; margin: 0 0 2px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); flex: 1; }
.field input, .field select {
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
.field-checkbox { gap: 8px; }
.field-row { display: flex; gap: 12px; }
.field-hint { font-size: 12px; color: var(--text-dim); margin: -6px 0 0; line-height: 1.4; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-actions-split { justify-content: space-between; align-items: center; }

/* ---------- Tabs (modal configurações) ---------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.tab-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 4px;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }

details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary:before { content: '▸ '; }
details[open] summary:before { content: '▾ '; }

/* ---------- QR Code box ---------- */

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}
.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 10px;
  background: #ffffff;
  padding: 10px;
  box-shadow: var(--shadow-card);
}
.qr-status {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0;
  text-align: center;
}

.connected-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--up-dim);
}

/* ---------- Tela de login / primeiro acesso ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.auth-brand { justify-content: center; font-size: 21px; margin-bottom: 2px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { font-family: var(--font-display); font-size: 18px; margin: 0; text-align: center; }

/* ---------- Menu do usuário ---------- */

.user-menu { position: relative; }
.user-menu-btn {
  border-radius: 50%;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  background: var(--accent-dim);
  color: var(--accent);
  border-color: transparent;
}
.user-dropdown {
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 8px;
  width: 200px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-dropdown-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  word-break: break-all;
}
.dropdown-item {
  text-align: left;
  background: none;
  border: none;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-alt); }
.dropdown-item-danger { color: var(--down); }

/* ---------- Tabela de usuários ---------- */

.users-table { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.user-row-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.user-row-info b { font-size: 13.5px; }
.user-row-info span { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-dim); }
.user-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-row-actions button {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.user-row-actions button:hover { background: var(--surface-hover); }
.user-row-actions .danger { color: var(--down); border-color: var(--down); }

.divider { border: none; border-top: 1px solid var(--border); margin: 2px 0; }
.modal-subtitle { font-family: var(--font-display); font-size: 14.5px; margin: 0 0 -4px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-card);
  z-index: 100;
}
.toast.error { border-color: var(--down); color: var(--down); }
.toast.success { border-color: var(--up); color: var(--up); }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; gap: 12px; }
  main { padding: 18px 16px 40px; }
  .status-strip { order: 3; width: 100%; justify-content: space-between; margin-right: 0; }
  .field-row { flex-direction: column; }
}

/* respeita usuários que preferem menos movimento */
@media (prefers-reduced-motion: reduce) {
  .status-badge.up .pulse-dot { animation: none; }
  * { transition: none !important; }
}
