:root {
  --brand: #008069;
  --brand-strong: #00a884;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --chat-bg: #efeae2;
  --out: #d9fdd3;
  --in: #ffffff;
  --tick-read: #53bdeb;
  --badge: #25d366;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --error: #d93025;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1317;
    --panel: #111b21;
    --panel-2: #202c33;
    --border: #222d34;
    --text: #e9edef;
    --muted: #8696a0;
    --chat-bg: #0b141a;
    --out: #005c4b;
    --in: #202c33;
    --hover: #202c33;
    --active: #2a3942;
    --error: #f28b82;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 8px 0 0; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(var(--brand) 0 220px, var(--bg) 220px); }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 12px;
  padding: 32px 28px; box-shadow: 0 8px 24px rgba(0,0,0,.12); text-align: center; }
.login-logo { width: 72px; height: 72px; }
.login-card h1 { margin: 8px 0 4px; font-size: 24px; }
.login-card form { text-align: left; margin-top: 20px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; outline: none; }
.login-card input:focus { border-color: var(--brand-strong); }
.login-card button[type=submit] { width: 100%; padding: 12px; border: 0; border-radius: 24px;
  background: var(--brand-strong); color: #fff; font-weight: 600; cursor: pointer; font-size: 16px; }
.login-card button[disabled] { opacity: .6; cursor: default; }
.field-hint { display: block; font-size: 12px; margin-top: 4px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin-top: 20px; }
.link { background: none; border: 0; padding: 0; color: var(--brand-strong); cursor: pointer; text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: minmax(300px, 30%) 1fr; height: 100vh; height: 100dvh;
  max-width: 1600px; margin: 0 auto; background: var(--panel); }
@media (min-width: 1440px) { body { padding: 19px 0; } .app { height: calc(100dvh - 38px); box-shadow: 0 6px 18px rgba(11,20,26,.05); } }

.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 59px;
  background: var(--panel-2); border-bottom: 1px solid var(--border); }
.bar-title { flex: 1; min-width: 0; }
.bar .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 8px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:hover { background: var(--hover); }
.back { display: none; margin-left: -8px; }

.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 15px; position: relative; user-select: none; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%;
  background: var(--badge); border: 2px solid var(--panel); }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; background: var(--panel); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search input { width: 100%; padding: 8px 14px; border: 0; border-radius: 8px; background: var(--panel-2); outline: none; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 0 0 0 14px; cursor: pointer; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item .avatar { width: 49px; height: 49px; font-size: 18px; }
.chat-item .body { flex: 1; min-width: 0; padding: 12px 14px 12px 0; border-bottom: 1px solid var(--border); }
.chat-item .row { display: flex; align-items: center; gap: 6px; }
.chat-item .title { flex: 1; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 12px; color: var(--muted); }
.chat-item.unread .time { color: var(--badge); }
.chat-item .preview { flex: 1; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .preview.typing { color: var(--badge); }
.chat-item .badge { background: var(--badge); color: #fff; font-size: 12px; font-weight: 600; min-width: 20px; height: 20px;
  border-radius: 10px; display: grid; place-items: center; padding: 0 6px; }
.chat-list .section { padding: 14px 16px 6px; font-size: 13px; color: var(--brand-strong); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Conversation ---------- */
.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.empty { flex: 1; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--panel-2); border-bottom: 6px solid var(--badge); }
.empty h2 { font-weight: 300; font-size: 30px; margin: 16px 0 8px; }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 2px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.day { align-self: center; margin: 10px 0; padding: 5px 12px; font-size: 12.5px; border-radius: 8px;
  background: var(--panel); color: var(--muted); box-shadow: var(--shadow); text-transform: uppercase; }
.msg { max-width: min(65%, 560px); padding: 6px 7px 8px 9px; border-radius: 8px; box-shadow: var(--shadow);
  position: relative; word-wrap: break-word; white-space: pre-wrap; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.in { align-self: flex-start; background: var(--in); }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.in.first { border-top-left-radius: 0; }
.msg.out.first { border-top-right-radius: 0; }
.msg .meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.tick { width: 16px; height: 11px; color: var(--muted); }
.tick.read { color: var(--tick-read); }
.load-more { align-self: center; margin: 4px 0 8px; font-size: 13px; color: var(--muted); }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 16px; background: var(--panel-2); }
.composer textarea { flex: 1; resize: none; border: 0; outline: none; border-radius: 8px; padding: 10px 12px;
  background: var(--panel); max-height: 140px; line-height: 1.35; }
.send-btn { border: 0; background: var(--brand-strong); color: #fff; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex: none; }

.attach { align-self: center; transform: rotate(45deg); }

/* ---------- Attachments ---------- */
.file-card { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 8px 10px; margin-bottom: 4px;
  border-radius: 6px; background: rgba(0,0,0,.05); color: inherit; text-decoration: none; white-space: normal; }
a.file-card:hover { background: rgba(0,0,0,.09); }
.file-card .ext { flex: none; width: 36px; height: 42px; border-radius: 4px; background: var(--brand-strong); color: #fff;
  font-size: 10px; font-weight: 700; display: grid; place-items: center; text-transform: uppercase; overflow: hidden; }
.file-card .info { flex: 1; min-width: 0; }
.file-card .fname { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fsize { font-size: 12px; color: var(--muted); }
.file-card .dl { flex: none; color: var(--muted); }
.progress { height: 4px; border-radius: 2px; background: rgba(0,0,0,.1); margin-top: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand-strong); transition: width .2s; }
.msg.failed .meta { color: var(--error); }
.drop-hint { outline: 3px dashed var(--brand-strong); outline-offset: -12px; }

/* ---------- Groups ---------- */
.sender { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.clickable { cursor: pointer; }
.avatar.group { font-size: 18px; }

/* ---------- Dialogs ---------- */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); max-height: 85vh;
  background: var(--panel); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(11,20,26,.55); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .dlg-head { background: var(--panel-2); } }
.dlg-head h3 { flex: 1; margin: 0; font-size: 17px; font-weight: 500; }
.dlg-head button { background: none; border: 0; color: inherit; font-size: 22px; cursor: pointer; line-height: 1; }
.dlg-body { padding: 16px; overflow-y: auto; max-height: calc(85vh - 120px); }
.dlg-body label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.dlg-body input[type=text], .dlg-body input[type=tel] { display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; outline: none; font-size: 15px; }
.dlg-body p { margin: 0 0 12px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.btn { border: 0; border-radius: 20px; padding: 9px 18px; font-weight: 600; cursor: pointer; background: var(--panel-2); color: var(--text); text-decoration: none; display: inline-block; }
.btn.primary { background: var(--brand-strong); color: #fff; }
.btn.wa { background: #25d366; color: #fff; }
.btn.danger { color: var(--error); }
.btn[disabled] { opacity: .5; cursor: default; }
.pick-list { list-style: none; margin: 0; padding: 0; }
.pick-list li { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.pick-list li label { display: flex; align-items: center; gap: 12px; margin: 0; flex: 1; color: var(--text); font-size: 15px; cursor: pointer; }
.pick-list .tag { font-size: 12px; color: var(--brand-strong); }
.invite-link { display: flex; gap: 8px; align-items: center; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; word-break: break-all; font-size: 13px; }
.invite-banner { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--panel);
  padding: 10px 18px; border-radius: 8px; z-index: 10; font-size: 14px; max-width: calc(100vw - 32px); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app .conversation { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .conversation { display: flex; }
  .back { display: grid; }
  .messages { padding: 12px 4%; }
  .msg { max-width: 85%; }
}
