:root {
  --wa-green: #00a884;
  --wa-green-bright: #25d366;
  --wa-green-dim: #005c4b;
  --wa-bg: #0b141a;
  --wa-surface: #111b21;
  --wa-surface-2: #1f2c34;
  --wa-surface-3: #202c33;
  --wa-border: #2a3942;
  --wa-text: #e9edef;
  --wa-muted: #8696a0;
  --wa-danger: #ea4335;
  --wa-warning: #f4c430;
  --wa-info: #53bdeb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--wa-bg);
  color: var(--wa-text);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(0, 168, 132, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(37, 211, 102, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

/* ── Header ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--wa-green-bright), var(--wa-green));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 168, 132, 0.35);
}

.brand-icon svg { width: 26px; height: 26px; fill: #fff; }

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--wa-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--wa-surface-2);
  border: 1px solid var(--wa-border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--wa-muted);
}

.user-chip strong { color: var(--wa-text); font-weight: 500; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--wa-surface);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--wa-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card.total .value { color: var(--wa-text); }
.stat-card.connected .value { color: var(--wa-green-bright); }
.stat-card.qr .value { color: var(--wa-warning); }
.stat-card.inactive .value { color: var(--wa-muted); }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: stretch;
  background: var(--wa-surface);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 24px;
}

.toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
}

/* ── Cards & channels ── */
.channels-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.channel-card {
  background: var(--wa-surface);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.channel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--wa-border);
  background: var(--wa-surface-3);
}

.channel-title h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.channel-meta {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--wa-muted);
  line-height: 1.5;
}

.channel-body {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 0;
}

@media (max-width: 860px) {
  .channel-body { grid-template-columns: 1fr; }
}

.channel-main { padding: 20px; }

.channel-side {
  padding: 20px;
  background: var(--wa-surface-2);
  border-left: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

@media (max-width: 860px) {
  .channel-side {
    border-left: none;
    border-top: 1px solid var(--wa-border);
  }
}

.section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--wa-muted);
  margin: 0 0 10px;
}

.section { margin-bottom: 20px; }
.section:last-child { margin-bottom: 0; }

.field-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.field-row input { flex: 1; min-width: 180px; }

/* ── Status badges ── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.connected {
  background: rgba(37, 211, 102, 0.15);
  color: var(--wa-green-bright);
}

.status-pill.qr {
  background: rgba(244, 196, 48, 0.15);
  color: var(--wa-warning);
}

.status-pill.connecting {
  background: rgba(83, 189, 235, 0.15);
  color: var(--wa-info);
}

.status-pill.inactive,
.status-pill.disconnected {
  background: rgba(134, 150, 160, 0.15);
  color: var(--wa-muted);
}

/* ── QR panel ── */
.qr-panel .qr-img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px;
}

.qr-placeholder {
  width: 200px;
  height: 200px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--wa-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--wa-muted);
  font-size: 0.8rem;
  padding: 16px;
}

.qr-hint {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--wa-muted);
  line-height: 1.45;
  max-width: 220px;
}

/* ── Contacts ── */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 4px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--wa-surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--wa-border);
}

.contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--wa-surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--wa-muted);
  flex-shrink: 0;
}

.contact-phone {
  font-size: 0.82rem;
  font-family: ui-monospace, monospace;
}

/* ── Integration accordion ── */
details.integration-panel {
  border: 1px solid var(--wa-border);
  border-radius: var(--radius-sm);
  background: var(--wa-surface-2);
}

details.integration-panel summary {
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--wa-text);
  list-style: none;
  user-select: none;
}

details.integration-panel summary::-webkit-details-marker { display: none; }

details.integration-panel summary::after {
  content: "▾";
  float: right;
  color: var(--wa-muted);
  transition: transform 0.2s;
}

details.integration-panel[open] summary::after { transform: rotate(180deg); }

details.integration-panel .integration-body {
  padding: 0 14px 14px;
  font-size: 0.8rem;
  color: var(--wa-muted);
  line-height: 1.55;
}

details.integration-panel code {
  background: var(--wa-surface);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.78rem;
}

.code-block {
  margin-top: 10px;
  background: var(--wa-bg);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
  color: var(--wa-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}

/* ── Buttons & inputs ── */
input[type="text"],
input[type="password"] {
  background: var(--wa-surface-2);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--wa-text);
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--wa-green);
}

input[readonly] {
  color: var(--wa-muted);
  cursor: default;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--wa-green);
  color: #fff;
}

.btn-primary:hover { background: var(--wa-green-bright); }

.btn-secondary {
  background: var(--wa-surface-2);
  color: var(--wa-text);
  border-color: var(--wa-border);
}

.btn-secondary:hover { background: var(--wa-surface-3); }

.btn-ghost {
  background: transparent;
  color: var(--wa-muted);
  border-color: var(--wa-border);
}

.btn-ghost:hover { color: var(--wa-text); background: var(--wa-surface-2); }

.btn-danger {
  background: rgba(234, 67, 53, 0.12);
  color: #ff8a80;
  border-color: rgba(234, 67, 53, 0.3);
}

.btn-danger:hover { background: rgba(234, 67, 53, 0.22); }

.btn-sm { padding: 7px 12px; font-size: 0.78rem; }

.btn-icon { padding: 8px 10px; }

.channel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--wa-surface);
  border: 1px dashed var(--wa-border);
  border-radius: var(--radius);
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--wa-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wa-muted);
}

.empty-state h3 { margin: 0 0 8px; font-size: 1.1rem; }
.empty-state p { margin: 0; color: var(--wa-muted); font-size: 0.9rem; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--wa-surface-3);
  border: 1px solid var(--wa-border);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  animation: toast-in 0.25s ease;
  max-width: 360px;
}

.toast.error { border-color: rgba(234, 67, 53, 0.5); color: #ff8a80; }
.toast.success { border-color: rgba(37, 211, 102, 0.5); color: var(--wa-green-bright); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--wa-surface);
  border: 1px solid var(--wa-border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-card .brand {
  justify-content: center;
  flex-direction: column;
  text-align: center;
  margin-bottom: 28px;
}

.login-card label {
  display: block;
  font-size: 0.78rem;
  color: var(--wa-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.login-card input { width: 100%; margin-bottom: 14px; }

.login-card .btn { width: 100%; margin-top: 4px; }

.login-error {
  color: #ff8a80;
  font-size: 0.8rem;
  min-height: 20px;
  margin-top: 12px;
  text-align: center;
}

/* ── Loading ── */
.loading-bar {
  height: 3px;
  background: var(--wa-border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 20px;
  display: none;
}

.loading-bar.active { display: block; }

.loading-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--wa-green);
  border-radius: 2px;
  animation: loading-slide 1s ease infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.muted { color: var(--wa-muted); font-size: 0.8rem; }
