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

:root {
  --bg:       #0d0f14;
  --surface:  #161921;
  --border:   #252830;
  --accent:   #25d366;  /* WhatsApp green */
  --accent2:  #f5a623;
  --danger:   #e74c3c;
  --text:     #e8eaf0;
  --muted:    #6b7280;
  --radius:   10px;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'DM Sans', sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── SIDEBAR ─────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
}
.logo-icon { font-size: 28px; }
.logo-title { font-family: var(--font-mono); font-size: 13px; font-weight: 700; color: var(--accent); }
.logo-sub   { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  position: relative;
}
.nav-item:hover  { background: rgba(255,255,255,.04); color: var(--text); }
.nav-item.active { background: rgba(37,211,102,.1); color: var(--accent); }

.badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
}
.status-dot.ok { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ── MAIN ─────────────────────────────────────────────── */
.main { flex: 1; padding: 32px 36px; overflow-y: auto; }

.tab { display: none; }
.tab.active { display: block; animation: fadeIn .2s ease; }

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

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 16px;
}
.page-header h1 { font-family: var(--font-mono); font-size: 20px; margin-bottom: 4px; }
.page-header p  { color: var(--muted); font-size: 13px; }

/* ── BUTTONS ─────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #0a1f13;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: .85; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
}
.btn-ghost:hover { border-color: var(--text); color: var(--text); }

.btn-danger {
  background: rgba(231,76,60,.1);
  color: var(--danger);
  font-size: 12px;
  padding: 6px 12px;
  border: 1px solid rgba(231,76,60,.3);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.btn-danger:hover { background: rgba(231,76,60,.2); }

/* ── SESSION CARDS ──────────────────────────────────── */
.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.session-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--muted);
}
.session-card.connected::before  { background: var(--accent); }
.session-card.qr_pending::before { background: var(--accent2); animation: pulse 1.5s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.session-id   { font-family: var(--font-mono); font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.session-phone { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.session-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(107,114,128,.15);
  color: var(--muted);
  margin-bottom: 16px;
}
.session-status.connected  { background: rgba(37,211,102,.12); color: var(--accent); }
.session-status.qr_pending { background: rgba(245,166,35,.12); color: var(--accent2); }

.session-qr img { width: 180px; border-radius: 8px; border: 4px solid #fff; margin: 12px 0; display: block; }
.qr-hint { font-size: 11px; color: var(--muted); }

/* ── NOTIFICATIONS ──────────────────────────────────── */
#notif-list { display: flex; flex-direction: column; gap: 10px; }

.notif-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  transition: opacity .2s;
}
.notif-card.unread { border-left-color: var(--accent); }
.notif-card.order  { border-left-color: var(--accent2); }
.notif-card.agent_request { border-left-color: #3b82f6; }

.notif-icon { font-size: 22px; flex-shrink: 0; }
.notif-body { flex: 1; }
.notif-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.notif-meta  { font-size: 11px; color: var(--muted); }
.notif-time  { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ── TABLE ───────────────────────────────────────────── */
.search-wrap input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  width: 220px;
}
.search-wrap input:focus { border-color: var(--accent); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: rgba(255,255,255,.03);
  padding: 12px 16px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.chip.green { background: rgba(37,211,102,.12); color: var(--accent); }
.chip.red   { background: rgba(231,76,60,.12);  color: var(--danger); }

/* ── MODAL ───────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 380px;
  max-width: 95vw;
}
.modal h2 { font-family: var(--font-mono); margin-bottom: 8px; }
.modal p  { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.modal input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  margin-bottom: 20px;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
#qr-area { text-align: center; padding: 12px 0; }
.qr-label { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
#qr-img { width: 200px; border-radius: 8px; border: 4px solid #fff; }

/* ── TOAST ───────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  transform: translateY(80px);
  opacity: 0;
  transition: all .3s;
  z-index: 200;
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── EMPTY / LOADING ─────────────────────────────────── */
.empty-state, .loading {
  color: var(--muted);
  text-align: center;
  padding: 48px;
  font-size: 13px;
}

/* ── LOGIN ─────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px;
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-box h1 { font-family: var(--font-mono); font-size: 22px; color: var(--accent); margin-bottom: 4px; }
.login-box p  { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.login-box input {
  display: block; width: 100%;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  padding: 11px 14px; font-family: var(--font-body); font-size: 14px;
  margin-bottom: 12px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 12px;
  background: var(--accent); color: #0a1f13;
  font-weight: 700; font-size: 14px;
  border: none; border-radius: 8px; cursor: pointer;
  margin-top: 4px; transition: opacity .15s;
}
.login-box button:hover { opacity: .85; }
#login-error { color: var(--danger); font-size: 12px; margin-bottom: 12px; min-height: 16px; }

/* ── PENDING CARDS ──────────────────────────────────── */
#pending-list { display: flex; flex-direction: column; gap: 12px; }
.pending-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent2);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.pending-card.trade { border-left-color: #8b5cf6; }
.pending-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pending-type {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--accent2);
}
.pending-card.trade .pending-type { color: #8b5cf6; }
.pending-client { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.pending-msg    { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.pending-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Textarea style global */
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-family: var(--font-body);
  font-size: 13px;
  resize: vertical;
  outline: none;
}
textarea:focus { border-color: var(--accent); }