:root {
  color-scheme: dark;
  --bg-0: #050b14;
  --bg-1: #08111d;
  --bg-2: #0c1726;
  --surface: rgba(10, 17, 31, 0.72);
  --surface-strong: rgba(10, 17, 31, 0.9);
  --surface-soft: rgba(148, 163, 184, 0.06);
  --border: rgba(148, 163, 184, 0.15);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #e6edf6;
  --muted: #94a3b8;
  --accent: #34d399;
  --accent-2: #22d3ee;
  --accent-3: #8b5cf6;
  --danger: #fb7185;
  --warning: #fbbf24;
  --shadow-xl: 0 28px 80px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(34, 211, 238, 0.12), transparent 28%),
    radial-gradient(circle at 80% 10%, rgba(52, 211, 153, 0.12), transparent 24%),
    radial-gradient(circle at 70% 90%, rgba(139, 92, 246, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 48%, var(--bg-2));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.34;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.15));
}

* {
  box-sizing: border-box;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

::selection {
  background: rgba(52, 211, 153, 0.28);
  color: #f8fafc;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.7), rgba(34, 211, 238, 0.7));
  border-radius: 999px;
  border: 3px solid rgba(15, 23, 42, 0.75);
}

.dashboard-layout,
.chat-layout {
  width: min(1600px, calc(100% - 24px));
  margin: 0 auto;
}

.glass {
  background: linear-gradient(180deg, rgba(11, 18, 34, 0.86), rgba(7, 12, 24, 0.8));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(20px);
}

.surface {
  background: rgba(15, 23, 42, 0.66);
  border: 1px solid rgba(148, 163, 184, 0.14);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 460px);
  border-radius: 30px;
  padding: 28px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #04111b;
  background: linear-gradient(135deg, #34d399 0%, #22d3ee 100%);
  box-shadow: 0 14px 40px rgba(34, 211, 238, 0.18);
}

.hero-title {
  letter-spacing: -0.045em;
  text-wrap: balance;
}

.subtle {
  color: var(--muted);
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 22px;
  padding: 18px 0 30px;
}

.sidebar {
  position: sticky;
  top: 18px;
  align-self: start;
  min-height: calc(100vh - 36px);
  border-radius: 30px;
  padding: 22px;
}

.workspace {
  min-width: 0;
  display: grid;
  gap: 22px;
}

.hero-panel,
.panel,
.metric-panel,
.log-panel,
.feed-panel,
.chat-panel {
  border-radius: 28px;
}

.hero-panel {
  padding: 28px;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 14px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #dbe5f3;
  font-size: 13px;
  font-weight: 700;
}

.chip--accent {
  border-color: rgba(52, 211, 153, 0.24);
  background: rgba(52, 211, 153, 0.12);
  color: #d1fae5;
}

.chip--cyan {
  border-color: rgba(34, 211, 238, 0.24);
  background: rgba(34, 211, 238, 0.12);
  color: #cffafe;
}

.chip--indigo {
  border-color: rgba(129, 140, 248, 0.24);
  background: rgba(129, 140, 248, 0.12);
  color: #e0e7ff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-btn,
button.action-btn,
a.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  padding: 0 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  cursor: pointer;
}

.action-btn:hover {
  transform: translateY(-1px);
}

.action-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(52, 211, 153, 0.7);
  outline-offset: 2px;
}

.action-btn--primary {
  color: #04111b;
  background: linear-gradient(135deg, #34d399 0%, #22d3ee 100%);
  box-shadow: 0 18px 38px rgba(34, 211, 238, 0.18);
}

.action-btn--secondary {
  background: rgba(255, 255, 255, 0.04);
  color: #e5eef8;
}

.action-btn--danger {
  color: #ffe4e6;
  border-color: rgba(251, 113, 133, 0.2);
  background: rgba(251, 113, 133, 0.08);
}

.action-btn--blue {
  color: #e0f2fe;
  border-color: rgba(96, 165, 250, 0.25);
  background: rgba(59, 130, 246, 0.12);
}

.input-field,
textarea,
select {
  width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 23, 0.5);
  color: var(--text);
  padding: 14px 16px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.input-field::placeholder,
textarea::placeholder {
  color: rgba(148, 163, 184, 0.68);
}

.input-field:focus,
textarea:focus,
select:focus {
  border-color: rgba(52, 211, 153, 0.45);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12);
  outline: none;
}

.panel,
.metric-panel,
.log-panel,
.feed-panel,
.chat-panel {
  padding: 22px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.section-label {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.82);
}

.section-title {
  margin: 0;
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.section-copy {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 70ch;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.metric-card {
  padding: 18px;
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
}

.metric-card .label {
  color: rgba(226, 232, 240, 0.75);
  font-size: 13px;
  font-weight: 700;
}

.metric-card .value {
  margin-top: 10px;
  font-size: clamp(28px, 2.4vw, 40px);
  font-weight: 900;
  letter-spacing: -0.05em;
}

.metric-card .hint {
  margin-top: 4px;
  color: rgba(226, 232, 240, 0.62);
  font-size: 12px;
}

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

.grid-2-4 {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

.grid-logs {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}

.chart-shell {
  position: relative;
  min-height: 300px;
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  padding: 18px;
}

.chart-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.stat-pill {
  border-radius: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(2, 6, 23, 0.35);
}

.stat-pill .name {
  color: rgba(148, 163, 184, 0.85);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-pill .stat {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.data-list,
.group-list,
.log-list {
  display: grid;
  gap: 12px;
}

.soft-card {
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(255, 255, 255, 0.03);
  padding: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 12px;
  font-weight: 800;
}

.badge--ready {
  color: #d1fae5;
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.10);
}

.badge--warning {
  color: #fef3c7;
  border-color: rgba(251, 191, 36, 0.24);
  background: rgba(251, 191, 36, 0.10);
}

.badge--danger {
  color: #ffe4e6;
  border-color: rgba(251, 113, 133, 0.24);
  background: rgba(251, 113, 133, 0.10);
}

#toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  max-width: min(440px, calc(100vw - 36px));
  border-radius: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

#logsBox,
#testMessagePreview {
  border-radius: 22px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(2, 6, 23, 0.42);
  color: #dbeafe;
}

#logsBox {
  min-height: 32rem;
  max-height: 32rem;
  overflow: auto;
}

#qrBox {
  min-height: 16rem;
  border-radius: 22px;
  border: 1px dashed rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 23, 0.3);
}

#relayFeed {
  display: grid;
  gap: 14px;
}

#relayFeed article {
  border-radius: 24px !important;
  border: 1px solid rgba(148, 163, 184, 0.14) !important;
  background: rgba(2, 6, 23, 0.42) !important;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

#relayCount,
#botStateCard,
#waStateCard,
#queueStateCard,
#ruleStateCard {
  transition: color 0.18s ease;
}

@media (max-width: 1280px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    top: 0;
    min-height: auto;
  }

  .metrics-grid,
  .chart-toolbar,
  .grid-logs,
  .grid-2,
  .grid-2-4 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .dashboard-layout,
  .chat-layout {
    width: min(100%, calc(100% - 16px));
  }

  .hero-panel,
  .panel,
  .metric-panel,
  .log-panel,
  .feed-panel,
  .chat-panel,
  .sidebar {
    padding: 18px;
    border-radius: 22px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chart-shell {
    min-height: 240px;
  }
}
