/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #25D366;
  --primary-dark: #128C7E;
  --primary-light: #DCF8C6;
  --accent: #075E54;
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-sidebar: #13161f;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --text-muted: #718096;
  --text-light: #a0aec0;
  --blue: #3b82f6;
  --red: #ef4444;
  --yellow: #f59e0b;
  --purple: #8b5cf6;
  --teal: #14b8a6;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: all 0.2s ease;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1117 0%, #1a2332 50%, #0f1117 100%);
  position: relative;
  overflow: hidden;
}
.login-screen::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(37,211,102,0.08) 0%, transparent 70%);
  top: -200px; right: -200px;
  border-radius: 50%;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}
.login-logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  color: white;
  margin: 0 auto 24px;
  box-shadow: 0 8px 32px rgba(37,211,102,0.3);
}
.login-card h1 {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
}
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 8px;
}
.input-icon {
  position: relative;
}
.input-icon i {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
}
.input-icon input {
  padding-left: 40px;
}
input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  transition: var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.15);
}
textarea { resize: vertical; }
select { cursor: pointer; }
select option { background: var(--bg-card); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-success { background: #059669; color: white; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline-danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn-outline-danger:hover { background: var(--red); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #3a3d4a; }
.btn-full { width: 100%; justify-content: center; padding: 14px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ===== LAYOUT ===== */
#app { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-brand {
  padding: 24px 20px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}
.sidebar-brand i { font-size: 28px; }

.wa-status-badge {
  margin: 16px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.status-dot.disconnected { background: var(--text-muted); }
.status-dot.qr { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.status-dot.connecting { background: var(--blue); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sidebar-nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--text-light);
  text-decoration: none;
  transition: var(--transition);
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
}
.nav-item i { width: 18px; text-align: center; font-size: 15px; }
.nav-item:hover { background: rgba(37,211,102,0.08); color: var(--primary); }
.nav-item.active { background: rgba(37,211,102,0.15); color: var(--primary); }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* TOPBAR */
.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  justify-content: space-between;
  position: sticky; top: 0;
  z-index: 50;
}
.menu-toggle {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: none;
  padding: 8px;
}
.topbar-user { display: flex; align-items: center; gap: 8px; color: var(--text-light); font-size: 14px; }

/* PAGE */
.page-container { flex: 1; padding: 28px 32px; }
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 28px; }
.page-header h2 { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.page-header h2 i { color: var(--primary); }
.page-header p { color: var(--text-muted); margin-top: 4px; font-size: 14px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.card-header.between { justify-content: space-between; }
.card-header h3 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-header h3 i { color: var(--primary); }
.card-body { padding: 24px; }
.card-footer { padding: 16px 24px; border-top: 1px solid var(--border); }
.mt-4 { margin-top: 24px; }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card.blue::before { background: var(--blue); }
.stat-card.green::before { background: var(--primary); }
.stat-card.teal::before { background: var(--teal); }
.stat-card.red::before { background: var(--red); }
.stat-card.purple::before { background: var(--purple); }
.stat-card:hover { transform: translateY(-2px); border-color: rgba(37,211,102,0.3); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.stat-card.blue .stat-icon { background: rgba(59,130,246,0.15); color: var(--blue); }
.stat-card.green .stat-icon { background: rgba(37,211,102,0.15); color: var(--primary); }
.stat-card.teal .stat-icon { background: rgba(20,184,166,0.15); color: var(--teal); }
.stat-card.red .stat-icon { background: rgba(239,68,68,0.15); color: var(--red); }
.stat-card.purple .stat-icon { background: rgba(139,92,246,0.15); color: var(--purple); }

.stat-value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== TABLES ===== */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  background: rgba(0,0,0,0.2);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-light);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: rgba(37,211,102,0.15); color: var(--primary); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--blue); }

/* ===== WA PAGE ===== */
.wa-connection-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 700px;
}
.wa-status-large {
  display: flex; align-items: center; gap: 20px;
  margin-bottom: 24px;
}
.status-icon {
  width: 64px; height: 64px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
}
.status-icon.connected { background: rgba(37,211,102,0.15); color: var(--primary); }
.status-icon.disconnected { background: rgba(113,128,150,0.15); color: var(--text-muted); }
.status-icon.qr { background: rgba(245,158,11,0.15); color: var(--yellow); }
.wa-status-large h3 { font-size: 18px; font-weight: 600; }
.wa-status-large p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.wa-actions { display: flex; gap: 12px; }

.qr-section {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 24px;
  display: flex; gap: 32px;
}
.qr-instruction h3 { font-size: 16px; margin-bottom: 12px; }
.qr-instruction ol { padding-left: 20px; }
.qr-instruction li { margin-bottom: 8px; color: var(--text-light); font-size: 14px; line-height: 1.5; }
.qr-container {
  position: relative;
  width: 220px; height: 220px;
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
}
.qr-container img { width: 100%; height: 100%; object-fit: cover; }
.qr-refresh-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  color: white;
}
.qr-hint { color: var(--text-muted); font-size: 12px; text-align: center; margin-top: 8px; }

/* ===== API KEYS ===== */
.key-display {
  font-family: monospace;
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--primary);
  cursor: pointer;
  border: 1px solid var(--border);
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 12px;
}
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: rgba(37,211,102,0.1); border: 1px solid rgba(37,211,102,0.3); color: var(--primary); }
.alert-info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: #93c5fd; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 18px; padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; justify-content: flex-end; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  min-width: 280px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  font-size: 14px;
}
@keyframes toastIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast-success { border-left: 3px solid var(--primary); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--blue); }
.toast i.success { color: var(--primary); }
.toast i.error { color: var(--red); }
.toast i.info { color: var(--blue); }

/* ===== LOADING ===== */
.loading-state {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}

/* ===== DOCS ===== */
.docs-container { display: flex; gap: 32px; }
.docs-sidebar {
  width: 200px;
  flex-shrink: 0;
}
.docs-sidebar ul { list-style: none; }
.docs-sidebar li { margin-bottom: 4px; }
.docs-sidebar a {
  display: block; padding: 8px 12px;
  color: var(--text-muted); text-decoration: none;
  border-radius: 8px; font-size: 14px;
  transition: var(--transition);
}
.docs-sidebar a:hover { background: var(--bg-card); color: var(--primary); }
.docs-content { flex: 1; }
.doc-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 24px;
}
.doc-section h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.doc-section p { color: var(--text-muted); margin-bottom: 16px; }
.endpoint-badge {
  display: inline-flex; gap: 8px; align-items: center;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px;
  font-family: monospace; font-size: 14px;
  margin-bottom: 16px;
}
.method { font-weight: 700; }
.method.post { color: #f59e0b; }
.method.get { color: #3b82f6; }
pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  color: #a5f3fc;
  font-family: 'Courier New', monospace;
}

/* ===== GRID ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.char-count { display: block; text-align: right; color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ===== MISC ===== */
.form-control.sm { width: auto; min-width: 160px; }
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; }
.page-btn {
  padding: 6px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-light);
  cursor: pointer; font-size: 13px;
}
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:hover:not(.active) { border-color: var(--primary); }
.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }
.empty-state i { font-size: 48px; margin-bottom: 12px; opacity: 0.3; display: block; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .qr-section { flex-direction: column; }
  .docs-container { flex-direction: column; }
  .docs-sidebar { width: 100%; }
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .page-container { padding: 20px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 32px 24px; margin: 16px; }
}
