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

/* ─── Theme Variables ─── */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

/* ─── Light Theme ─── */
[data-theme="light"] {
  --bg-base: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-input: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --overlay: rgba(0, 0, 0, 0.4);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-card-hover: 0 10px 30px rgba(0, 0, 0, 0.08);
}

/* ─── Dark Theme ─── */
[data-theme="dark"] {
  --bg-base: #0c0e1a;
  --bg-surface: #141625;
  --bg-card: #1a1d31;
  --bg-elevated: #1e2139;
  --bg-input: #1a1d31;
  --border: #2a2d45;
  --border-light: #23263e;
  --text-primary: #f1f5f9;
  --text-secondary: #a1a5c0;
  --text-muted: #64688a;
  --overlay: rgba(0, 0, 0, 0.7);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-card-hover: 0 8px 30px rgba(99, 102, 241, 0.12);
}

/* ─── Base ─── */
body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 28px;
}

/* ─── Navbar ─── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  margin-bottom: 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

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

.navbar-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
}

.navbar-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.navbar-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.5px;
}

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

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.nav-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Theme Toggle ─── */
.theme-toggle {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform var(--transition);
}

[data-theme="dark"] .theme-toggle::after {
  transform: translateX(18px);
}

.theme-toggle-label {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* ─── API Key Bar ─── */
.key-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.key-bar label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

.key-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  transition: all var(--transition);
}

.key-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-icon {
  padding: 6px 8px;
  font-size: 14px;
}

/* ─── Stats Grid ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 800px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}

.stat-icon.purple {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
}

.stat-icon.green {
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
}

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

.stat-icon.blue {
  background: rgba(59, 130, 246, 0.12);
  color: var(--info);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  margin-top: 4px;
  color: var(--text-primary);
}

/* ─── Section Header ─── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title .count {
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ─── Tenant Cards ─── */
.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

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

.tenant-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
}

.tenant-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

.tenant-card-body {
  padding: 20px;
}

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

.tenant-name {
  font-size: 17px;
  font-weight: 700;
}

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-online {
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
}

.badge-offline {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.badge-degraded {
  background: rgba(245, 158, 11, 0.12);
  color: var(--warning);
}

.badge-provisioning {
  background: rgba(59, 130, 246, 0.1);
  color: var(--info);
}

.tenant-meta {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.tenant-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.tenant-meta-item b {
  font-weight: 600;
  color: var(--text-primary);
}

/* Services inside tenant */
.svc-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 12px;
}

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

.svc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

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

.svc-dot.up {
  background: var(--success);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.svc-dot.down {
  background: var(--danger);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.svc-app-health {
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}

.svc-name {
  font-weight: 500;
  color: var(--text-primary);
}

.svc-port {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.svc-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.svc-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  transition: all var(--transition);
}

.svc-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.svc-actions button.svc-del:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.svc-toggle {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all var(--transition);
  flex-shrink: 0;
}

.svc-toggle.on {
  background: var(--success);
  border-color: var(--success);
}

.svc-toggle.off {
  background: var(--bg-input);
}

.svc-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  transition: transform var(--transition);
}

.svc-toggle.on::after {
  transform: translateX(14px);
}

/* Tenant actions */
.tenant-footer {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  background: var(--bg-elevated);
}

.tenant-footer .btn {
  font-size: 12px;
  padding: 6px 12px;
}

/* ─── Modals ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  display: none;
  z-index: 100;
  justify-content: center;
  align-items: center;
}

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

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 90%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal h2 {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  margin-top: 16px;
}

.modal input,
.modal select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  transition: all var(--transition);
}

.modal input:focus,
.modal select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  justify-content: flex-end;
}

/* ─── Empty state ─── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  margin-bottom: 6px;
}

.empty-state-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ─── Toasts ─── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}