/* ============================================
   WA Dashboard — Main Stylesheet
   Font: Plus Jakarta Sans + JetBrains Mono
   Theme: WhatsApp-inspired dark green
   ============================================ */

:root {
  --bg-base:        #0a0e0f;
  --bg-surface:     #111b1c;
  --bg-card:        #182122;
  --bg-hover:       #1f2d2e;
  --bg-input:       #1a2627;
  --border:         #263335;
  --border-light:   #2e3d3f;

  --wa-green:       #00a884;
  --wa-green-dark:  #008069;
  --wa-green-light: #25d366;
  --wa-teal:        #2a9090;

  --accent:         #00a884;
  --accent-hover:   #00c59a;
  --danger:         #e53935;
  --warning:        #f59e0b;
  --info:           #3b82f6;
  --success:        #25d366;

  --text-primary:   #e9edef;
  --text-secondary: #8696a0;
  --text-muted:     #526268;
  --text-link:      #00a884;

  --sidebar-w:      260px;
  --topbar-h:       60px;
  --radius:         12px;
  --radius-sm:      8px;
  --radius-lg:      16px;
  --shadow:         0 2px 16px rgba(0,0,0,0.4);

  --font-main:  'Plus Jakarta Sans', sans-serif;
  --font-mono:  'JetBrains Mono', monospace;

  --msg-out-bg: #005c4b;
  --msg-in-bg:  #202c33;
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--text-link); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; }

/* ========== LAYOUT ========== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--wa-green-light);
}
.logo-icon { font-size: 22px; }
.sidebar-toggle-btn {
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer; font-size: 18px;
  padding: 4px;
}

/* Connection Status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  flex-wrap: wrap;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.disconnected { background: var(--text-muted); }
.status-text { color: var(--text-secondary); font-weight: 500; }
.connected-number { color: var(--text-muted); font-size: 11px; width: 100%; padding-left: 16px; }

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 16px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--text-secondary);
  border-radius: 0;
  transition: all 0.15s ease;
  font-weight: 500;
  font-size: 13.5px;
  position: relative;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-link.active {
  background: rgba(0,168,132,0.12);
  color: var(--wa-green-light);
  border-right: 3px solid var(--wa-green-light);
}
.nav-link.active .nav-icon { transform: scale(1.1); }
.nav-link-danger:hover { background: rgba(229,57,53,0.1); color: var(--danger); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-label {}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--wa-green-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; display: block; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ========== MAIN CONTENT ========== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ========== TOPBAR ========== */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.page-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.mobile-menu-btn {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer; font-size: 20px;
}
.topbar-right {}
.topbar-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  background: var(--bg-card);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.topbar-status.connected { color: var(--success); border-color: rgba(37,211,102,0.3); }
.topbar-status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ========== PAGE CONTENT ========== */
.page-content {
  padding: 24px;
  flex: 1;
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ========== STATS GRID ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.stat-icon {
  font-size: 28px;
  width: 50px; height: 50px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}
.stat-value { font-size: 26px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ========== FORMS ========== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-control {
  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;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.12);
}
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { cursor: pointer; }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--wa-green);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); color: white; }
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { color: var(--text-primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c62828; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 13px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ========== ALERTS ========== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.alert-success { background: rgba(37,211,102,0.1); border-color: rgba(37,211,102,0.3); color: #25d366; }
.alert-error   { background: rgba(229,57,53,0.1); border-color: rgba(229,57,53,0.3); color: #ef5350; }
.alert-warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
.alert-info    { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #60a5fa; }

/* ========== TABLES ========== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bg-hover); }
th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

/* ========== BADGES ========== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: rgba(37,211,102,0.15); color: #25d366; }
.badge-danger  { background: rgba(229,57,53,0.15); color: #ef5350; }
.badge-warning { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-info    { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-muted   { background: var(--bg-hover); color: var(--text-muted); }

/* ========== QR CODE BOX ========== */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
}
.qr-box {
  width: 240px; height: 240px;
  background: white;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--wa-green);
  box-shadow: 0 0 30px rgba(0,168,132,0.2);
  position: relative;
  overflow: hidden;
}
.qr-box img { width: 210px; height: 210px; }
.qr-placeholder {
  color: #888;
  font-size: 13px;
  text-align: center;
  padding: 20px;
}
.qr-scan-hint { color: var(--text-muted); font-size: 13px; text-align: center; max-width: 260px; }

/* ========== CHAT UI ========== */
.chat-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h) - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.chat-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}
.chat-search {
  margin-top: 10px;
}
.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: rgba(0,168,132,0.1); border-left: 3px solid var(--wa-green); }
.chat-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--wa-green-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
  color: white;
}
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; font-size: 14px; truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.chat-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11px; color: var(--text-muted); }

/* Chat Window */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
}
.chat-window-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23182122' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  display: flex;
  margin-bottom: 4px;
}
.message.out { justify-content: flex-end; }
.message.in  { justify-content: flex-start; }
.message-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.5;
  position: relative;
}
.message.out .message-bubble {
  background: var(--msg-out-bg);
  border-bottom-right-radius: 3px;
}
.message.in .message-bubble {
  background: var(--msg-in-bg);
  border-bottom-left-radius: 3px;
}
.message-time {
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  margin-top: 3px;
  text-align: right;
}
.message-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 0;
}
.message-date-divider span {
  background: var(--bg-card);
  padding: 3px 10px;
  border-radius: 10px;
}

.chat-input-area {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  font-size: 14px;
  outline: none;
  line-height: 1.4;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send-btn {
  width: 44px; height: 44px;
  background: var(--wa-green);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--text-muted);
}
.chat-empty-icon { font-size: 64px; opacity: 0.3; }

/* ========== LOGIN PAGE ========== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 20% 50%, rgba(0,168,132,0.08), transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(37,211,102,0.05), transparent 50%),
              var(--bg-base);
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo-icon { font-size: 48px; }
.login-logo-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--wa-green-light);
  margin-top: 8px;
}
.login-logo-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ========== PROGRESS BAR ========== */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--wa-green), var(--wa-green-light));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ========== TAG CHIPS ========== */
.tag-chip {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(0,168,132,0.12);
  color: var(--wa-green-light);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  margin: 1px;
}

/* ========== LOADING SPINNER ========== */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--wa-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== MONO CODE ========== */
.mono { font-family: var(--font-mono); font-size: 12px; }

/* ========== UTILS ========== */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.w-100 { width: 100%; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .mobile-menu-btn { display: block; }
  .chat-sidebar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .chat-layout { flex-direction: column; height: auto; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px 20px; }
}

/* ========== ANIMATION ========== */
.fade-in {
  animation: fadeIn 0.3s ease forwards;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.pulse {
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
