:root {
  --bg: #f8f9fc;
  --panel: #ffffff;
  --card: #ebeef4;
  --card-high: #e3e6ee;
  --outline: #c4c7d0;
  --on-surface: #1b1b1f;
  --muted: #5f6368;
  --primary: #0b57d0;
  --primary-container: #d3e3fd;
  --on-primary-container: #041e49;
  --sim: #7b2ff7;
  --menu: #ffffff;
  --shadow: 0 6px 24px rgba(0,0,0,.16);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c21;
    --panel: #111216;
    --card: #282a30;
    --card-high: #30323a;
    --outline: #44474f;
    --on-surface: #e3e3e8;
    --muted: #a8abb4;
    --primary: #a8c7fa;
    --primary-container: #0842a0;
    --on-primary-container: #d3e3fd;
    --menu: #2b2d34;
    --shadow: 0 6px 24px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Google Sans", Roboto, -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  padding-top: env(safe-area-inset-top);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.warn { color: #e46962; }
.center { text-align: center; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }

/* ---------- sign in / passphrase ---------- */
#signin, #pass-view { min-height: 90vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 24px; }
#signin h1, #pass-view h1 { margin: 0; font-size: 26px; font-weight: 500; }
.signin-logo { width: 88px; height: 88px; }
#pass-view .muted { max-width: 340px; }
#pass-input { width: 100%; max-width: 320px; padding: 14px 18px; border-radius: 28px;
  border: 1px solid var(--outline); background: var(--card); outline: none; }
button.primary { background: var(--primary-container); color: var(--on-primary-container);
  padding: 12px 24px; border-radius: 24px; font-weight: 500; }
button.icon { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; flex: 0 0 auto; }
button.icon:hover { background: var(--card); }

/* ---------- shared ---------- */
.appbar { position: sticky; top: 0; z-index: 4; display: flex; align-items: center;
  gap: 10px; padding: 10px 12px; background: var(--bg); }
.appbar .title { font-size: 21px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto; display: flex;
  align-items: center; justify-content: center; font-size: 22px; overflow: hidden; }
.avatar.small { width: 40px; height: 40px; font-size: 19px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.person { background: var(--card-high); color: var(--muted); }
.menu { position: absolute; z-index: 10; background: var(--menu); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px 0; min-width: 200px; }
.menu-label { padding: 10px 16px; font-size: 13px; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 16px; }
.menu-item:hover { background: var(--card); }
.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 20; }

/* ---------- conversation list ---------- */
.list-head { position: sticky; top: 0; z-index: 4; display: flex; align-items: center;
  padding: 14px 12px 4px 20px; background: var(--bg); }
.list-title { font-size: 24px; flex: 1; }
.account-wrap { position: relative; }
.account-btn { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px; }
.account-btn img { width: 100%; height: 100%; object-fit: cover; }
.account-wrap .menu { right: 0; top: 44px; }
.search-wrap { position: sticky; top: 58px; z-index: 3; margin: 6px 16px 4px; display: flex;
  align-items: center; gap: 10px; padding: 0 18px; border-radius: 28px;
  border: 1px solid var(--outline); background: var(--bg); }
.search-icon { font-size: 15px; opacity: .7; }
#search { flex: 1; border: none; background: none; outline: none; padding: 14px 0; }
.threads { display: flex; flex-direction: column; padding-bottom: 100px; }
.thread-row { display: flex; align-items: center; gap: 14px; padding: 10px 16px; cursor: pointer; }
.thread-row:hover { background: var(--card); }
.thread-main { flex: 1; min-width: 0; }
.thread-top { display: flex; align-items: baseline; gap: 8px; }
.thread-title { flex: 1; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time { color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.thread-snippet { color: var(--muted); font-size: 15px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { margin-top: 40px; line-height: 1.6; }
.fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px; background: var(--primary-container);
  color: var(--on-primary-container); padding: 16px 20px; border-radius: 16px;
  font-weight: 500; box-shadow: var(--shadow); z-index: 5; }

/* ---------- new chat ---------- */
.to-card { margin: 0 12px; padding: 14px 20px; border-radius: 28px; background: var(--card); }
.to-row { display: flex; align-items: center; min-height: 44px; }
.with-row { margin-top: 8px; }
.to-label { width: 56px; flex: 0 0 auto; font-size: 17px; }
#newchat-to { flex: 1; border: none; background: none; outline: none; font-size: 17px; padding: 8px 0; min-width: 0; }
#newchat-to::placeholder, #reply-input::placeholder, #search::placeholder { color: var(--muted); }
.sim-wrap { position: relative; }
.sim-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--outline); font-size: 16px; }
.sim-badge { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 24px;
  border-radius: 3px 8px 3px 3px; background: var(--sim); color: #fff; font-size: 13px; font-weight: 500; flex: 0 0 auto; }
.sim-menu { left: 0; top: 46px; }
.sim-menu.up { top: auto; bottom: 40px; }
.sim-option { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 10px 16px; }
.sim-option:hover { background: var(--card); }
.sim-option .num { font-size: 13px; color: var(--muted); }
.contacts { display: flex; flex-direction: column; gap: 2px; padding: 12px 12px 40px; }
.contacts-empty { padding: 24px; }
.letter { font-size: 15px; font-weight: 500; padding: 18px 16px 10px; }
.contact { display: flex; align-items: center; gap: 16px; padding: 14px 16px; background: var(--card);
  border-radius: 4px; cursor: pointer; text-align: left; width: 100%; }
.contact:hover { background: var(--card-high); }
.contact.first { border-top-left-radius: 20px; border-top-right-radius: 20px; }
.contact.last { border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; }
.contact-name { font-size: 17px; }
.contact-name b { color: var(--primary); }
.contact-num { font-size: 15px; color: var(--muted); }

/* ---------- thread ---------- */
.thread-head { gap: 12px; }
.panel { min-height: calc(100vh - 140px); background: var(--panel); border-radius: 28px 28px 0 0;
  padding: 12px 12px 110px; display: flex; flex-direction: column; }
.messages { display: flex; flex-direction: column; gap: 3px; }
.older { text-align: center; font-size: 13px; padding: 8px; }
.divider { text-align: center; font-size: 13px; color: var(--muted); padding: 12px 0; }
.msg { max-width: min(78%, 520px); padding: 10px 14px; border-radius: 20px; font-size: 16px;
  word-wrap: break-word; white-space: pre-wrap; cursor: pointer; }
.msg.in { align-self: flex-start; background: var(--card-high); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; background: var(--primary-container); color: var(--on-primary-container);
  border-bottom-right-radius: 6px; }
.status { font-size: 12px; color: var(--muted); align-self: flex-end; margin: 2px 8px 0; }
.status.failed { color: #e46962; }
.texting-with { text-align: center; font-size: 13px; padding: 18px 0 4px; }
.replybar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); z-index: 4; }
.reply-pill { flex: 1; display: flex; align-items: center; min-width: 0; padding: 0 18px;
  border-radius: 28px; background: var(--card-high); }
.reply-sim { color: var(--muted); font-size: 17px; padding: 14px 0; white-space: nowrap; }
.reply-sim:disabled { cursor: default; }
#reply-input { flex: 1; min-width: 0; border: none; background: none; outline: none; font-size: 17px; padding: 14px 0; }
.send-btn { width: 56px; height: 56px; border-radius: 50%; flex: 0 0 auto; display: flex;
  align-items: center; justify-content: center; background: var(--primary-container);
  color: var(--on-primary-container); }
.send-btn:disabled { opacity: .45; cursor: default; }

/* ---------- offline + devices ---------- */
.offline { margin: 12px 16px; padding: 18px 20px; border-radius: 24px; background: var(--card); }
.offline .off-title { font-size: 17px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.offline .off-title::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: #e46962; }
.offline .off-body { color: var(--muted); margin-top: 6px; font-size: 15px; line-height: 1.45; }
.panel .offline { margin: 4px 0 12px; }
.devices-intro { padding: 0 20px; font-size: 14px; line-height: 1.5; }
.devices { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; }
.device { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 20px; background: var(--card); }
.device-main { flex: 1; min-width: 0; }
.device-name { font-size: 16px; font-weight: 500; }
.device-sub { font-size: 14px; color: var(--muted); }
.device-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; background: var(--card-high); font-size: 20px; flex: 0 0 auto; }
.text-btn { color: var(--primary); padding: 10px 14px; border-radius: 20px; font-weight: 500; }
.text-btn:hover { background: var(--card); }
.devices-actions { padding: 4px 12px 8px; }
.status.expired { color: #e46962; }

/* ---------- composer extras ---------- */
.pill-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: var(--muted); font-size: 20px; flex: 0 0 auto; }
.pill-icon:hover { background: var(--card); }
.reply-pill { gap: 6px; padding-left: 8px; }
.replybar { position: fixed; }
.emoji-pop { bottom: 84px; right: 80px; width: min(360px, calc(100vw - 32px)); max-height: 300px;
  overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 2px; padding: 10px; }
.emoji-pop button { width: 40px; height: 40px; font-size: 24px; border-radius: 8px; }
.emoji-pop button:hover { background: var(--card); }
.attach-menu { bottom: 84px; left: 12px; display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; width: min(380px, calc(100vw - 24px)); }
.attach-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 104px; padding: 10px 4px;
  border-radius: 16px; font-size: 14px; }
.attach-opt:hover { background: var(--card); }
.attach-ico { width: 56px; height: 56px; border-radius: 20px; background: var(--panel); display: flex;
  align-items: center; justify-content: center; font-size: 24px; }
.attach-note { width: 100%; text-align: center; font-size: 12px; color: var(--muted); padding: 6px 4px 0; }
.status.scheduled { color: var(--primary); cursor: pointer; }
.msg.scheduled { opacity: .75; border: 1px dashed var(--outline); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center;
  justify-content: center; z-index: 30; padding: 16px; }
.modal-card { background: var(--menu); border-radius: 28px; padding: 22px; width: min(440px, 100%);
  max-height: 85vh; display: flex; flex-direction: column; }
.modal-title { font-size: 20px; margin-bottom: 12px; }
#modal-body { overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; }
.modal input { width: 100%; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--outline);
  background: var(--card); outline: none; }
.pick-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; cursor: pointer; width: 100%; text-align: left; }
.pick-row:hover { background: var(--card); }

/* ---------- MMS attachments ---------- */
.replybar { flex-wrap: wrap; }
.pending { width: 100%; display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; }
.pend { position: relative; width: 72px; height: 72px; border-radius: 14px; overflow: hidden; flex: 0 0 auto;
  background: var(--card-high); display: flex; align-items: center; justify-content: center; font-size: 11px;
  text-align: center; padding: 4px; word-break: break-all; }
.pend img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.pend-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 13px; z-index: 1; }
.att-img { max-width: min(240px, 70vw); max-height: 320px; border-radius: 18px; cursor: zoom-in; display: block;
  background: var(--card-high); min-height: 60px; min-width: 60px; object-fit: contain; }
.att-wrap { display: flex; margin: 1px 0; }
.att-wrap.out { justify-content: flex-end; }
.att-file { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 18px; background: var(--card-high);
  max-width: 280px; cursor: pointer; }
.att-wrap.out .att-file { background: var(--primary-container); color: var(--on-primary-container); }
.att-file .fname { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.att-file .fsize { font-size: 12px; opacity: .75; }
.att-loading { font-size: 13px; color: var(--muted); padding: 20px; }
.imgview { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 40; display: flex; align-items: center;
  justify-content: center; cursor: zoom-out; }
.imgview img { max-width: 96vw; max-height: 96vh; object-fit: contain; }
