/* Art direction: Industrial VPN monitoring dashboard → SCADA/control system aesthetic
   Palette: Dark surfaces (cool-neutral), accent: industrial teal/cyan (#0ff-ish but muted)
   Typography: Inter (UI body) + JetBrains Mono (technical data, IPs, metrics)
   Density: Dense but readable — operator control panel feel */

/* ===== FONTS ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ===== TOKENS ===== */
:root {
  /* Font families */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Type scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  /* 4px spacing system */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;
}

/* ===== DARK MODE (DEFAULT) ===== */
:root, [data-theme="dark"] {
  /* Surfaces — cool dark, not warm */
  --color-bg:               #0d1117;
  --color-surface:          #131920;
  --color-surface-2:        #161d26;
  --color-surface-offset:   #1a222c;
  --color-surface-offset-2: #1f2833;
  --color-surface-dynamic:  #252e3a;
  --color-divider:          #2a3441;
  --color-border:           #334155;

  /* Text */
  --color-text:           #e2e8f0;
  --color-text-muted:     #94a3b8;
  --color-text-faint:     #64748b;
  --color-text-inverse:   #0d1117;

  /* Primary — Industrial Teal/Cyan */
  --color-primary:          #22d3ee;
  --color-primary-hover:    #06b6d4;
  --color-primary-active:   #0891b2;
  --color-primary-highlight: #164e63;
  --color-primary-glow:     oklch(0.75 0.15 195 / 0.15);

  /* Success — Online / Reachable */
  --color-success:          #34d399;
  --color-success-hover:    #10b981;
  --color-success-active:   #059669;
  --color-success-highlight: #064e3b;

  /* Error — Offline / Unreachable */
  --color-error:            #f87171;
  --color-error-hover:      #ef4444;
  --color-error-active:     #dc2626;
  --color-error-highlight:  #450a0a;

  /* Warning */
  --color-warning:          #fbbf24;
  --color-warning-hover:    #f59e0b;
  --color-warning-active:   #d97706;
  --color-warning-highlight: #451a03;

  /* Shadows */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.5);
}

/* ===== LIGHT MODE ===== */
[data-theme="light"] {
  --color-bg:               #f1f5f9;
  --color-surface:          #ffffff;
  --color-surface-2:        #f8fafc;
  --color-surface-offset:   #e2e8f0;
  --color-surface-offset-2: #cbd5e1;
  --color-surface-dynamic:  #dde5ed;
  --color-divider:          #cbd5e1;
  --color-border:           #94a3b8;

  --color-text:           #0f172a;
  --color-text-muted:     #475569;
  --color-text-faint:     #94a3b8;
  --color-text-inverse:   #f1f5f9;

  --color-primary:          #0891b2;
  --color-primary-hover:    #0e7490;
  --color-primary-active:   #155e75;
  --color-primary-highlight: #cffafe;
  --color-primary-glow:     oklch(0.60 0.12 195 / 0.10);

  --color-success:          #059669;
  --color-success-hover:    #047857;
  --color-success-active:   #065f46;
  --color-success-highlight: #d1fae5;

  --color-error:            #dc2626;
  --color-error-hover:      #b91c1c;
  --color-error-active:     #991b1b;
  --color-error-highlight:  #fee2e2;

  --color-warning:          #d97706;
  --color-warning-hover:    #b45309;
  --color-warning-active:   #92400e;
  --color-warning-highlight: #fef3c7;

  --shadow-sm: 0 1px 2px oklch(0.2 0.01 240 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 240 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 240 / 0.12);
}

/* System preference fallback */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg:               #f1f5f9;
    --color-surface:          #ffffff;
    --color-surface-2:        #f8fafc;
    --color-surface-offset:   #e2e8f0;
    --color-surface-offset-2: #cbd5e1;
    --color-surface-dynamic:  #dde5ed;
    --color-divider:          #cbd5e1;
    --color-border:           #94a3b8;
    --color-text:           #0f172a;
    --color-text-muted:     #475569;
    --color-text-faint:     #94a3b8;
    --color-text-inverse:   #f1f5f9;
    --color-primary:          #0891b2;
    --color-primary-hover:    #0e7490;
    --color-primary-active:   #155e75;
    --color-primary-highlight: #cffafe;
    --color-primary-glow:     oklch(0.60 0.12 195 / 0.10);
    --color-success:          #059669;
    --color-success-hover:    #047857;
    --color-success-active:   #065f46;
    --color-success-highlight: #d1fae5;
    --color-error:            #dc2626;
    --color-error-hover:      #b91c1c;
    --color-error-active:     #991b1b;
    --color-error-highlight:  #fee2e2;
    --color-warning:          #d97706;
    --color-warning-hover:    #b45309;
    --color-warning-active:   #92400e;
    --color-warning-highlight: #fef3c7;
    --shadow-sm: 0 1px 2px oklch(0.2 0.01 240 / 0.06);
    --shadow-md: 0 4px 12px oklch(0.2 0.01 240 / 0.08);
    --shadow-lg: 0 12px 32px oklch(0.2 0.01 240 / 0.12);
  }
}

/* ===== DASHBOARD LAYOUT ===== */
html, body {
  height: 100%;
  overflow: hidden;
  margin: 0;
}

.dashboard {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.dashboard-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-shrink: 0;
}

.dashboard-main {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5);
}

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-primary);
  opacity: 0.5;
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.2;
  font-variant-numeric: tabular-nums lining-nums;
}

.kpi-sub {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-1);
  font-family: var(--font-mono);
}

/* ===== CLIENT TABLE ===== */
.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-title svg {
  color: var(--color-primary);
  flex-shrink: 0;
}

.table-container {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-5);
}

.client-table {
  font-size: var(--text-sm);
}

.client-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.client-table th {
  background: var(--color-surface-offset);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-divider);
}

.client-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}

.client-table tbody tr:last-child td {
  border-bottom: none;
}

.client-table tbody tr {
  transition: background var(--transition-interactive);
}

.client-table tbody tr:hover {
  background: var(--color-surface-offset);
}

/* Client name */
.client-name {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--color-text);
}

/* IP addresses */
.ip-addr {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums lining-nums;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge--online {
  background: color-mix(in oklch, var(--color-success) 15%, transparent);
  color: var(--color-success);
}

.status-badge--offline {
  background: color-mix(in oklch, var(--color-error) 15%, transparent);
  color: var(--color-error);
}

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

.status-dot--online {
  background: var(--color-success);
  box-shadow: 0 0 6px var(--color-success);
  animation: pulse-green 2s ease-in-out infinite;
}

.status-dot--offline {
  background: var(--color-error);
  opacity: 0.7;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--color-success); }
  50% { opacity: 0.6; box-shadow: 0 0 2px var(--color-success); }
}

/* Data cells */
.data-bytes {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums lining-nums;
}

.data-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ===== LAN DEVICES ===== */
.lan-section {
  margin-bottom: var(--space-5);
}

.lan-client-group {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  overflow: hidden;
}

.lan-client-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  border-bottom: 1px solid var(--color-divider);
}

.lan-client-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-sm);
}

.lan-client-subnet {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.lan-devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
  padding: var(--space-4);
}

.lan-device-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-interactive);
}

.lan-device-card:hover {
  border-color: var(--color-border);
}

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

.device-status-dot--reachable {
  background: var(--color-success);
  box-shadow: 0 0 6px color-mix(in oklch, var(--color-success) 50%, transparent);
}

.device-status-dot--unreachable {
  background: var(--color-error);
  opacity: 0.6;
}

.device-info {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.device-ip {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.device-status-label {
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

.device-status-label--reachable { color: var(--color-success); }
.device-status-label--unreachable { color: var(--color-error); opacity: 0.8; }

.device-lastseen {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  white-space: nowrap;
}

/* ===== HEADER ===== */
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-mark {
  flex-shrink: 0;
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--color-divider);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.last-update {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.refresh-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-success);
  animation: pulse-green 2s ease-in-out infinite;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  border: 1px solid var(--color-divider);
  background: transparent;
}

.theme-toggle:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

/* ===== SERVER STATUS BAR ===== */
.server-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.server-bar-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
}

.server-bar-label {
  color: var(--color-text-faint);
  font-family: var(--font-body);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.server-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-success);
  font-weight: 500;
}

/* ===== NO DEVICES MESSAGE ===== */
.no-devices {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  font-style: italic;
}

/* ===== FOOTER ===== */
.dashboard-footer {
  padding: var(--space-3) var(--space-6);
  text-align: center;
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
  flex-shrink: 0;
}

.dashboard-footer a {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
}

.dashboard-footer a:hover {
  color: var(--color-text-muted);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 300ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Stagger children */
.stagger > *:nth-child(1) { animation-delay: 50ms; }
.stagger > *:nth-child(2) { animation-delay: 100ms; }
.stagger > *:nth-child(3) { animation-delay: 150ms; }
.stagger > *:nth-child(4) { animation-delay: 200ms; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .dashboard-header {
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
  }

  .dashboard-main {
    padding: var(--space-4);
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
  }

  .kpi-value {
    font-size: var(--text-lg);
  }

  .table-container {
    overflow-x: auto;
  }

  .client-table {
    min-width: 700px;
  }

  .lan-devices-grid {
    grid-template-columns: 1fr;
  }

  .server-bar {
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
  }

  .header-divider {
    display: none;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .header-title {
    font-size: var(--text-base);
  }

  .last-update {
    display: none;
  }
}
