/* Monroe palette: #975f7f (plum), #ad6d92 (rose), #e2c7d7 (blush), #f9eaf3 (pale) */
:root {
  --bg: #fff; --card: #fff; --text: #1d1519; --muted: #9a8a93; --line: #f0e4ea; --soft: #f8eff4;
  --accent: #975f7f; --out: #efd3e3; --out-text: #1d1519; --in: #fff; --in-text: #1d1519; --tick: #975f7f;
  --danger: #e53935; --ok: #4fae4e; --quote: #975f7f; --quote-bg: rgba(151,95,127,.12);
  --wall: rgba(249,234,243,.9); --wallbase: #f3dfe9;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #211820; --card: #211820; --text: #f7eef3; --muted: #9a8392; --line: #160f15; --soft: #2f232d;
    --accent: #e3a6c9; --out: #6a3f58; --out-text: #fff; --in: #33262f; --in-text: #f7eef3; --tick: #f0bfdc;
    --wall: rgba(28,18,26,.9); --wallbase: #1c121a; --quote: #e3a6c9; --quote-bg: rgba(227,166,201,.14); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; font-size: 16px; }
[hidden] { display: none !important; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--sat) + 8px) 12px 8px; background: var(--card); min-height: 54px; }
.bar h1 { font-size: 22px; margin: 0; flex: 1; font-weight: 700; color: var(--accent); letter-spacing: -.3px; }
.iconbtn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); font-size: 22px; flex: none; }
.iconbtn:active { background: var(--soft); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* auth */
.auth { justify-content: center; align-items: center; padding: 24px;
  background-color: var(--wallbase); background-image: linear-gradient(var(--wall), var(--wall)), url(/swirl.png); background-size: 100% 100%, max(190vw, 150vh) auto; background-position: center; }
.auth .logo { width: 110px; height: 110px; border-radius: 28px; margin-bottom: 14px; box-shadow: 0 6px 20px rgba(151,95,127,.35); }
.auth h1 { margin: 0 0 4px; font-size: 28px; }
.auth p { color: var(--muted); margin: 0 0 22px; text-align: center; }
.auth form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.field { padding: 13px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--soft); outline: none; width: 100%; }
.field:focus { border-color: var(--accent); }
.btn { padding: 13px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; text-align: center; }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn:disabled { opacity: .5; }
.link { color: var(--accent); margin-top: 14px; text-align: center; }
.err { color: var(--danger); font-size: 14px; min-height: 18px; text-align: center; }

/* avatar */
.av { border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; background-size: cover; background-position: center; position: relative; }
.av .dot { position: absolute; right: 0; bottom: 0; width: 26%; height: 26%; border-radius: 50%; background: var(--ok); border: 2.5px solid var(--card); }

/* chat list */
.pill { margin: 2px 14px 8px; background: var(--soft); border-radius: 22px; padding: 11px 16px 11px 42px; border: 0; outline: none; width: calc(100% - 28px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238a8f96' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center; }
.tabs { display: flex; gap: 6px; padding: 0 14px 6px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 6px 14px; border-radius: 16px; color: var(--muted); font-weight: 600; font-size: 15px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.tab.on { background: var(--soft); color: var(--accent); }
.tab .n { background: var(--muted); color: #fff; border-radius: 9px; font-size: 12px; padding: 0 6px; min-width: 18px; text-align: center; }
.tab.on .n { background: var(--accent); }
.row { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--card); width: 100%; text-align: left; }
.row:active { background: var(--soft); }
.row .mid { flex: 1; min-width: 0; padding: 4px 0; }
.row .top { display: flex; gap: 6px; align-items: center; }
.row .name { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .mute { color: var(--muted); display: inline-flex; }
.row .mute svg { width: 15px; height: 15px; }
.row .top .sp { flex: 1; }
.row .time { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 3px; }
.row .time .tk { color: var(--tick); font-size: 14px; }
.row .sub { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 16px; margin-top: 1px; }
.row .sub .txt { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub .txt.typing { color: var(--accent); }
.badge { background: var(--accent); color: #fff; border-radius: 12px; font-size: 14px; min-width: 24px; height: 24px; line-height: 24px; padding: 0 7px; text-align: center; font-weight: 600; }
.badge.muted { background: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 30px; }
.banner { margin: 6px 14px 10px; padding: 12px 14px; border-radius: 14px; background: var(--soft); font-size: 14px; }
.banner b { display: block; margin-bottom: 2px; }
.fab { position: absolute; right: 18px; bottom: calc(var(--sab) + 18px); width: 56px; height: 56px; border-radius: 50%; background: var(--accent);
  color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.28); display: grid; place-items: center; }

/* chat screen */
.chat { background: var(--bg); }
.chatbar { padding-left: 4px; padding-right: 10px; gap: 4px; border-bottom: 1px solid var(--line); }
.chatbar .back { display: flex; align-items: center; color: var(--accent); font-size: 17px; min-width: 76px; padding: 6px 0; }
.chatbar .back svg { width: 28px; height: 28px; stroke-width: 2.4; margin-right: -2px; }
.chatbar .who { flex: 1; min-width: 0; text-align: center; }
.chatbar .who .n { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatbar .who .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatbar .right { min-width: 76px; display: flex; justify-content: flex-end; align-items: center; gap: 2px; }
.chatbar .right .iconbtn { color: var(--accent); width: 36px; }
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 10px; display: flex; flex-direction: column;
  background-color: var(--wallbase);
  background-image: linear-gradient(var(--wall), var(--wall)), url(/swirl.png);
  background-size: 100% 100%, max(190vw, 150vh) auto; background-position: center; background-attachment: local, scroll; }
.day, .sys { align-self: center; font-size: 13px; font-weight: 500; color: #fff; background: rgba(120,80,105,.5); border-radius: 12px; padding: 2px 10px; margin: 10px 0 6px; backdrop-filter: blur(6px); }
.sys { margin: 6px 0; text-align: center; }
.m { max-width: 82%; margin: 1px 0; display: flex; flex-direction: column; }
.m.me { align-self: flex-end; align-items: flex-end; }
.m.them { align-self: flex-start; align-items: flex-start; }
.m.gap { margin-top: 7px; }
.m .sender { font-size: 14px; font-weight: 600; margin: 0 10px 1px; }
.bub { padding: 6px 10px 6px; border-radius: 17px; background: var(--in); color: var(--in-text); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; position: relative; min-width: 0; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.m.them .bub { border-bottom-left-radius: 5px; }
.m.me .bub { background: var(--out); color: var(--out-text); border-bottom-right-radius: 5px; }
.bub.media { padding: 3px; }
.bub img, .bub video { display: block; max-width: 100%; max-height: 340px; border-radius: 14px; }
.bub .cap { padding: 5px 8px 3px; }
.bub .meta { font-size: 12px; color: var(--muted); text-align: right; margin-top: 1px; display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; float: right; margin-left: 10px; position: relative; top: 3px; }
.m.me .bub .meta { color: var(--tick); }
.bub.media .meta { padding: 0 8px 3px; float: none; margin: 0; top: 0; }
.bub .tick { font-size: 12px; }
.bub .tick.read { color: var(--tick); }
.bub.del { font-style: italic; background: transparent; box-shadow: none; border: 1px dashed rgba(255,255,255,.7); color: #fff; }
.m.me .bub.del { color: #fff; background: transparent; }
.quote { border-left: 3px solid var(--quote); background: var(--quote-bg); padding: 3px 8px; border-radius: 6px; margin-bottom: 4px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.quote b { display: block; font-size: 13px; color: var(--quote); }
.reacts { display: flex; gap: 3px; margin: -5px 6px 0; z-index: 1; flex-wrap: wrap; }
.react { background: var(--card); border-radius: 12px; padding: 0 7px; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.react.mine { background: var(--accent); color: #fff; }
.file { display: flex; gap: 10px; align-items: center; min-width: 190px; padding: 4px; }
.file .ic { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; }
.file small { color: var(--muted); display: block; }
.audio { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 2px 2px; }
.audio .play { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; }
.audio .track { flex: 1; height: 4px; border-radius: 2px; background: rgba(127,127,127,.35); position: relative; }
.audio .track i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 2px; width: 0; }
.audio .dur { font-size: 12px; color: var(--muted); min-width: 32px; }
.callmsg { align-self: center; background: var(--card); border-radius: 14px; padding: 7px 14px; margin: 6px 0; display: flex; gap: 8px; align-items: center; font-size: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.callmsg.missed { color: var(--danger); }
.typing-ind { display: none; }

.composer { background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(var(--sab) + 6px); }
.composer .replybar { display: flex; align-items: center; gap: 8px; padding: 4px 8px 8px; font-size: 14px; }
.composer .replybar .quote { flex: 1; margin: 0; }
.composer .line { display: flex; align-items: flex-end; gap: 4px; }
.composer .line .iconbtn { color: var(--muted); }
.composer .inp { flex: 1; display: flex; align-items: flex-end; background: var(--soft); border-radius: 21px; border: 1px solid var(--line); min-width: 0; }
.composer textarea { flex: 1; resize: none; border: 0; background: transparent; padding: 9px 4px 9px 14px; max-height: 120px; outline: none; line-height: 1.3; min-width: 0; }
.composer .inp .iconbtn { width: 38px; height: 38px; }
.composer .sendbtn { background: var(--accent); color: #fff; border-radius: 50%; width: 40px; height: 40px; display: grid; place-items: center; flex: none; }
.composer .sendbtn svg { stroke-width: 2.4; }
.recbar { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.recbar .rdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.recbar .t { flex: 1; font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .2; } }
.emojipanel { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 200px; overflow-y: auto; padding: 6px 4px 2px; }
.emojipanel button { font-size: 26px; padding: 4px 0; }

/* sheets & modals */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; border-radius: 16px 16px 0 0; padding: 10px 0 calc(var(--sab) + 10px); max-height: 85%; overflow-y: auto; }
.sheet .item { display: flex; gap: 12px; padding: 14px 20px; width: 100%; text-align: left; align-items: center; font-size: 17px; }
.sheet .item:active { background: var(--soft); }
.sheet .item.danger { color: var(--danger); }
.sheet .reactrow { display: flex; justify-content: space-around; padding: 6px 10px 12px; border-bottom: 1px solid var(--line); }
.sheet .reactrow button { font-size: 28px; padding: 4px 6px; border-radius: 20px; }
.sheet .reactrow button.on { background: var(--soft); }
.sheet h3 { margin: 4px 20px 10px; }
.page { position: absolute; inset: 0; background: var(--bg); z-index: 40; display: flex; flex-direction: column; }
.check { margin-left: auto; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; color: #fff; }
.check.on { background: var(--accent); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 14px; }
.chip { background: var(--accent); color: #fff; border-radius: 14px; padding: 3px 10px; font-size: 14px; }
.profile { display: flex; flex-direction: column; align-items: center; padding: 20px; gap: 10px; }
.form { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.lbl { font-size: 13px; color: var(--muted); margin: 8px 18px 4px; text-transform: uppercase; letter-spacing: .4px; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 90; display: flex; align-items: center; justify-content: center; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; }
.viewer .x { position: absolute; top: calc(var(--sat) + 10px); right: 14px; color: #fff; font-size: 30px; width: 44px; height: 44px; background: rgba(0,0,0,.5); border-radius: 50%; }
#toast { position: fixed; left: 50%; top: calc(var(--sat) + 12px); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 200; font-size: 14px; max-width: 90%; }

/* calls */
.call { position: fixed; inset: 0; z-index: 100; background: #14161a; color: #fff; display: flex; flex-direction: column; align-items: center; }
.call .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call .local { position: absolute; top: calc(var(--sat) + 14px); right: 14px; width: 110px; height: 150px; object-fit: cover; border-radius: 14px; background: #222; z-index: 2; border: 1px solid rgba(255,255,255,.3); transform: scaleX(-1); }
.call .local.back { transform: none; }
.call .info { position: relative; z-index: 2; margin-top: calc(var(--sat) + 70px); text-align: center; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.call .info h2 { margin: 12px 0 4px; font-size: 26px; }
.call .info div { opacity: .85; }
.call .ctrls { position: relative; z-index: 2; margin-top: auto; padding: 20px 20px calc(var(--sab) + 30px); display: flex; gap: 22px; justify-content: center; }
.cbtn { width: 62px; height: 62px; border-radius: 50%; background: rgba(255,255,255,.2); font-size: 26px; display: grid; place-items: center; backdrop-filter: blur(8px); }
.cbtn.off { background: #fff; color: #000; }
.cbtn.end { background: var(--danger); }
.cbtn.acc { background: var(--ok); }
.call.voice { background: linear-gradient(160deg, #975f7f, #2a1822); }

@media (prefers-color-scheme: dark) {
  .react.mine, .badge, .tab.on .n, .chip, .btn, .fab, .sendbtn, .file .ic, .audio .play, .cbtn.acc { color: #211820; }
}
.bar h1 { display: flex; align-items: center; gap: 8px; }
.bar h1 img { width: 30px; height: 30px; object-fit: contain; }

/* ===== Monroe theme v2: swirl nav, plum + grey bubbles, squircle avatars ===== */
:root { --in: #ececf0; --in-text: #1d1519; --out-text: #fff; --out-grad: linear-gradient(135deg, #b0719a, #8a5277); }
@media (prefers-color-scheme: dark) { :root { --in: #3a3a42; --in-text: #f4f0f3; --out-text: #fff; } }

.bar { background: linear-gradient(rgba(74,36,60,.12), rgba(74,36,60,.12)), #975f7f url(/banner.png) center / cover; color: #fff; border-bottom: 0;
  box-shadow: 0 2px 12px rgba(80,40,65,.28); position: relative; z-index: 3; }
.bar h1 { color: #fff; font-size: 27px; font-weight: 800; letter-spacing: .2px; text-shadow: 0 1px 8px rgba(60,20,45,.6); }
.bar .iconbtn, .chatbar .iconbtn { color: #fff; }
.bar .iconbtn:active { background: rgba(255,255,255,.22); }
.bar svg.i { filter: drop-shadow(0 1px 3px rgba(60,20,45,.5)); }
.chatbar { padding-left: 2px; gap: 6px; border-bottom: 0; }
.chatbar .back { min-width: 0; width: 36px; justify-content: center; color: #fff; padding: 6px 0; }
.chatbar .back svg { margin: 0; }
.chatbar .who { text-align: left; color: #fff; text-shadow: 0 1px 6px rgba(60,20,45,.6); }
.chatbar .who .n { font-size: 17px; }
.chatbar .who .s { color: rgba(255,255,255,.88); }

.av { border-radius: 32%; }
.av .dot { right: auto; left: -3px; bottom: -3px; width: 30%; height: 30%; background: var(--accent); border: 2.5px solid var(--card); }

.tabs { padding: 4px 14px 8px; gap: 8px; }
.tab { padding: 7px 16px; border-radius: 18px; color: var(--text); font-weight: 500; background: transparent; }
.tab.on { background: var(--accent); color: #fff; }
.tab .n { background: var(--accent); color: #fff; }
.tab.on .n { background: rgba(255,255,255,.3); }
@media (prefers-color-scheme: dark) { .tab.on { color: #211820; } .tab.on .n { background: rgba(33,24,32,.25); color: #211820; } }
.badge { background: var(--accent); }
.row .time { font-size: 13px; }
.row .sub { font-size: 15px; }

.msgs { background: var(--bg); background-image: none; padding: 10px 12px; }
.day, .sys { background: var(--soft); color: var(--muted); backdrop-filter: none; font-weight: 500; }
.bub { border-radius: 20px; padding: 8px 13px; box-shadow: none; }
.bub.media { padding: 3px; }
.m.them .bub { background: var(--in); color: var(--in-text); border-bottom-left-radius: 6px; }
.m.me .bub { background: var(--out-grad); color: var(--out-text); border-bottom-right-radius: 6px; }
.m.me .bub .meta { color: rgba(255,255,255,.78); }
.m.me .bub .tick.read { color: #fff; }
.m.me .quote { background: rgba(255,255,255,.2); border-color: #fff; }
.m.me .quote b { color: #fff; }
.m .sender { font-size: 13px; }
.bub.del, .m.me .bub.del { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.react { background: var(--soft); box-shadow: none; border: 1px solid var(--line); }
.react.mine { background: var(--accent); color: #fff; border-color: var(--accent); }
.m.me .audio .play, .m.me .file .ic { background: #fff; color: #975f7f; }
.m.me .audio .track i { background: #fff; }
.m.me .audio .dur, .m.me .file small { color: rgba(255,255,255,.82); }
.callmsg { background: var(--soft); box-shadow: none; }

.composer { border-top: 0; box-shadow: 0 -2px 12px rgba(0,0,0,.06); padding: 8px 10px calc(var(--sab) + 8px); }
.composer .line .iconbtn { color: var(--accent); }
.composer .inp { background: var(--soft); border: 0; border-radius: 24px; }
.composer .sendbtn { background: var(--out-grad); }

.setrow { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: 16px; gap: 10px; }
.setrow small { color: var(--muted); font-size: 13px; }
.setrow.link:active { background: var(--soft); }
.form .field { margin-bottom: 0; }
.cicon { display: inline-flex; }
.cicon svg { width: 16px; height: 16px; }
.cicon.bad { color: var(--danger); }
.call.voice { background: linear-gradient(rgba(60,25,48,.5), rgba(24,10,19,.88)), #975f7f url(/swirl.png) center / cover; }
.call .info .av { margin: 0 auto; }
.btn { background: var(--out-grad); }
.fab { display: none; }

.auth form { max-width: 340px; }
.or { color: var(--muted); font-size: 13px; margin: 14px 0 10px; display: flex; align-items: center; gap: 10px; width: 100%; max-width: 300px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.social { display: flex; flex-direction: column; gap: 10px; align-items: center; width: 100%; }
.applebtn { width: 300px; max-width: 100%; height: 44px; border-radius: 22px; background: #000; color: #fff; font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.aplogo { font-size: 20px; line-height: 1; }

.bar h1 { font-size: 24px; white-space: nowrap; }
