/* ========================================
   VPN Panel — Liquid Glass Design System
   Optimized for PWA + Desktop + Mobile
   ======================================== */

/* Theme tokens */
:root {
  --bg: #0a0e1a;
  --bg-secondary: rgba(15, 23, 42, 0.8);
  --glass: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-glow: rgba(96, 165, 250, 0.2);
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.15);
  --warning: #fbbf24;
  --warning-glow: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --danger-glow: rgba(248, 113, 113, 0.15);
  --purple: #a78bfa;
  --purple-glow: rgba(167, 139, 250, 0.15);
  --cyan: #22d3ee;
  --cyan-glow: rgba(34, 211, 238, 0.15);
  --radius: 1rem;
  --radius-sm: 0.625rem;
  --radius-lg: 1.25rem;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --blur: 20px;
  --blur-strong: 40px;
}

html.light {
  --bg: #e8ecf1;
  --bg-secondary: rgba(255, 255, 255, 0.7);
  --glass: rgba(255, 255, 255, 0.5);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-hover: rgba(255, 255, 255, 0.65);
  --glass-strong: rgba(255, 255, 255, 0.6);
  --border: rgba(0, 0, 0, 0.08);
  --border-subtle: rgba(0, 0, 0, 0.04);
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.12);
  --purple: #7c3aed;
  --purple-glow: rgba(124, 58, 237, 0.12);
  --cyan: #0891b2;
  --cyan-glow: rgba(8, 145, 178, 0.12);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0);
  word-wrap: break-word;
  -webkit-overflow-scrolling: touch;
}

/* Ambient background glow */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(96, 165, 250, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(167, 139, 250, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(34, 211, 238, 0.04) 0%, transparent 60%);
  pointer-events: none;
  z-index: -1;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); }
img, svg { max-width: 100%; height: auto; }

/* ========================================
   PWA Safe Area & Standalone Mode
   ======================================== */
@supports(padding-top: env(safe-area-inset-top)) {
  body { padding-top: env(safe-area-inset-top); }
}

/* When running as PWA standalone — extra bottom padding */
@media all and (display-mode: standalone) {
  body { padding-bottom: env(safe-area-inset-bottom, 0); }
}

/* ========================================
   Liquid Glass Card
   ======================================== */
.card {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}
.card:hover {
  background: var(--glass-hover);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.05);
}
html.light .card {
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.5);
}

/* ========================================
   Liquid Glass Stat Card
   ======================================== */
.stat-card {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--stat-accent, var(--primary));
  opacity: 0.7;
}
.stat-card::after {
  content: '';
  position: absolute;
  top: -50%; right: -50%;
  width: 100%; height: 100%;
  background: radial-gradient(circle, var(--stat-glow, var(--primary-glow)) 0%, transparent 70%);
  opacity: 0.5;
  pointer-events: none;
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-strong);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; color: var(--stat-accent, var(--primary)); }
.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.03em;
  position: relative;
  z-index: 1;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  position: relative;
  z-index: 1;
}

/* ========================================
   Liquid Glass Link Card
   ======================================== */
.link-card {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: var(--transition);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.link-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}
.link-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-strong);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.link-icon svg { width: 18px; height: 18px; color: var(--link-accent, var(--primary)); }
.link-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   Liquid Glass Navbar
   ======================================== */
.navbar {
  background: rgba(10, 14, 26, 0.7) !important;
  backdrop-filter: blur(var(--blur-strong)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur-strong)) saturate(180%);
  border-bottom: 1px solid var(--glass-border) !important;
}
html.light .navbar {
  background: rgba(255, 255, 255, 0.7) !important;
}

/* ========================================
   Liquid Glass Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.8125rem;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  line-height: 1.4;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}
.btn:hover::before { opacity: 1; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.2), rgba(59, 130, 246, 0.3));
  color: var(--primary);
  border: 1px solid rgba(96, 165, 250, 0.3);
  backdrop-filter: blur(10px);
}
.btn-primary:hover {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.3), rgba(59, 130, 246, 0.4));
  box-shadow: 0 0 20px var(--primary-glow);
  border-color: rgba(96, 165, 250, 0.5);
}

.btn-success {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.2), rgba(16, 185, 129, 0.3));
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.3);
  backdrop-filter: blur(10px);
}
.btn-success:hover {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.3), rgba(16, 185, 129, 0.4));
  box-shadow: 0 0 20px var(--success-glow);
}

.btn-danger {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.2), rgba(239, 68, 68, 0.3));
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
  backdrop-filter: blur(10px);
}
.btn-danger:hover {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.3), rgba(239, 68, 68, 0.4));
  box-shadow: 0 0 20px var(--danger-glow);
}

.btn-warning {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(245, 158, 11, 0.3));
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.3);
  backdrop-filter: blur(10px);
}
.btn-warning:hover {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.3), rgba(245, 158, 11, 0.4));
  box-shadow: 0 0 20px var(--warning-glow);
}

.btn-ghost {
  background: var(--glass);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
}
.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--glass-hover);
}

.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.75rem; }
.btn-icon { padding: 0.5rem; }

/* ========================================
   Liquid Glass Table
   ======================================== */
.table-container {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}
.table-container::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}
.table-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.table-title { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; min-width: 500px; }
thead th {
  padding: 0.625rem 1.25rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}
html.light thead th { background: rgba(255, 255, 255, 0.3); }
tbody td {
  padding: 0.75rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}
tbody tr { transition: var(--transition); }
tbody tr:hover { background: var(--glass-hover); }
tbody tr:last-child td { border-bottom: none; }

/* ========================================
   Liquid Glass Badges
   ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1;
  backdrop-filter: blur(10px);
}
.badge-success { background: rgba(52, 211, 153, 0.15); color: var(--success); border: 1px solid rgba(52, 211, 153, 0.2); }
.badge-warning { background: rgba(251, 191, 36, 0.15); color: var(--warning); border: 1px solid rgba(251, 191, 36, 0.2); }
.badge-danger { background: rgba(248, 113, 113, 0.15); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.2); }
.badge-primary { background: rgba(96, 165, 250, 0.15); color: var(--primary); border: 1px solid rgba(96, 165, 250, 0.2); }
.badge-purple { background: rgba(167, 139, 250, 0.15); color: var(--purple); border: 1px solid rgba(167, 139, 250, 0.2); }
.badge-neutral { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); border: 1px solid rgba(100, 116, 139, 0.2); }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ========================================
   Liquid Glass Forms
   ======================================== */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  transition: var(--transition);
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow), 0 0 20px var(--primary-glow);
  background: var(--glass-hover);
}
.form-input::placeholder { color: var(--text-muted); }

/* ========================================
   Section Title
   ======================================== */
.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title::before {
  content: '';
  width: 3px;
  height: 1rem;
  background: linear-gradient(180deg, var(--primary), var(--purple));
  border-radius: 2px;
}

/* ========================================
   Animations
   ======================================== */
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.pulse { animation: pulse-dot 2s ease-in-out infinite; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1); }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--glass) 25%, var(--glass-hover) 50%, var(--glass) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========================================
   Toast notifications — avoid safe area
   ======================================== */
.toast-container,
div[style*="position:fixed"][style*="bottom:1.5rem"] {
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)) !important;
}

/* ========================================
   Stagger animation for grid items
   ======================================== */
.stats-grid > * { animation: fadeSlideUp 0.4s ease backwards; }
.stats-grid > *:nth-child(1) { animation-delay: 0ms; }
.stats-grid > *:nth-child(2) { animation-delay: 60ms; }
.stats-grid > *:nth-child(3) { animation-delay: 120ms; }
.stats-grid > *:nth-child(4) { animation-delay: 180ms; }

.links-grid > * { animation: fadeSlideUp 0.4s ease backwards; }
.links-grid > *:nth-child(1) { animation-delay: 60ms; }
.links-grid > *:nth-child(2) { animation-delay: 120ms; }
.links-grid > *:nth-child(3) { animation-delay: 180ms; }
.links-grid > *:nth-child(4) { animation-delay: 240ms; }

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

/* ========================================
   Focus visible ring
   ======================================== */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Selection color */
::selection {
  background: var(--primary-glow);
  color: var(--text);
}

/* ========================================
   Responsive — Tablet (max-width: 1024px)
   ======================================== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .links-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ========================================
   Responsive — Mobile (max-width: 640px)
   ======================================== */
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .links-grid { grid-template-columns: 1fr 1fr !important; }
  .actions-grid { grid-template-columns: repeat(2, 1fr) !important; }

  .stat-card { padding: 1rem; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat-value { font-size: 1.375rem; }
  .stat-label { font-size: 0.6875rem; }

  .link-card { padding: 0.75rem; gap: 0.5rem; }
  .link-icon { width: 36px; height: 36px; }
  .link-icon svg { width: 16px; height: 16px; }
  .link-title { font-size: 0.8125rem; }
  .link-desc { font-size: 0.6875rem; }

  .card { padding: 1rem; }

  .table-header { padding: 0.75rem 1rem; }
  thead th, tbody td { padding: 0.5rem 0.75rem; font-size: 0.75rem; }
  .btn { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
  .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.6875rem; }

  /* Navbar — hide username text, keep avatar */
  .navbar .flex.items-center.gap-2 > span:not(.badge):not(.pulse) { display: none; }
}

/* ========================================
   Responsive — Small Mobile (max-width: 380px)
   ======================================== */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr !important; }
  .links-grid { grid-template-columns: 1fr !important; }
  .actions-grid { grid-template-columns: 1fr !important; }
  .stat-value { font-size: 1.25rem; }
}

/* ========================================
   Reduced motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   Touch-friendly overrides
   ======================================== */
@media (hover: none) and (pointer: coarse) {
  .card:hover, .link-card:hover, .stat-card:hover, .btn:hover {
    transform: none;
    box-shadow: none;
  }
  .link-card:active, .stat-card:active {
    transform: scale(0.98);
    background: var(--glass-hover);
  }
  .btn:active {
    transform: scale(0.96);
  }
  tbody tr:hover { transform: none; }
  tbody tr:hover::after { transform: none; }
  .link-card:hover .link-icon { transform: none; box-shadow: none; }
  .stat-card:hover .stat-icon { transform: none; box-shadow: none; }
}

/* ========================================
   Print
   ======================================== */
@media print {
  .navbar, .back-fab, .proxy-bar { display: none !important; }
  body { background: white; color: black; }
}
