/* ─────────────────────────────────────────────
   WAPI Dashboard — Global Styles
   WhatsApp-themed: greens on dark sidebar
   ───────────────────────────────────────────── */

:root {
  --wha-dark:    #075E54;
  --wha-mid:     #128C7E;
  --wha-green:   #25D366;
  --wha-light:   #DCF8C6;
  --wha-bg:      #f0f2f5;
  --sidebar-w:   250px;
  --topbar-h:    60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--wha-bg);
  color: #333;
}

/* ── Sidebar ─────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--wha-dark);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
}
.sidebar-header .logo-icon {
  width: 36px; height: 36px;
  background: var(--wha-green);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.sidebar-header .brand-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}
.sidebar-header .brand-sub {
  font-size: 10px;
  opacity: .7;
}

.sidebar-nav {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  flex: 1;
}
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-left-color: var(--wha-green);
}
.sidebar-nav li a i {
  width: 18px;
  text-align: center;
  font-size: 15px;
}
.sidebar-section {
  padding: 10px 18px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.4);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-footer .user-info {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.sidebar-footer .avatar {
  width: 32px; height: 32px;
  background: var(--wha-mid);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 600;
}
.sidebar-footer .uname { color: #fff; font-size: 13px; font-weight: 600; }
.sidebar-footer .urole { color: rgba(255,255,255,.5); font-size: 11px; }

/* ── Main content area ───────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ─────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--wha-dark);
}
.topbar .topbar-right {
  display: flex; align-items: center; gap: 12px;
}

/* ── Content ─────────────────────────────────── */
.content {
  padding: 24px;
  flex: 1;
}

/* ── Stat cards ──────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.green  { background: #d1fae5; color: var(--wha-mid); }
.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-value { font-size: 26px; font-weight: 700; color: #111; line-height: 1; }
.stat-label { font-size: 13px; color: #6b7280; margin-top: 2px; }

/* ── Cards / panels ──────────────────────────── */
.panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h6 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--wha-dark);
}
.panel-body { padding: 20px; }

/* ── Status badges ───────────────────────────── */
.badge-working  { background: #d1fae5; color: #065f46; }
.badge-stopped  { background: #fee2e2; color: #991b1b; }
.badge-starting { background: #fef3c7; color: #92400e; }
.badge-scan     { background: #dbeafe; color: #1e40af; }
.badge-failed   { background: #fee2e2; color: #991b1b; }

/* ── Session cards ───────────────────────────── */
.session-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px;
  background: #fff;
  transition: box-shadow .2s;
}
.session-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.session-avatar {
  width: 44px; height: 44px;
  background: var(--wha-dark);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px;
}

/* ── QR modal ────────────────────────────────── */
#qr-img { max-width: 240px; border-radius: 8px; border: 4px solid var(--wha-green); }

/* ── Message type tabs ───────────────────────── */
.msg-tab { cursor: pointer; }
.msg-tab.active { background: var(--wha-dark) !important; color: #fff !important; }

/* ── Chat list ───────────────────────────────── */
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background .15s;
}
.chat-item:hover { background: #f9fafb; }
.chat-avatar {
  width: 42px; height: 42px;
  background: var(--wha-mid);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 600;
  flex-shrink: 0;
}
.chat-name { font-size: 14px; font-weight: 600; color: #111; }
.chat-preview { font-size: 12px; color: #6b7280; }
.chat-time { font-size: 11px; color: #9ca3af; }

/* ── Message bubble ──────────────────────────── */
.msg-bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  margin: 4px 0;
  font-size: 14px;
  line-height: 1.4;
}
.msg-in  { background: #fff; border: 1px solid #e5e7eb; align-self: flex-start; }
.msg-out { background: var(--wha-light); align-self: flex-end; }

/* ── API key display ─────────────────────────── */
.key-display {
  font-family: 'Courier New', monospace;
  background: #1e293b;
  color: var(--wha-green);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  word-break: break-all;
  position: relative;
}

/* ── Log table ───────────────────────────────── */
.log-method {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}
.log-method.GET    { background: #dbeafe; color: #1e40af; }
.log-method.POST   { background: #d1fae5; color: #065f46; }
.log-method.DELETE { background: #fee2e2; color: #991b1b; }
.log-method.PATCH  { background: #fef3c7; color: #92400e; }

/* ── Form helpers ────────────────────────────── */
.form-label { font-size: 13px; font-weight: 600; color: #374151; }
.form-control:focus, .form-select:focus {
  border-color: var(--wha-green);
  box-shadow: 0 0 0 3px rgba(37,211,102,.15);
}
.btn-wha {
  background: var(--wha-dark);
  color: #fff;
  border: none;
}
.btn-wha:hover { background: var(--wha-mid); color: #fff; }
.btn-wha-green {
  background: var(--wha-green);
  color: #fff;
  border: none;
}
.btn-wha-green:hover { background: #1ebe5d; color: #fff; }

/* ── Alert toast ─────────────────────────────── */
#toast-container {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 280px;
}
.toast-msg {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: slideIn .25s ease;
}
.toast-msg.success { background: var(--wha-mid); }
.toast-msg.error   { background: #dc2626; }
.toast-msg.info    { background: #2563eb; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Loading spinner ─────────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--wha-green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #9ca3af;
}
.empty-state i { font-size: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 15px; }

/* ── Login page ──────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--wha-dark) 0%, var(--wha-mid) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  width: 64px; height: 64px;
  background: var(--wha-green);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  color: #fff;
  margin: 0 auto 20px;
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); transition: transform .25s; }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
}
