:root { --red: #e01a1a; --ink: #16181d; --muted: #6b7280; --line: #e5e7eb; --bg: #f5f6f8; --in: #ffffff; --out: #dcf8c6; }
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button { font: inherit; border: 0; border-radius: 8px; padding: 9px 16px; background: var(--red); color: #fff; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; color: var(--ink); width: 100%; }
textarea { resize: vertical; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); margin: 0; }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 14px; }

.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #25d366; }
.numbers { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.numbers button { background: transparent; color: var(--ink); border: 1px solid var(--line); padding: 6px 12px; white-space: nowrap; }
.numbers button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.me { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

.body { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.list { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.list input { margin: 12px; width: auto; }
.threads { overflow-y: auto; flex: 1; }
.thread { display: block; width: 100%; text-align: left; background: #fff; color: var(--ink); border-radius: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
.thread:hover { background: #fafafa; }
.thread.active { background: #fdecec; }
.thread .row { display: flex; justify-content: space-between; gap: 8px; }
.thread .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.thread .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .badge { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #25d366; margin-right: 6px; }

.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.conv { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-head { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 12px; align-items: baseline; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 8px 12px; border-radius: 10px; background: var(--in); box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .meta { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); text-align: right; }
.reply { display: flex; gap: 10px; padding: 12px 18px; background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.template { padding: 12px 18px; background: #fff; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.template p { margin: 0; }
.template-row { display: flex; gap: 10px; }
.template-params { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 90%; }

@media (max-width: 760px) {
  .body { grid-template-columns: 1fr; }
  .app.reading .list { display: none; }
  .app:not(.reading) .chat { display: none; }
  .top { flex-wrap: wrap; }
}
button.small { padding: 5px 10px; font-size: 13px; }
.back { display: none; }
@media (max-width: 760px) { .back { display: inline-block; } }
