:root {
  --bg-primary: #F3EDE8;
  --bg-card: #FFFFFF;
  --bg-card-subtle: #F9F6F3;
  --border-color: rgba(0, 0, 0, 0.06);
  --text-main: #1C1917;
  --text-muted: #78716C;
  --text-light: #A8A29E;
  
  --accent-yellow: #F6C95B;
  --accent-lime: #C8F26A;
  --accent-blue: #3A3F5C;
  --accent-purple: #6D5BD0;
  --accent-green: #3DB070;
  --accent-orange: #F59E0B;
  --accent-red: #EF4444;

  --card-radius: 22px;
  --card-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
  --font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --dot-color: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg-primary: #121214;
  --bg-card: #1C1C20;
  --bg-card-subtle: #24242A;
  --border-color: #2A2A30;
  --text-main: #F4F4F5;
  --text-muted: #A1A1AA;
  --text-light: #71717A;
  --dot-color: rgba(255, 255, 255, 0.03);
  --card-shadow: 0 12px 36px -6px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  background-image: radial-gradient(var(--dot-color) 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  color: var(--text-main);
  min-height: 100vh;
  padding: 18px 24px 40px;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* Privacy Blur Mode */
body.privacy-mode .blur-target {
  filter: blur(5.5px) !important;
  user-select: none;
  transition: filter 0.2s ease;
}

/* Header */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1480px;
  margin: 0 auto 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-purple), #907FFA);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(109, 91, 208, 0.3);
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--card-shadow);
  transition: all 0.15s ease;
}

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

.btn-icon.active {
  background: var(--text-main);
  color: var(--bg-card);
}

/* Layout Grid */
.dashboard-container {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Card base */
.dash-card {
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  padding: 20px;
  position: relative;
  transition: all 0.2s ease;
}

/* Row 1: Health, Now, DNS */
.top-stats-row {
  display: grid;
  grid-template-columns: 280px 360px 1fr;
  gap: 16px;
}

/* Health 24h Card */
.health-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.health-number {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
  color: var(--text-main);
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  width: fit-content;
}

.badge-ok {
  background: rgba(61, 176, 112, 0.12);
  color: var(--accent-green);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-orange);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.12);
  color: var(--accent-red);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* Yellow Card "Now" */
.now-card {
  background: var(--accent-yellow) !important;
  color: #1C1917 !important;
  border: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.now-card .card-label {
  color: rgba(28, 25, 23, 0.7);
}

.now-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.now-item-val {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.now-item-lbl {
  font-size: 12px;
  font-weight: 500;
  color: rgba(28, 25, 23, 0.75);
}

.now-route-box {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* DNS Summary Card */
.dns-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dns-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 6px;
}

.stat-box {
  background: var(--bg-card-subtle);
  padding: 12px 14px;
  border-radius: 14px;
}

.stat-box-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.stat-box-lbl {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

/* Cascade SVG Diagram Section */
.cascade-section {
  padding: 24px;
}

.cascade-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.backup-pill {
  background: var(--accent-lime);
  color: #172A05;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  display: none;
}

.backup-pill.visible {
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(0.98); }
}

.cascade-svg-container {
  width: 100%;
  height: 220px;
  position: relative;
}

svg.cascade-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* SVG Line Animations */
.link-line {
  stroke: #D6D3D1;
  stroke-width: 2.5;
  stroke-dasharray: 6 6;
  fill: none;
  transition: all 0.3s ease;
}

[data-theme="dark"] .link-line {
  stroke: #3F3F46;
}

.link-line.active {
  stroke: var(--accent-purple);
  stroke-width: 3.5;
  animation: dashMove 1s linear infinite;
  filter: drop-shadow(0 0 6px rgba(109, 91, 208, 0.45));
}

@keyframes dashMove {
  to {
    stroke-dashoffset: -12;
  }
}

.node-group rect {
  transition: all 0.2s ease;
  cursor: pointer;
}

.node-group:hover rect {
  transform: translateY(-2px);
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.12));
}

/* 4 Nodes Cards Row */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.node-card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.node-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.node-ip {
  font-size: 12px;
  font-family: monospace;
  color: var(--text-muted);
  margin-top: 2px;
}

.node-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--bg-card-subtle);
  color: var(--text-muted);
}

.node-metrics-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.node-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.metric-lbl {
  color: var(--text-muted);
}

.metric-val {
  font-weight: 600;
}

/* Progress bar inside cards */
.progress-bar-bg {
  width: 100%;
  height: 5px;
  background: var(--bg-card-subtle);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 3px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-purple);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.services-dots-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.service-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.service-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #A8A29E;
}

.service-dot.active {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(61, 176, 112, 0.5);
}

.service-dot.stopped {
  background: var(--accent-orange);
}

/* Special egress node styling */
.node-card.exit-node {
  background: var(--accent-blue);
  color: white;
}

.node-card.exit-node .metric-lbl {
  color: #A5B4FC;
}

.node-card.exit-node .node-ip {
  color: #C7D2FE;
}

.node-card.exit-node .progress-bar-bg {
  background: rgba(255, 255, 255, 0.15);
}

.node-card.exit-node .progress-bar-fill {
  background: var(--accent-lime);
}

/* Row: Graph & Failover Events */
.analytics-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chart-tabs {
  display: flex;
  background: var(--bg-card-subtle);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.chart-tab-btn {
  background: transparent;
  border: none;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
}

.chart-tab-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

#uplot-chart-container {
  width: 100%;
  height: 240px;
}

/* Failover Journal Card */
.failover-card {
  display: flex;
  flex-direction: column;
}

.failover-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.events-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 230px;
  padding-right: 4px;
}

.event-item {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-card-subtle);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 3.5px solid var(--text-light);
}

.event-item.warning {
  border-left-color: var(--accent-orange);
}

.event-item.danger {
  border-left-color: var(--accent-red);
}

.event-item.success {
  border-left-color: var(--accent-green);
}

.event-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.event-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* Clients & Devices Table */
.clients-section {
  margin-top: 8px;
}

.clients-table-wrapper {
  overflow-x: auto;
  margin-top: 12px;
}

.clients-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.clients-table th {
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

.clients-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

/* Daily check banner */
.daily-check-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-subtle);
  padding: 14px 20px;
  border-radius: 16px;
  margin-top: 8px;
  font-size: 13px;
}

.daily-check-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Modal styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border-radius: 24px;
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}

.btn-primary {
  background: var(--accent-purple);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-primary:hover {
  opacity: 0.9;
}

/* Mobile responsiveness */
@media (max-width: 1080px) {
  .top-stats-row {
    grid-template-columns: 1fr;
  }
  .nodes-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .analytics-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }
  .nodes-grid {
    grid-template-columns: 1fr;
  }
  .dns-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
