:root {
  --bg: #f3f5fb;
  --sidebar: #151a23;
  --sidebar-text: #d6dde8;
  --accent: #6b4eff;
  --viber: #7360f2;
  --telegram: #2aabee;
  --whatsapp: #25d366;
  --card: #ffffff;
  --border: #e4e8f1;
  --danger: #e11d48;
  --ok: #059669;
  --muted: #6b7790;
  --text: #1a2233;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(107, 78, 255, 0.15), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(42, 171, 238, 0.12), transparent 35%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(21, 26, 35, 0.08);
}
.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
}
.auth-card p.lead {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  background: #f8f9fd;
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
}
.auth-forgot {
  text-align: right;
  margin: -4px 0 14px;
  font-size: 0.9rem;
}
.ok-box {
  display: none;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #e8f8ee;
  border: 1px solid #bfe8ca;
  color: #19663b;
  font-size: 0.92rem;
}
.ok-box.show { display: block; }
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.auth-links {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.error-box {
  background: #fff1f2;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  display: none;
}
.error-box.show { display: block; }

.app-shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 18px;
  color: #fff;
}
.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 800;
}
.nav-item {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 12px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}
.nav-item.active, .nav-item:hover {
  background: rgba(255,255,255,0.08);
}
.nav-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-footer {
  margin-top: auto;
  font-size: 0.8rem;
  color: #8b97ab;
}
.main {
  padding: 18px 22px 40px;
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.connect-btn {
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  cursor: pointer;
}
.connect-btn.viber { background: var(--viber); }
.connect-btn.telegram { background: var(--telegram); opacity: 0.55; cursor: not-allowed; }
.connect-btn.whatsapp { background: var(--whatsapp); opacity: 0.55; cursor: not-allowed; }
.topbar-right {
  margin-left: auto;
  display: flex;
  gap: 12px;
  align-items: center;
}
.user-chip {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.9rem;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.stat-card .value {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 4px 0;
}
.stat-card .label { color: var(--muted); font-size: 0.85rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  letter-spacing: 0.04em;
}
.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.toolbar input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 220px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; }
.badge {
  display: inline-block;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge.active { background: #d1fae5; color: var(--ok); }
.badge.deactivated, .badge.disabled, .badge.error { background: #ffe4e6; color: var(--danger); }
.badge.requires_activation, .badge.pending_connect { background: #fef3c7; color: #b45309; }
.empty {
  color: var(--muted);
  padding: 24px 8px;
  text-align: center;
}
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.btn-sm {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.45);
  display: none;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal-backdrop.show { display: grid; }
.modal {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 20px;
}
.modal h3 { margin: 0 0 12px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.key-reveal {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
  word-break: break-all;
}
.api-hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}
.gateway-banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  background: #fff;
}
.gateway-banner.mock {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}
.gateway-banner.live {
  border-color: #10b981;
  background: #ecfdf5;
  color: #065f46;
}
.lab-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}
.lab-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
}
.lab-result {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.82rem;
  overflow: auto;
  min-height: 48px;
  max-height: 240px;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .stats { grid-template-columns: 1fr 1fr; }
  .topbar-right { margin-left: 0; width: 100%; }
  .lab-grid { grid-template-columns: 1fr; }
}
