/* ===== WA Gateway Dashboard — Design System ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --bg-glass: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --border-focus: rgba(37,211,102,0.5);
  --text-primary: #f0f0f5;
  --text-secondary: #8a8a9a;
  --text-muted: #55556a;
  --accent: #25D366;
  --accent-hover: #1ebe5a;
  --accent-glow: rgba(37,211,102,0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --info: #3b82f6;
  --success: #25D366;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.slide-up { animation: slideUp 0.5s ease-out forwards; }

/* ===== Login Page ===== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.login-bg-pattern {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 20% 50%, rgba(37,211,102,0.06) 0%, transparent 70%),
    radial-gradient(ellipse 500px 300px at 80% 30%, rgba(59,130,246,0.04) 0%, transparent 70%);
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 48px 40px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: slideUp 0.6s ease-out;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  justify-content: center;
}

.login-logo svg { width: 40px; height: 40px; }

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #6ee7b7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 32px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(255,255,255,0.06);
}

.form-input::placeholder { color: var(--text-muted); }

textarea.form-input { resize: vertical; min-height: 100px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-card-hover); border-color: rgba(255,255,255,0.15); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: 8px 16px; font-size: 0.8rem; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ===== Dashboard Layout ===== */
.dashboard-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header svg { width: 32px; height: 32px; flex-shrink: 0; }

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #6ee7b7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  min-height: 100vh;
}

.page-header { margin-bottom: 32px; }
.page-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 4px; }
.page-header p { color: var(--text-secondary); font-size: 0.9rem; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: var(--transition);
}

.card:hover { border-color: rgba(255,255,255,0.12); }

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

.card-title { font-size: 1rem; font-weight: 600; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover { border-color: rgba(255,255,255,0.12); transform: translateY(-2px); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.green { background: rgba(37,211,102,0.12); color: var(--accent); }
.stat-icon.blue { background: rgba(59,130,246,0.12); color: var(--info); }
.stat-icon.red { background: rgba(239,68,68,0.12); color: var(--danger); }
.stat-icon.yellow { background: rgba(245,158,11,0.12); color: var(--warning); }

.stat-icon svg { width: 22px; height: 22px; }

.stat-info { flex: 1; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ===== Status Badge ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-badge.connected { background: rgba(37,211,102,0.12); color: var(--accent); }
.status-badge.authenticated { background: rgba(59,130,246,0.12); color: var(--info); }
.status-badge.disconnected { background: rgba(239,68,68,0.12); color: var(--danger); }
.status-badge.qr { background: rgba(245,158,11,0.12); color: var(--warning); }
.status-badge.sent { background: rgba(37,211,102,0.12); color: var(--accent); }
.status-badge.failed { background: rgba(239,68,68,0.12); color: var(--danger); }
.status-badge.pending { background: rgba(245,158,11,0.12); color: var(--warning); }

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

.status-badge.connected .status-dot { animation: pulse 2s infinite; }

/* ===== QR Code Display ===== */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
}

.qr-container img {
  width: 260px; height: 260px;
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.qr-hint { color: var(--text-secondary); font-size: 0.85rem; text-align: center; }

.connected-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px;
}

.connected-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(37,211,102,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.connected-icon svg { width: 36px; height: 36px; color: var(--accent); }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  vertical-align: middle;
}

.data-table tr { transition: var(--transition); }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.msg-text {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Send Message Form ===== */
.send-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.send-form-grid .form-group:last-of-type { grid-column: 1 / -1; }

/* ===== API Key Items ===== */
.api-key-list { display: flex; flex-direction: column; gap: 12px; }

.api-key-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.api-key-item:hover { border-color: rgba(255,255,255,0.12); }

.api-key-info { flex: 1; min-width: 0; }
.api-key-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.api-key-value { font-size: 0.8rem; color: var(--text-muted); font-family: monospace; }
.api-key-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===== Toast / Alert ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  animation: slideUp 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(12px);
  max-width: 380px;
  box-shadow: var(--shadow);
}

.toast.success { background: rgba(37,211,102,0.15); border: 1px solid rgba(37,211,102,0.3); color: var(--accent); }
.toast.error { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.toast.info { background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.3); color: var(--info); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.3s ease-out;
}

.modal h3 { font-size: 1.1rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ===== Alert message ===== */
.alert-msg {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.alert-msg.error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); color: #fca5a5; }

/* ===== Mobile Toggle ===== */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text-primary);
  cursor: pointer;
}

.mobile-toggle svg { width: 20px; height: 20px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .mobile-toggle { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; padding: 24px 16px; padding-top: 64px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .send-form-grid { grid-template-columns: 1fr; }
  .login-card { margin: 16px; padding: 32px 24px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .api-key-item { flex-direction: column; align-items: flex-start; }
  .api-key-actions { width: 100%; }
}
