:root{--bg:#f3f4f6;--panel:#fff;--text:#111827;--muted:#6b7280;--accent:#2563eb;--mine:#dbeafe;--theirs:#fff;--line:#e5e7eb}
@media (prefers-color-scheme:dark){:root{--bg:#0f172a;--panel:#1e293b;--text:#f1f5f9;--muted:#94a3b8;--accent:#3b82f6;--mine:#1e3a8a;--theirs:#334155;--line:#334155}}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{font-family:Tahoma,"Segoe UI",system-ui,sans-serif;background:var(--bg);color:var(--text);font-size:15px}
.hidden{display:none!important}
.grow{flex:1;min-width:0}
.clickable{cursor:pointer}
input,button{font:inherit;color:inherit}
input{border:1px solid var(--line);background:var(--panel);border-radius:10px;padding:10px 12px;outline:none;width:100%}
input:focus{border-color:var(--accent)}
button,.btn{border:0;background:var(--accent);color:#fff;border-radius:10px;padding:10px 16px;cursor:pointer;text-decoration:none;display:inline-block}
button.ghost,.btn.ghost{background:transparent;color:var(--text);padding:8px 10px}
button.red{background:#dc2626}button.green{background:#16a34a}
a{color:var(--accent);text-align:center}
.err{color:#dc2626;min-height:1.2em;font-size:13px}
.hint{color:var(--muted);font-size:13px;margin:0;line-height:1.7}
.note{padding:16px;color:var(--muted);text-align:center}

/* auth */
#auth{height:100%;display:flex;align-items:center;justify-content:center;padding:16px}
.card{background:var(--panel);padding:24px;border-radius:16px;width:100%;max-width:360px;display:flex;flex-direction:column;gap:12px}
.card h1{margin:0 0 4px;text-align:center;font-size:22px}
.vpn{background:#fef3c7;color:#92400e;border-radius:10px;padding:10px 12px;font-size:13px;line-height:1.7;text-align:center}

/* layout */
#main{height:100%;display:flex}
#side{width:340px;max-width:100%;background:var(--panel);border-inline-end:1px solid var(--line);display:flex;flex-direction:column}
#side>input{margin:8px 12px;width:auto}
header{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--line);min-height:56px}
header .grow{font-weight:bold;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tabs{display:flex;border-bottom:1px solid var(--line)}
.tab{flex:1;background:transparent;color:var(--muted);border-radius:0;padding:10px}
.tab.on{color:var(--accent);box-shadow:inset 0 -2px 0 var(--accent)}
#list{flex:1;overflow-y:auto}
.item{display:flex;gap:10px;padding:10px 12px;cursor:pointer;align-items:center;border-bottom:1px solid var(--line)}
.item:hover{background:var(--bg)}
.item.pin{background:color-mix(in srgb,var(--accent) 12%,transparent)}
.item .info{flex:1;min-width:0}
.item .name{font-weight:bold}
.item .sub{color:var(--muted);font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.avatar{width:42px;height:42px;border-radius:50%;background:var(--accent);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:bold;flex:none;overflow:hidden}
.avatar img{width:100%;height:100%;object-fit:cover}
.avatar.big{width:96px;height:96px;font-size:36px}
.badge{background:var(--accent);color:#fff;border-radius:999px;min-width:22px;height:22px;display:inline-flex;align-items:center;justify-content:center;font-size:12px;padding:0 6px}

#chat{flex:1;display:flex;flex-direction:column;min-width:0}
#empty{margin:auto;color:var(--muted)}
.pane{display:flex;flex-direction:column;height:100%}
.back{display:none;font-size:22px}
.msgs{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:6px}
#older{align-self:center}
.msg{max-width:78%;padding:8px 10px;border-radius:14px;background:var(--theirs);align-self:flex-start;word-break:break-word;white-space:pre-wrap}
.msg.mine{background:var(--mine);align-self:flex-end}
.msg img,.msg video{max-width:100%;max-height:320px;border-radius:10px;display:block;cursor:pointer}
.msg audio{max-width:100%;width:240px}
.msg .t{font-size:11px;color:var(--muted);margin-top:4px;text-align:end}
.compose{display:flex;gap:6px;padding:8px 10px calc(8px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--panel);align-items:center}
.compose input{flex:1}
#mic.rec{background:#dc2626;color:#fff}

/* secure theme */
#secure-box{--bg:#150d2b;--panel:#21143f;--text:#f3e8ff;--muted:#a78bfa;--accent:#8b5cf6;--mine:#5b21b6;--theirs:#2e1d54;--line:#3b2a66;background:var(--bg);color:var(--text)}
.lockbar{background:#2e1065;color:#ddd6fe;font-size:12px;text-align:center;padding:6px 10px}

/* modal */
#modal{position:fixed;inset:0;background:#000a;display:flex;align-items:center;justify-content:center;padding:16px;z-index:50}
#modal-box{background:var(--panel);border-radius:16px;padding:18px;width:100%;max-width:380px;max-height:90vh;overflow:auto;display:flex;flex-direction:column;gap:10px}
#modal-box h3{margin:0}
.slots{display:flex;gap:8px}
.slot{position:relative;flex:1;aspect-ratio:1;border-radius:12px;overflow:hidden;background:var(--bg)}
.slot img{width:100%;height:100%;object-fit:cover}
.slot-btns{position:absolute;bottom:0;left:0;right:0;display:flex;justify-content:space-between;background:#0008}
.slot-btns button{color:#fff;padding:4px 8px}
.slot.empty{display:flex;align-items:center;justify-content:center;font-size:28px;border:2px dashed var(--line);cursor:pointer;color:var(--muted)}
.photos{display:flex;gap:8px;overflow-x:auto;scroll-snap-type:x mandatory}
.photos img{width:80%;flex:none;scroll-snap-align:center;border-radius:12px;aspect-ratio:1;object-fit:cover;cursor:pointer}

/* call */
#call{position:fixed;inset:0;background:#0b1220f2;z-index:60;display:flex;align-items:center;justify-content:center;color:#fff}
.call-card{display:flex;flex-direction:column;align-items:center;gap:14px;padding:24px}
#call-name{font-size:20px;font-weight:bold}
#call-status{color:#cbd5e1}
.call-btns{display:flex;gap:10px;margin-top:10px}

@media (max-width:720px){
  #side{width:100%}
  #chat{display:none;width:100%}
  body.in-chat #side{display:none}
  body.in-chat #chat{display:flex}
  .back{display:block}
}
