/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Dark (default) */
  --bg:           #080808;
  --bg-2:         #0E0E0E;
  --card:         #111111;
  --card-hover:   #161616;
  --border:       #1C1C1C;
  --border-hi:    #2E2E2E;
  --text:         #EDEDED;
  --text-muted:   #666666;
  --text-dim:     #2E2E2E;
  --accent:       #FFFFFF;
  --btn-bg:       #FFFFFF;
  --btn-text:     #000000;
  --btn-hover:    #E0E0E0;
  --input-bg:     #0E0E0E;
  --input-border: #242424;
  --input-focus:  #3E3E3E;
  --on:           #34D399;
  --on-bg:        rgba(52, 211, 153, 0.08);
  --off:          #F87171;
  --off-bg:       rgba(248, 113, 113, 0.08);
  --warn:         #FBBF24;

  /* Chart */
  --color-total:  #EDEDED;
  --color-esp:    #818CF8;
  --color-pac:    #34D399;
  --chart-grid:   rgba(255,255,255,0.04);
  --chart-tick:   #444;

  /* Sizes */
  --header-h:     56px;
  --radius:       0px;  /* Sharp corners — heon brand */

  /* Transitions */
  --t:            160ms ease;

  font-family: 'Syne', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

[data-theme="light"] {
  --bg:           #F2F2F2;
  --bg-2:         #EBEBEB;
  --card:         #FFFFFF;
  --card-hover:   #FAFAFA;
  --border:       #E4E4E4;
  --border-hi:    #C8C8C8;
  --text:         #0A0A0A;
  --text-muted:   #888888;
  --text-dim:     #DDDDDD;
  --accent:       #000000;
  --btn-bg:       #0A0A0A;
  --btn-text:     #FFFFFF;
  --btn-hover:    #222222;
  --input-bg:     #FFFFFF;
  --input-border: #D8D8D8;
  --input-focus:  #A0A0A0;
  --on:           #059669;
  --on-bg:        rgba(5, 150, 105, 0.07);
  --off:          #DC2626;
  --off-bg:       rgba(220, 38, 38, 0.07);
  --warn:         #D97706;
  --chart-grid:   rgba(0,0,0,0.05);
  --chart-tick:   #AAAAAA;
}

/* ── Logo inversion for light mode ──────────────────────────────────────────── */
[data-theme="light"] .login-logo,
[data-theme="light"] .header-logo {
  filter: invert(1);
}

/* ── Theme icon visibility ───────────────────────────────────────────────────── */
[data-theme="dark"]  .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: block; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: block; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ════════════════════════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════════════════════ */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: background var(--t), color var(--t);
  overflow: hidden;
}

/* Subtle grid texture */
.login-body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.4;
  pointer-events: none;
}

.login-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 24px;
  animation: fadeUp 0.4s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-panel {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 40px 36px;
  transition: background var(--t), border-color var(--t);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 36px;
}

.login-logo {
  height: 22px;
  width: auto;
  object-fit: contain;
  transition: filter var(--t);
}

.login-brand-sep {
  width: 1px;
  height: 24px;
  background: var(--border-hi);
}

.login-brand-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.login-lia {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
  line-height: 1;
}

.login-dashboard {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  line-height: 1;
}

.login-header {
  margin-bottom: 28px;
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.login-header p {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-group label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field-group input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
  padding: 11px 14px;
  outline: none;
  transition: border-color var(--t), background var(--t);
}

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

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  padding-right: 40px;
}

.toggle-pw {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color var(--t);
}

.toggle-pw:hover { color: var(--text); }

.login-error {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--off);
  min-height: 0;
  transition: all var(--t);
}

.login-error:empty { display: none; }

.btn-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  padding: 13px 20px;
  font-family: 'Syne', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--t), opacity var(--t), transform 80ms;
  margin-top: 4px;
}

.btn-login:hover  { background: var(--btn-hover); }
.btn-login:active { transform: scale(0.99); }
.btn-login:disabled { opacity: 0.5; cursor: not-allowed; }

/* Theme toggle in login corner */
.theme-toggle-corner {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color var(--t), border-color var(--t), background var(--t);
}

.theme-toggle-corner:hover { color: var(--text); border-color: var(--border-hi); }

/* ════════════════════════════════════════════════════════════════════════════
   DASHBOARD
════════════════════════════════════════════════════════════════════════════ */

.dash-body {
  min-height: 100vh;
  background: var(--bg);
  transition: background var(--t), color var(--t);
}

/* ── Header ──────────────────────────────────────────────────────────────────── */

.dash-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  transition: background var(--t), border-color var(--t);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  height: 18px;
  width: auto;
  object-fit: contain;
  transition: filter var(--t);
}

.header-critical {
  display: flex;
  align-items: center;
  gap: 20px;
  flex: 1;
  justify-content: center;
  padding: 0 24px;
  flex-wrap: wrap;
}

.critical-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
  cursor: default;
  white-space: nowrap;
}

.critical-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.critical-dot--open       { background: var(--on); }
.critical-dot--connecting { background: var(--warn); animation: ws-dot-pulse 1.2s ease-in-out infinite; }
.critical-dot--close      { background: var(--off); }
.critical-dot--unknown    { background: var(--text-dim); }

.critical-name {
  transition: color var(--t);
}

.critical-item:has(.critical-dot--close) .critical-name,
.critical-item:has(.critical-dot--connecting) .critical-name {
  color: var(--text);
}

.header-sep {
  width: 1px;
  height: 22px;
  background: var(--border-hi);
}

.header-title {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.header-lia {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text);
}

.header-sub {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.interval-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-right: 1px solid var(--border);
  margin-right: 4px;
}

.interval-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.interval-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--card);
  border: 1px solid var(--border-hi);
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  padding: 4px 22px 4px 8px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--t), color var(--t);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.interval-select:hover { border-color: var(--text-muted); color: var(--text); }
.interval-select option { background: var(--card); color: var(--text); }

.header-update {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0 10px;
  margin-right: 4px;
}

.header-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color var(--t), border-color var(--t), background var(--t);
}

.header-btn:hover {
  color: var(--text);
  border-color: var(--border-hi);
  background: var(--card-hover);
}

.header-btn--logout:hover { color: var(--off); border-color: var(--off); }

/* ── Main content ────────────────────────────────────────────────────────────── */

.dash-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Stats grid ──────────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: background var(--t), border-color var(--t), transform 80ms;
  animation: fadeUp 0.4s ease calc(var(--delay, 0ms)) both;
}

.stat-card:hover {
  border-color: var(--border-hi);
  background: var(--card-hover);
}

.stat-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--t), border-color var(--t);
}

.stat-body {
  min-width: 0;
  flex: 1;
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-family: 'DM Mono', monospace;
  font-size: 1.85rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
  margin-bottom: 5px;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Section headers ─────────────────────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.section-header--inline {
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  margin-bottom: 3px;
}

.section-title p {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Chart section ───────────────────────────────────────────────────────────── */

.chart-section {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 24px;
  transition: background var(--t), border-color var(--t);
  animation: fadeUp 0.4s ease 240ms both;
}

.chart-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  padding: 5px 12px;
  background: none;
  border: 1px solid var(--border-hi);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t);
  letter-spacing: 0.04em;
}

.filter-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.filter-btn--active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.filter-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--border-hi);
  margin: 0 4px;
  vertical-align: middle;
  align-self: center;
}

.chart-legend {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-wrapper {
  position: relative;
  height: 280px;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  z-index: 2;
  background: var(--card);
}

.chart-loading.hidden { display: none; }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-hi);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Bottom grid ─────────────────────────────────────────────────────────────── */

.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  animation: fadeUp 0.4s ease 300ms both;
}

.table-section {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  transition: background var(--t), border-color var(--t);
  min-height: 360px;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 400px;
}

.table-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

/* ── Data tables ─────────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
}

.data-table th {
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}

.data-table th:not(:first-child) { text-align: right; }

.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
  transition: background var(--t);
}

.data-table td:not(:first-child) { text-align: right; }

.data-table tbody tr:hover td { background: var(--card-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .col-id {
  font-size: 0.72rem;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table .col-num {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.data-table .col-num--hi {
  color: var(--text);
  font-weight: 500;
}

.data-table .col-num--muted {
  color: var(--text-muted);
}

.data-table .col-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.data-table .rank {
  font-size: 0.65rem;
  color: var(--text-dim);
  width: 28px;
  text-align: right;
}

/* ── Status badges ───────────────────────────────────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 3px 8px;
}

.status-badge--on  { color: var(--on);  background: var(--on-bg); }
.status-badge--off { color: var(--off); background: var(--off-bg); }

.status-dot-sm {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot-sm--on  { background: var(--on); }
.status-dot-sm--off { background: var(--off); }

/* ── Instances filter row ────────────────────────────────────────────────────── */

.inst-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* ── Sortable column headers ─────────────────────────────────────────────────── */

.data-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--t);
}

.data-table th.th-sortable:hover { color: var(--text); }

.sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.6rem;
  color: var(--text-dim);
  vertical-align: middle;
  transition: color var(--t);
}

.sort-icon--active { color: var(--text-muted); }

/* ── Empty state ─────────────────────────────────────────────────────────────── */

.empty-state {
  padding: 40px;
  text-align: center;
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Refresh animation ───────────────────────────────────────────────────────── */

.header-btn.refreshing svg {
  animation: spin 0.7s linear infinite;
}

/* ── Tab bar ─────────────────────────────────────────────────────────────────── */

.tab-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: background var(--t), border-color var(--t);
}

.tab-bar__tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar__tabs::-webkit-scrollbar { display: none; }

.tab-bar__controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  border-left: 1px solid var(--border);
  position: absolute;
  right: 0;
  top: 0;
  bottom: 2px;
  background: var(--bg-2);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 20px;
  height: 42px;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: color var(--t), background var(--t);
  flex-shrink: 0;
}

.tab-btn:hover { color: var(--text); background: var(--card-hover); }

.tab-btn--active {
  color: var(--text);
  background: var(--card);
}

.tab-btn--active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 2px;
  background: var(--text);
}

.tab-btn--alert { color: var(--off); }
.tab-btn--alert.tab-btn--active { color: var(--off); }
.tab-btn--alert.tab-btn--active::after { background: var(--off); }
.tab-btn--alert:hover { color: var(--off); }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--off);
  color: #fff;
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 9px;
  animation: fadeUp 0.2s ease both;
}

/* Tab progress bar */
.tab-progress-track {
  height: 2px;
  background: var(--border);
  overflow: hidden;
}

.tab-progress-bar {
  height: 100%;
  background: var(--text);
  transform-origin: left;
  transform: scaleX(1);
}

/* Tab panes */
.tab-pane {
  display: none;
  flex-direction: column;
  gap: 20px;
}

.tab-pane--active {
  display: flex;
}

/* Alert count card (Alertas tab) */
.alert-count-card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 28px 32px;
  transition: background var(--t), border-color var(--t);
  animation: fadeUp 0.3s ease both;
}

.alert-count-inner {
  display: flex;
  align-items: center;
  gap: 28px;
}

.alert-count-num {
  font-family: 'DM Mono', monospace;
  font-size: 4rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  min-width: 80px;
  flex-shrink: 0;
  transition: color var(--t);
}

.alert-count-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.alert-count-sub {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Pause icon toggle */
[data-paused] .icon-pause { display: none; }
[data-paused] .icon-play  { display: block !important; }

/* ── WhatsApp status section ─────────────────────────────────────────────────── */

.section-tag--consult {
  color: #22C55E;
  border-color: rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.05);
}

.stats-grid--4c {
  grid-template-columns: repeat(4, 1fr);
}

.stat-icon--confirm { color: #22C55E; }
.stat-icon--cancel  { color: #F87171; }

.chart-section--consult {
  /* herda de .chart-section */
}

.section-tag--ws {
  color: #60A5FA;
  border-color: rgba(96, 165, 250, 0.3);
  background: rgba(96, 165, 250, 0.05);
}

/* Alert banner */
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 20px;
  background: rgba(245, 158, 11, 0.07);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-left: 3px solid #F59E0B;
  color: #F59E0B;
  animation: fadeUp 0.3s ease both, ws-blink 2.4s ease-in-out infinite;
}

@keyframes ws-blink {
  0%, 100% { border-left-color: #F59E0B; }
  50%       { border-left-color: rgba(245, 158, 11, 0.3); }
}

.alert-banner__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.alert-banner__msg {
  font-family: 'Syne', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
}

.alert-banner__sub {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* WS section card */
.ws-section {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  transition: background var(--t), border-color var(--t);
  animation: fadeUp 0.4s ease 200ms both;
}

.ws-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.ws-card {
  padding: 16px 20px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  transition: border-color var(--t), background var(--t);
}

.ws-card--open      { border-color: rgba(52, 211, 153, 0.15); background: rgba(52, 211, 153, 0.03); }
.ws-card--connecting { border-color: rgba(245, 158, 11, 0.15); background: rgba(245, 158, 11, 0.03); }
.ws-card--close      { border-color: rgba(248, 113, 113, 0.15); background: rgba(248, 113, 113, 0.03); }

/* Elevated state when connecting > 0 */
.ws-card--connecting.ws-card--alert {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.07);
}

.ws-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ws-card-lbl {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.ws-card-val {
  font-family: 'DM Mono', monospace;
  font-size: 2.2rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
}

.ws-card--open .ws-card-val      { color: var(--on); }
.ws-card--connecting .ws-card-val { color: var(--warn); }
.ws-card--close .ws-card-val      { color: var(--off); }

/* Status dots on cards */
.ws-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ws-dot--open       { background: var(--on); }
.ws-dot--connecting { background: var(--warn); animation: ws-dot-pulse 1.2s ease-in-out infinite; }
.ws-dot--close      { background: var(--off); }

@keyframes ws-dot-pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.6); opacity: 0.5; }
}

/* Status badges in table */
.ws-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 3px 9px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.ws-badge--open       { color: var(--on);   background: var(--on-bg); }
.ws-badge--connecting { color: var(--warn);  background: rgba(245, 158, 11, 0.08); }
.ws-badge--close      { color: var(--off);   background: var(--off-bg); }

/* Pulsing dot inside "connecting" badge */
.ws-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
  animation: ws-dot-pulse 1.2s ease-in-out infinite;
}

/* Connecting rows get a subtle left border */
.ws-row--connecting td:first-child {
  border-left: 2px solid rgba(245, 158, 11, 0.5);
}

/* Section label / tag ─────────────────────────────────────────────────────── */

.section-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-tag {
  font-family: 'DM Mono', monospace;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 3px 8px;
  border: 1px solid var(--border-hi);
  background: var(--bg-2);
}

.section-tag--tokens {
  color: #F59E0B;
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.05);
}

/* ── 3-column stats grid (tokens row) ───────────────────────────────────────── */

.stats-grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.stat-icon--tokens {
  color: #F59E0B;
}

.stat-value--usd {
  color: #F59E0B;
}

/* ── Tokens chart + table side-by-side ───────────────────────────────────────── */

.tokens-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  animation: fadeUp 0.4s ease 360ms both;
}

.chart-section--tokens {
  /* Inherits from .chart-section */
}

.chart-wrapper--sm {
  height: 220px;
}

/* ── USD column in tables ────────────────────────────────────────────────────── */

.usd-col {
  color: #F59E0B !important;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */

/* ─ Tablet largo (≤1100px) ─────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid       { grid-template-columns: repeat(2, 1fr); }
  .stats-grid--3    { grid-template-columns: repeat(3, 1fr); }
  .stats-grid--4c   { grid-template-columns: repeat(2, 1fr); }
  .bottom-grid      { grid-template-columns: 1fr; }
  .tokens-grid      { grid-template-columns: 1fr; }
  .header-critical  { gap: 14px; }
}

/* ─ Tablet (≤768px) ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header: esconde itens secundários */
  .header-update  { display: none; }
  .interval-wrap  { display: none; }

  /* Critical: só dots, sem nome */
  .header-critical { gap: 12px; padding: 0 10px; }
  .critical-name   { display: none; }
  .critical-dot    { width: 10px; height: 10px; }

  /* Tab bar compacto */
  .tab-btn         { padding: 0 14px; font-size: 0.68rem; height: 38px; }
  .tab-bar__controls { padding: 4px 10px; }

  /* Stats */
  .stats-grid--3   { grid-template-columns: repeat(3, 1fr); }
  .stat-value      { font-size: 1.5rem; }
  .stat-card       { padding: 16px 14px; }

  /* Gráficos */
  .chart-wrapper   { height: 220px; }
  .chart-wrapper--sm { height: 180px; }

  /* Seções */
  .chart-section, .table-section, .ws-section { padding: 16px; }

  /* WS cards */
  .ws-card-val     { font-size: 1.8rem; }

  /* Alert count */
  .alert-count-num { font-size: 3rem; }
}

/* ─ Phone (≤640px) ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --header-h: 48px; }

  /* Header */
  .dash-header     { padding: 0 12px; }
  .header-critical { display: none; }          /* sem espaço no header */
  .header-sep      { display: none; }
  .header-sub      { display: none; }
  .header-lia      { font-size: 0.8rem; }

  /* Tab bar */
  .tab-btn         { padding: 0 10px; height: 36px; font-size: 0.62rem; gap: 4px; }
  .tab-btn svg     { display: none; }          /* esconde ícones */
  .tab-bar__controls { gap: 2px; padding: 3px 8px; }

  /* Main */
  .dash-main       { padding: 10px; gap: 10px; }

  /* Stats */
  .stats-grid,
  .stats-grid--4c  { grid-template-columns: 1fr 1fr; }
  .stats-grid--3   { grid-template-columns: 1fr 1fr; }
  .stat-card       { padding: 12px 10px; gap: 8px; }
  .stat-icon       { width: 28px; height: 28px; }
  .stat-value      { font-size: 1.25rem; }
  .stat-label      { font-size: 0.58rem; }
  .stat-meta       { font-size: 0.63rem; }

  /* Gráficos */
  .chart-wrapper   { height: 180px; }
  .chart-wrapper--sm { height: 160px; }
  .chart-legend    { gap: 10px; flex-wrap: wrap; }
  .legend-item     { font-size: 0.62rem; }
  .chart-section   { padding: 14px 12px; }

  /* Filtros */
  .filter-btn      { font-size: 0.65rem; padding: 4px 9px; }

  /* Tabelas */
  .table-section   { padding: 12px 10px; }
  .data-table      { font-size: 0.72rem; }
  .data-table th   { font-size: 0.58rem; padding: 6px 8px; }
  .data-table td   { padding: 7px 8px; }

  /* WS */
  .ws-section      { padding: 12px 10px; }
  .ws-cards        { gap: 8px; }
  .ws-card         { padding: 12px; }
  .ws-card-val     { font-size: 1.8rem; }
  .ws-card-lbl     { font-size: 0.58rem; }

  /* Alert count */
  .alert-count-card  { padding: 18px 14px; }
  .alert-count-inner { flex-direction: column; gap: 10px; }
  .alert-count-num   { font-size: 3rem; min-width: unset; }
  .alert-count-label { font-size: 0.85rem; }

  /* Login */
  .login-panel     { padding: 24px 16px; }
  .login-header h1 { font-size: 1.25rem; }

  /* Seção de status WS crítico (abaixo do header em mobile) */
  .header-critical-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px 12px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
  }
}

/* ─ Phone pequeno (≤400px) ───────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .stats-grid,
  .stats-grid--3,
  .stats-grid--4c  { grid-template-columns: 1fr; }
  .ws-cards        { grid-template-columns: 1fr; }
  .stat-value      { font-size: 1.5rem; }
  .tab-btn         { padding: 0 8px; font-size: 0.6rem; }
}
