:root {
  --bg: #0a0f14;
  --panel: #121922;
  --panel-2: #1a2330;
  --border: #232e3d;
  --text: #e6edf3;
  --muted: #7c8b9a;
  --accent: #33d6a6;
  --accent-dim: #1f8f6d;
  --warn: #e8a33d;
  --danger: #e5484d;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 15px;
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(51,214,166,0.15);
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(51,214,166,0.08), transparent 40%),
    var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 320px;
  text-align: center;
}
.login-sub { color: var(--muted); font-size: 13px; margin: 10px 0 20px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 14px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 12px; border-radius: 8px; border: none;
  background: var(--accent); color: #04140f; font-weight: 600;
  font-family: var(--font-display); cursor: pointer; font-size: 14px;
}
.login-card button:hover { background: #45e0b5; }
.login-error { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 10px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh;
}

.conn-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  font-family: var(--font-mono);
}
.conn-pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  flex-shrink: 0;
}
.conn-pulse.live { background: var(--accent); animation: pulse 1.6s infinite; }
.conn-pulse.connecting { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(51,214,166,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(51,214,166,0); }
  100% { box-shadow: 0 0 0 0 rgba(51,214,166,0); }
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: none; border: none; color: var(--muted);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
  font-family: var(--font-body); font-weight: 500;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--accent); }

.logout-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 9px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

.main { flex: 1; padding: 32px 40px; max-width: 1100px; }

.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 24px; }
.view-header h1 {
  font-family: var(--font-display); font-size: 24px; margin: 0 0 6px;
}
.view-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; max-width: 560px; }

.primary-btn {
  background: var(--accent); color: #04140f; border: none;
  padding: 10px 16px; border-radius: 8px; font-weight: 600;
  font-family: var(--font-display); font-size: 13px; cursor: pointer;
}
.primary-btn:hover { background: #45e0b5; }

.ghost-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 10px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
}

/* ---------- Chats ---------- */
.split { display: flex; gap: 20px; height: 68vh; }
.chat-list {
  width: 300px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel);
}
.chat-item {
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.selected { background: var(--panel-2); border-left: 2px solid var(--accent); }
.chat-item .phone { font-family: var(--font-mono); font-size: 12.5px; }
.chat-item .preview { color: var(--muted); font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-badge {
  display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 20px;
  margin-top: 6px; font-family: var(--font-mono);
}
.mode-badge.bot { background: rgba(51,214,166,0.12); color: var(--accent); }
.mode-badge.human { background: rgba(232,163,61,0.14); color: var(--warn); }

.chat-detail {
  flex: 1; border: 1px solid var(--border); border-radius: 10px; background: var(--panel);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-detail-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 75%; padding: 9px 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.4; }
.msg.user { align-self: flex-start; background: var(--panel-2); }
.msg.bot { align-self: flex-end; background: rgba(51,214,166,0.12); border: 1px solid rgba(51,214,166,0.25); }
.msg-time { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; font-family: var(--font-mono); }

.toggle-mode-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 7px; cursor: pointer; font-size: 12px;
}

.empty-state { color: var(--muted); font-size: 13px; padding: 30px; text-align: center; width: 100%; }

/* ---------- Products ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.product-card {
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel); padding: 16px;
}
.product-card h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 15px; }
.product-card .kw { font-family: var(--font-mono); font-size: 11.5px; color: var(--accent); margin-bottom: 10px; }
.product-card .status { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.product-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.product-card-actions button { flex: 1; font-size: 12px; padding: 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; }
.product-card-actions button.danger { color: var(--danger); }

/* ---------- Settings ---------- */
.settings-form { display: flex; flex-direction: column; gap: 6px; max-width: 620px; }
.settings-form label { font-size: 12.5px; color: var(--muted); margin-top: 14px; }
.settings-form textarea, .settings-form input[type=text] {
  width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-family: var(--font-body); font-size: 13.5px; resize: vertical;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.saved-msg { color: var(--accent); font-size: 12px; margin-left: 12px; }

/* ---------- Payments table ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--panel-2); }
td.mono { font-family: var(--font-mono); font-size: 12px; }
.status-pill { padding: 2px 9px; border-radius: 20px; font-size: 11px; }
.status-pill.success { background: rgba(51,214,166,0.14); color: var(--accent); }
.status-pill.pending { background: rgba(232,163,61,0.14); color: var(--warn); }
.status-pill.failed { background: rgba(229,72,77,0.14); color: var(--danger); }

/* ---------- QR ---------- */
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); max-width: 340px; }
.qr-wrap img { width: 240px; height: 240px; border-radius: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,8,12,0.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 26px; width: 420px; }
.modal-card h2 { font-family: var(--font-display); margin: 0 0 16px; font-size: 18px; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.modal-card input, .modal-card textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: var(--font-body); resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 14px; gap: 12px; overflow-x: auto; }
  .nav { flex-direction: row; }
  .main { padding: 20px; }
  .split { flex-direction: column; height: auto; }
  .chat-list { width: 100%; max-height: 220px; }
}
