/* ------------------------------------------------------------------
   WhatsApp Platform - UI
   ------------------------------------------------------------------ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --text: #101828;
  --text-muted: #667085;
  --brand: #128c7e;
  --brand-dark: #0b6b60;
  --brand-soft: #e7f5f2;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --success: #067647;
  --success-soft: #ecfdf3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .9rem; margin: 0 0 .5rem; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .875em; }
.muted { color: var(--text-muted); }
.small { font-size: .825rem; }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar__inner {
  max-width: 1180px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; align-items: center; gap: 1.5rem; height: 58px;
}
.brand { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.brand__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }

.nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; }
.nav a {
  padding: .45rem .7rem; border-radius: 7px; color: var(--text-muted); font-weight: 500; font-size: .9rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--brand-soft); color: var(--brand-dark); }

.page { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.page-head { margin-bottom: 1.5rem; }

.grid { display: grid; gap: 1rem; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

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

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.15rem;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: .9rem;
}
.card__head h2 { margin: 0; }

.stat__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.stat__value { font-size: 1.75rem; font-weight: 650; line-height: 1.2; margin-top: .2rem; letter-spacing: -.02em; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; font-weight: 550;
  cursor: pointer; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn--danger { color: var(--danger); border-color: #fecdca; background: var(--danger-soft); }
.btn--sm { padding: .35rem .65rem; font-size: .82rem; }
.btn--lg { padding: .8rem 1.5rem; font-size: 1rem; }

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

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .85rem; font-weight: 550; margin-bottom: .3rem; }
.input, .select, .textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; font-size: .9rem; background: var(--surface); color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.textarea { resize: vertical; min-height: 90px; }
.hint { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* ---- Tables ------------------------------------------------------ */

.table { width: 100%; border-collapse: collapse; font-size: .885rem; }
.table th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600; padding: .5rem .65rem; border-bottom: 1px solid var(--border);
}
.table td { padding: .65rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* ---- Badges ------------------------------------------------------ */

.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge--ok { background: var(--success-soft); color: var(--success); border-color: #abefc6; }
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: #fedf89; }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.badge--info { background: var(--brand-soft); color: var(--brand-dark); border-color: #b9e3da; }

/* ---- Alerts ------------------------------------------------------ */

.alert {
  padding: .8rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); margin-bottom: 1rem; font-size: .9rem;
}
.alert ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.alert--success { background: var(--success-soft); border-color: #abefc6; color: var(--success); }
.alert--warn { background: var(--warn-soft); border-color: #fedf89; color: var(--warn); }
.alert--error { background: var(--danger-soft); border-color: #fecdca; color: var(--danger); }
.alert--info { background: var(--brand-soft); border-color: #b9e3da; color: var(--brand-dark); }

/* ---- Embedded signup --------------------------------------------- */

.es-hero { text-align: center; padding: 2rem 1.5rem; }
.es-status { margin: 1rem 0; font-size: .9rem; font-weight: 500; }
.es-status--idle { color: var(--text-muted); }
.es-status--busy { color: var(--brand-dark); }
.es-status--success { color: var(--success); }
.es-status--warn { color: var(--warn); }
.es-status--error { color: var(--danger); }

.es-steps { list-style: none; padding: 0; margin: 1rem auto; max-width: 26rem; text-align: left; }
.es-step {
  padding: .4rem 0 .4rem 1.6rem; position: relative; font-size: .875rem; color: var(--text-muted);
}
.es-step--done::before {
  content: "✓"; position: absolute; left: 0; color: var(--success); font-weight: 700;
}
.es-numbers { list-style: none; padding: 0; margin: .75rem 0; }
.es-numbers li { padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }

/* ---- Inbox ------------------------------------------------------- */

.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; height: calc(100vh - 58px - 3.5rem); }
@media (max-width: 860px) { .inbox { grid-template-columns: 1fr; height: auto; } }

.thread-list { overflow-y: auto; padding: 0; }
.thread {
  display: block; width: 100%; text-align: left; padding: .75rem .9rem;
  border: none; border-bottom: 1px solid var(--border); background: none; cursor: pointer; font: inherit;
}
.thread:hover { background: var(--surface-2); }
.thread.is-active { background: var(--brand-soft); }
.thread__top { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.thread__name { font-weight: 600; font-size: .9rem; }
.thread__time { font-size: .74rem; color: var(--text-muted); white-space: nowrap; }
.thread__preview {
  font-size: .82rem; color: var(--text-muted); margin-top: .15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread__unread {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: .7rem; text-align: center; font-weight: 700;
}

.chat { display: flex; flex-direction: column; min-height: 420px; padding: 0; }
.chat__head { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); }
.chat__body { flex: 1; overflow-y: auto; padding: 1.1rem; background: var(--surface-2); }
.chat__foot { padding: .8rem 1.1rem; border-top: 1px solid var(--border); }

.bubble {
  max-width: 74%; padding: .5rem .75rem; border-radius: 10px; margin-bottom: .55rem;
  font-size: .9rem; word-wrap: break-word; white-space: pre-wrap;
}
.bubble--in { background: var(--surface); border: 1px solid var(--border); }
.bubble--out { background: var(--brand-soft); border: 1px solid #b9e3da; margin-left: auto; }
.bubble--failed { background: var(--danger-soft); border-color: #fecdca; }
.bubble__meta {
  font-size: .7rem; color: var(--text-muted); margin-top: .25rem;
  display: flex; gap: .4rem; align-items: center; justify-content: flex-end;
}
.bubble--in .bubble__meta { justify-content: flex-start; }
.bubble img, .bubble video { max-width: 100%; border-radius: 6px; display: block; }

.composer { display: flex; gap: .5rem; align-items: flex-end; }
.composer .textarea { min-height: 42px; max-height: 140px; }

.window-warning {
  background: var(--warn-soft); border: 1px solid #fedf89; color: var(--warn);
  padding: .6rem .8rem; border-radius: 8px; font-size: .85rem; margin-bottom: .6rem;
}

/* ---- Auth -------------------------------------------------------- */

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.auth-card { width: 100%; max-width: 25rem; }
.auth-card .card { padding: 1.75rem; }

/* ---- Misc -------------------------------------------------------- */

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.flex { display: flex; gap: .5rem; align-items: center; }
.flex--between { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .875rem;
}
.checklist li:last-child { border-bottom: none; }
.check-icon { flex: none; font-weight: 700; }
.check-icon--ok { color: var(--success); }
.check-icon--bad { color: var(--danger); }
