/* ============================================================
   WhatsApp Gateway — dark, WhatsApp-inspired theme
   ============================================================ */

:root {
  --bg: #0b141a;
  --bg-soft: #111b21;
  --card: #111b21;
  --card-border: #202c33;
  --card-border-hover: #2a3942;
  --text: #e9edef;
  --text-dim: #8696a0;
  --text-faint: #667781;
  --accent: #00a884;
  --accent-strong: #25d366;
  --accent-dim: rgba(0, 168, 132, 0.14);
  --warn: #f5c451;
  --bad: #f15c6d;
  --neutral: #8696a0;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* the `hidden` attribute must always win over any display rule */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(0, 168, 132, 0.14), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(37, 211, 102, 0.07), transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------- Login screen ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 36px 32px 30px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 45%), var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.4s ease both;
}
.login-card h1 {
  margin: 14px 0 0;
  font-size: 1.25rem;
  text-align: center;
}
.login-sub {
  margin: 2px 0 18px;
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
}
.login-brand {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 16px;
}
.login-brand svg { width: 32px; height: 32px; }
.login-card .field { margin-bottom: 14px; }
.login-btn { width: 100%; margin-top: 6px; }
.login-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  text-align: center;
  background: rgba(241, 92, 109, 0.1);
  border: 1px solid rgba(241, 92, 109, 0.3);
  color: #ff9ba8;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--card-border);
  background: rgba(17, 27, 33, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-icon {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #1fad6e);
  box-shadow: 0 6px 18px rgba(0, 168, 132, 0.35);
}
.brand-icon svg { width: 28px; height: 28px; }

.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.2px;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-small { padding: 8px 14px; font-size: 0.8rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s;
}
.pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--neutral);
  transition: background 0.25s;
}
.pill[data-tone="ok"] { color: var(--accent-strong); border-color: rgba(37, 211, 102, 0.35); }
.pill[data-tone="ok"] .dot { background: var(--accent-strong); box-shadow: 0 0 10px var(--accent-strong); }
.pill[data-tone="warn"] { color: var(--warn); border-color: rgba(245, 196, 81, 0.35); }
.pill[data-tone="warn"] .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.pill[data-tone="bad"] { color: var(--bad); border-color: rgba(241, 92, 109, 0.4); }
.pill[data-tone="bad"] .dot { background: var(--bad); animation: pulse 1.4s ease-in-out infinite; }
.pill[data-tone="neutral"] { color: var(--text-dim); }
.pill[data-tone="neutral"] .dot { background: var(--neutral); animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

/* ---------- Session bar ---------- */

.session-bar {
  max-width: 1100px;
  margin: 20px auto -6px;
  padding: 0 clamp(16px, 4vw, 40px);
}

.session-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.session-bar-head h2 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.session-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.session-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.session-chip:hover { border-color: var(--card-border-hover); transform: translateY(-1px); }
.session-chip[data-active="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 168, 132, 0.35);
}

.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--neutral);
}
.session-chip[data-tone="ok"] .session-dot { background: var(--accent-strong); box-shadow: 0 0 8px var(--accent-strong); }
.session-chip[data-tone="warn"] .session-dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.session-chip[data-tone="bad"] .session-dot { background: var(--bad); animation: pulse 1.4s ease-in-out infinite; }

.session-chip-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.session-chip-state {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
}

.chip-delete {
  width: 20px;
  height: 20px;
  margin-left: 2px;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--text-faint);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
}
.session-chip:hover .chip-delete, .session-chip:focus-within .chip-delete {
  opacity: 1;
}
.chip-delete:hover {
  color: var(--bad);
  background: rgba(241, 92, 109, 0.15);
}

.session-empty {
  margin: 4px 0;
  font-size: 0.82rem;
  color: var(--text-faint);
}

.session-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  max-width: 560px;
}
.session-add input { flex: 1 1 160px; padding: 10px 14px; min-width: 0; }
.session-add .btn-add { flex: none; }
.btn-add {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent-strong);
  padding: 10px 16px;
  flex: none;
}
.btn-add:hover { background: var(--accent-dim); }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 22px;
  padding: 26px clamp(16px, 4vw, 40px) 60px;
  max-width: 1100px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .brand-text p { display: none; }
}

.right-col {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

/* ---------- Cards ---------- */

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 40%), var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: border-color 0.25s ease, transform 0.25s ease;
  animation: rise 0.45s ease both;
}
.card:hover { border-color: var(--card-border-hover); }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}
.card-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}

.tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}
.tag[data-tone="ok"] { color: var(--accent-strong); background: rgba(37, 211, 102, 0.12); }
.tag[data-tone="warn"] { color: var(--warn); background: rgba(245, 196, 81, 0.12); }
.tag[data-tone="bad"] { color: var(--bad); background: rgba(241, 92, 109, 0.12); }
.tag-soft { text-transform: none; letter-spacing: 0; font-weight: 600; }

/* ---------- QR panel ---------- */

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-height: 300px;
}

#qr-img {
  width: 280px;
  height: 280px;
  padding: 12px;
  background: #fff;
  border-radius: 14px;
  image-rendering: pixelated;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: pop 0.35s ease;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.qr-placeholder {
  width: 280px;
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1.5px dashed var(--card-border-hover);
  border-radius: 14px;
  color: var(--text-faint);
  text-align: center;
  padding: 20px;
}
.qr-placeholder p { margin: 0; font-size: 0.85rem; }
.qr-placeholder svg { opacity: 0.7; }

.qr-hint {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  max-width: 300px;
  animation: rise 0.4s ease;
}
.qr-hint strong { color: var(--text); }
.qr-hint b { color: var(--text); font-weight: 600; }

/* ---------- Account ---------- */

.account {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 168, 132, 0.28);
  animation: pop 0.3s ease;
}
.account-check {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
}
.account-check svg { width: 20px; height: 20px; }
.account-info { min-width: 0; }
.account-name { margin: 0; font-weight: 700; font-size: 0.95rem; }
.account-id {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Error box ---------- */

.error-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.8rem;
  background: rgba(241, 92, 109, 0.1);
  border: 1px solid rgba(241, 92, 109, 0.3);
  color: #ff9ba8;
  word-break: break-word;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease, opacity 0.2s;
}
.btn:focus-visible { outline: 3px solid rgba(37, 211, 102, 0.4); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #1fad6e);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 168, 132, 0.3);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0, 168, 132, 0.4); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  border-color: var(--card-border-hover);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.connect-actions { margin-top: 16px; display: flex; justify-content: center; }

/* ---------- Forms ---------- */

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px 14px;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:hover, textarea:hover { border-color: var(--card-border-hover); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(0, 168, 132, 0.05);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.15);
}
input:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
textarea { resize: vertical; min-height: 96px; }

#send-form .btn { width: 100%; }
.form-hint {
  margin: 12px 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- Activity log ---------- */

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 380px; overflow-y: auto; }

.log-item {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  animation: rise 0.3s ease;
}
.log-in { border-left: 3px solid var(--warn); }
.log-out { border-left: 3px solid var(--accent-strong); }

.log-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.log-who {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-dim);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.log-time { font-size: 0.7rem; color: var(--text-faint); flex: none; }
.log-text { margin: 0; font-size: 0.87rem; color: var(--text); word-break: break-word; white-space: pre-wrap; }

.log-empty {
  margin: 18px 0 6px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-faint);
}

/* scrollbar */
.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--card-border-hover); border-radius: 4px; }
.log::-webkit-scrollbar-track { background: transparent; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: #fff;
  background: #233138;
  border: 1px solid var(--card-border-hover);
  box-shadow: var(--shadow);
  z-index: 50;
  animation: toast-in 0.3s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast[data-tone="ok"] { background: rgba(0, 168, 132, 0.95); }
.toast[data-tone="bad"] { background: rgba(241, 92, 109, 0.95); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* loading state on send button */
.btn.is-loading { pointer-events: none; opacity: 0.8; }
.btn.is-loading svg { animation: spin 0.8s linear infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
