:root {
  --wa: #25D366; --wa-dark: #128C7E; --wa-deep: #075E54;
  --wa-light: #DCF8C6; --wa-bg: #ECE5DD;
  --surface: #fff; --text: #111b21; --muted: #667781;
  --border: #e9edef; --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--surface); color: var(--text); }

.app-loading { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--wa-deep); }
.spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--wa); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-root { display: flex; flex-direction: column; height: 100%; max-height: 100dvh; }
.app-header {
  background: var(--wa-deep); color: white;
  padding: calc(0.65rem + env(safe-area-inset-top, 0px)) 1rem 0.65rem;
  display: flex; align-items: center; gap: 0.65rem;
  flex-shrink: 0;
}
.app-header h1 { font-size: 1.1rem; font-weight: 800; margin: 0; flex: 1; }
.app-header .back { background: none; border: none; color: white; font-size: 1.25rem; padding: 0.25rem; cursor: pointer; }

.app-main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.bottom-nav {
  display: flex; border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  background: var(--surface); flex-shrink: 0;
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 0.15rem; padding: 0.55rem 0.25rem;
  border: none; background: none; font: inherit;
  font-size: 0.65rem; font-weight: 600; color: var(--muted);
  cursor: pointer;
}
.nav-tab.active { color: var(--wa-dark); }
.nav-tab svg { width: 22px; height: 22px; }

/* Auth */
.auth-wrap {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: 1.5rem; background: linear-gradient(160deg, var(--wa-deep), #111b21);
}
.auth-box { background: white; border-radius: 20px; padding: 1.75rem; }
.auth-logo { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; font-weight: 800; font-size: 1.25rem; }
.auth-logo span.icon { width: 40px; height: 40px; background: var(--wa); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; }
.auth-input { width: 100%; padding: 0.85rem; border: 1px solid var(--border); border-radius: 12px; font: inherit; margin-bottom: 0.65rem; }
.btn-wa { width: 100%; padding: 0.85rem; border: none; border-radius: 12px; background: linear-gradient(135deg, var(--wa), var(--wa-dark)); color: white; font: inherit; font-weight: 700; cursor: pointer; }
.btn-ghost { background: none; border: none; color: var(--muted); font: inherit; width: 100%; margin-top: 0.5rem; padding: 0.5rem; }

/* Chat list */
.conv-list { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.conv-row {
  display: flex; gap: 0.75rem; padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border); cursor: pointer;
  active: background #f5f6f6;
}
.conv-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--wa), var(--wa-dark));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem; flex-shrink: 0;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.conv-name { font-weight: 700; font-size: 0.95rem; }
.conv-time { font-size: 0.72rem; color: var(--muted); }
.conv-preview { font-size: 0.82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 0.15rem; }
.badge { background: var(--wa); color: white; font-size: 0.65rem; font-weight: 700; padding: 0.1rem 0.4rem; border-radius: 999px; }

/* Thread */
.thread { flex: 1; overflow-y: auto; padding: 0.75rem; background: var(--wa-bg); -webkit-overflow-scrolling: touch; }
.msg { max-width: 82%; margin-bottom: 0.45rem; padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.92rem; line-height: 1.4; }
.msg.in { background: white; border-top-left-radius: 0; margin-right: auto; }
.msg.out { background: var(--wa-light); border-top-right-radius: 0; margin-left: auto; }
.msg-meta { font-size: 0.62rem; color: var(--muted); text-align: right; margin-top: 0.15rem; }

.compose-bar {
  display: flex; gap: 0.5rem; padding: 0.5rem 0.75rem calc(0.5rem + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end;
}
.compose-bar textarea {
  flex: 1; border: 1px solid var(--border); border-radius: 20px;
  padding: 0.55rem 0.85rem; font: inherit; resize: none; max-height: 100px;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--wa); color: white; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}

.account { padding: 1.25rem; }
.account-card { background: #f0f2f5; border-radius: 14px; padding: 1rem; margin-bottom: 1rem; }
.account-card strong { display: block; margin-bottom: 0.25rem; }
.account-card span { font-size: 0.85rem; color: var(--muted); }

.toast {
  position: fixed; bottom: calc(4.5rem + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 0.65rem 1rem; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600; z-index: 999; white-space: nowrap;
}
.empty { padding: 2rem 1.5rem; text-align: center; color: var(--muted); font-size: 0.9rem; }
