:root {
  --bg: #eef2f0;
  --panel: #ffffff;
  --text: #16201b;
  --muted: #6b7a73;
  --line: #dfe6e2;
  --brand: #1f9d6b;
  --brand-ink: #ffffff;
  --in: #ffffff;
  --out: #d9f5e6;
  --bn: #0d6b47;
  --chip: #f3f6f4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --panel: #17201c;
    --text: #e6eeea;
    --muted: #8d9c95;
    --line: #26322d;
    --brand: #22b47b;
    --in: #1d2823;
    --out: #164a33;
    --bn: #7fe0b2;
    --chip: #1f2a25;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Hind Siliguri", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

.view { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }
.center { align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 18px; padding: 26px 20px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.card h1 { margin: 10px 0 4px; font-size: 22px; }
.card input { width: 100%; margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 17px; }
.logo { width: 60px; height: 60px; margin: 0 auto; border-radius: 18px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.muted { color: var(--muted); font-size: 14px; }
.err { color: #d64545; font-size: 14px; min-height: 1em; margin: 10px 0 0; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; width: 100%; margin-top: 12px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--brand); color: #fff; }
.bar h2 { margin: 0; font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-wrap { flex: 1; min-width: 0; }
.title-wrap h2 { flex: none; }
.title-wrap small { color: rgba(255,255,255,.85); font-size: 12px; }
.badge { font-size: 12px; background: rgba(255,255,255,.2); padding: 3px 8px; border-radius: 99px; }
.icon { border: 0; background: transparent; cursor: pointer; width: 42px; height: 42px; border-radius: 50%; font-size: 20px; flex: none; display: grid; place-items: center; }
#b-back { color: #fff; font-size: 30px; line-height: 1; }
#c-lang { background: rgba(255,255,255,.18); border: 0; border-radius: 10px; padding: 6px 8px; color: #fff; max-width: 130px; font-size: 14px; }
#c-lang option { color: #000; }

.search { padding: 10px 12px; }
.search input { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
.dialogs { list-style: none; margin: 0; padding: 0 0 env(safe-area-inset-bottom); overflow-y: auto; flex: 1; }
.dialogs li { display: flex; gap: 12px; padding: 11px 14px; background: var(--panel); border-bottom: 1px solid var(--line); cursor: pointer; }
.dialogs li:active { background: var(--chip); }
.avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; }
.d-main { flex: 1; min-width: 0; }
.d-top { display: flex; justify-content: space-between; gap: 8px; }
.d-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-time { color: var(--muted); font-size: 12px; flex: none; }
.d-last { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-bn { color: var(--bn); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-unread { background: var(--brand); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 7px; margin-left: 6px; }

.msgs { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.more { align-self: center; border: 0; background: var(--panel); border-radius: 99px; padding: 6px 14px; color: var(--muted); font-size: 13px; cursor: pointer; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 2px 10px; border-radius: 99px; margin: 6px 0; }
.msg { max-width: 84%; padding: 8px 11px 5px; border-radius: 14px; background: var(--in); align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.05); overflow-wrap: anywhere; }
.msg.out { background: var(--out); align-self: flex-end; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--brand); }
.msg .orig { white-space: pre-wrap; }
.msg .bn { white-space: pre-wrap; color: var(--bn); border-top: 1px dashed var(--line); margin-top: 5px; padding-top: 4px; font-size: 15px; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .tag { display: block; font-size: 13px; color: var(--muted); }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; }
.msg .vbtn { border: 1px solid var(--line); background: var(--chip); border-radius: 99px; padding: 4px 12px; font-size: 13px; cursor: pointer; margin-top: 4px; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.composer .row { display: flex; align-items: flex-end; gap: 6px; }
#i-msg { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; background: var(--bg); max-height: 140px; outline: none; font-size: 16px; }
#i-msg:focus { border-color: var(--brand); }
.mic { background: var(--chip); }
.mic.rec { background: #e5484d; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.send { background: var(--brand); color: #fff; font-size: 18px; }
.preview { background: var(--chip); border-radius: 12px; padding: 6px 10px; margin-bottom: 6px; }
.pv-label { font-size: 12px; color: var(--muted); }
.pv-text { outline: none; white-space: pre-wrap; font-family: system-ui, -apple-system, sans-serif; }
.preview.loading .pv-text { opacity: .45; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #16201b; color: #fff; padding: 9px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; }
