:root {
  --bg: #0e1412; --panel: #141c19; --panel2: #1a2420; --line: #24302b; --text: #e6efeb; --muted: #8a9a93;
  --accent: #2fbf8f; --accent-ink: #062018; --out: #1d4a3b; --in: #1b2522; --danger: #e5484d; --warn: #f0b429;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; }
body.veil #app, body.veil #modal-root { filter: blur(24px); }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .center { text-align: center; } .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; min-width: 0; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ok-ic { width: 15px; height: 15px; color: var(--accent); vertical-align: -2px; }
.warn-ic { width: 15px; height: 15px; color: var(--warn); }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }
#app { height: 100%; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 11px 16px; font-weight: 600; }
.btn:hover { border-color: #33433c; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: #4a2224; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text); flex: none; }
.icon-btn:hover { background: var(--panel2); }
.icon-btn.send { background: var(--accent); color: var(--accent-ink); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; } .row.end { justify-content: flex-end; } .row > input { flex: 1; }
.stack { display: grid; gap: 4px; }
.spacer { flex: 1; }

/* auth screens */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; height: 100%; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; }
.auth-card h1 { margin: 10px 0 6px; font-size: 22px; }
.logo { width: 54px; height: 54px; display: block; }
.logo-a { fill: var(--accent); } .logo-b { fill: none; stroke: var(--bg); stroke-width: 4; stroke-linejoin: round; }
.field { display: block; margin-top: 12px; } .field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.hint { margin-top: 14px; font-size: 12.5px; color: var(--muted); background: var(--panel2); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 6px; }
.err { color: var(--danger); min-height: 18px; margin-top: 10px; font-size: 13.5px; }
.pin-input { font-size: 22px; letter-spacing: 6px; text-align: center; margin-top: 14px; }

/* main layout */
.main { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.side { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; padding-top: var(--safe-t); }
.side-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 10px 12px; border-bottom: 1px solid var(--line); }
.me { flex: 1; min-width: 0; margin-left: 8px; display: grid; } .me b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 3px; }
.dot.off { background: var(--danger); }
.side-foot { padding: 10px 14px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 6px; align-items: center; }
.side-foot .ic { width: 15px; height: 15px; }
.list { overflow-y: auto; flex: 1; min-height: 0; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: transparent; border-bottom: 1px solid #18211e; }
button.item:hover, label.item:hover { background: var(--panel2); }
.item.active { background: var(--panel2); }
.item-main { flex: 1; min-width: 0; }
.item-top, .item-bot { display: flex; align-items: center; gap: 6px; }
.item-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-bot .ell { flex: 1; }
.badge { background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.av-wrap { position: relative; flex: none; }
.online { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
.avatar { --h: 160; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none;
  background: hsl(var(--h) 35% 26%); color: hsl(var(--h) 60% 82%); }
.avatar.sm { width: 36px; height: 36px; font-size: 13px; } .avatar.lg { width: 72px; height: 72px; font-size: 24px; } .avatar.xl { width: 110px; height: 110px; font-size: 38px; }

/* chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-empty { margin: auto; text-align: center; max-width: 380px; padding: 20px; }
.chat-empty .logo { margin: 0 auto 12px; width: 70px; height: 70px; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: calc(8px + var(--safe-t)) 8px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-title { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; text-align: left; min-width: 0; padding: 4px; border-radius: 10px; }
.chat-title > div { min-width: 0; }
.back { display: none; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; font-size: 13.5px; }
.banner.warn { background: #3a2e10; color: #ffd98a; }
.banner .ic { color: var(--warn); }
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.e2e-note { align-self: center; max-width: 420px; text-align: center; font-size: 12.5px; color: #c9b77a; background: #221f14; border-radius: 10px; padding: 7px 12px; margin-bottom: 10px; display: flex; gap: 6px; align-items: center; }
.e2e-note .ic { width: 14px; height: 14px; }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--panel); padding: 4px 10px; border-radius: 8px; margin: 6px 0; }
.brow { display: flex; } .brow.out { justify-content: flex-end; }
.bubble { max-width: min(78%, 560px); padding: 7px 10px 5px; border-radius: 14px; background: var(--in); position: relative; user-select: text; -webkit-user-select: text; }
.bubble.out { background: var(--out); border-bottom-right-radius: 4px; } .bubble.in { border-bottom-left-radius: 4px; }
.bubble.media { padding: 4px; }
.who { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.txt { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 11px; color: #9fb3aa; margin-top: 2px; padding: 0 2px; }
.meta .left { display: inline-flex; align-items: center; gap: 2px; opacity: .8; }
.meta .ic { width: 12px; height: 12px; }
.st .ic { width: 15px; height: 15px; } .st-read { color: #5cc8ff; }
.img-box { width: min(300px, 62vw); min-height: 80px; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: #0b100e; }
.img-box img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 60; }
.viewer img { max-width: 100%; max-height: 100%; }
.voice { display: flex; align-items: center; gap: 8px; min-width: 220px; } .voice audio { width: 250px; max-width: 62vw; height: 40px; }
.file { display: flex; align-items: center; gap: 10px; border: 0; background: rgba(0,0,0,.2); border-radius: 10px; padding: 8px 10px; text-align: left; max-width: 280px; }
.file > div { min-width: 0; flex: 1; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.composer.center { justify-content: center; padding: 16px; }
.rec { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 8px; height: 40px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.modal.wide { max-width: 560px; }
.modal-head { display: flex; align-items: center; padding: 12px 12px 8px 18px; } .modal-head h2 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.modal .list { max-height: 50vh; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; }
.search { margin-bottom: 4px; }
.label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 0 6px; }
.profile { text-align: center; padding: 6px 0 4px; } .profile .avatar { margin: 0 auto 8px; } .profile h3 { margin: 0; }
.sn { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 10px; background: var(--panel2); padding: 12px; border-radius: 12px; text-align: center; font-size: 16px; letter-spacing: 1px; }
.sn.sn3 { grid-template-columns: repeat(3, 1fr); }
.safety p { margin-top: 8px; }
.settings section { border-top: 1px solid var(--line); padding: 6px 0 14px; } .settings section:first-child { border-top: 0; }
.settings h3 { margin: 10px 0 4px; font-size: 15px; }
.toggle { display: flex; gap: 10px; align-items: center; margin-top: 12px; font-size: 14px; }
.link-code { font-size: 22px; letter-spacing: 2px; background: var(--panel2); padding: 14px; border-radius: 12px; margin: 12px 0; word-break: break-all; }
.invite-url { font-size: 12px; background: var(--panel2); padding: 10px; border-radius: 10px; margin: 12px 0; word-break: break-all; user-select: all; }
.qr { border-radius: 10px; margin: 6px auto; display: block; max-width: 100%; }
.user-row { flex-wrap: wrap; } .user-row .row { margin-top: 0; width: 100%; justify-content: flex-end; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; background: #26332e; color: var(--text); padding: 10px 16px; border-radius: 12px; z-index: 80; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* call */
.call { position: fixed; inset: 0; z-index: 50; background: radial-gradient(circle at 50% 30%, #1c2e27, #070b09); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: calc(40px + var(--safe-t)) 16px calc(30px + var(--safe-b)); }
#call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; pointer-events: none; }
.call.has-video #call-remote { opacity: 1; }
#call-local { position: absolute; right: 14px; top: calc(14px + var(--safe-t)); width: 110px; height: 160px; object-fit: cover; border-radius: 12px; border: 2px solid rgba(255,255,255,.3); z-index: 2; transform: scaleX(-1); background: #000; }
.call-info { position: relative; z-index: 1; text-align: center; }
.call-info .avatar { margin: 0 auto 14px; }
.call.has-video .call-info .avatar { display: none; }
.call.has-video .call-info { background: rgba(0,0,0,.35); padding: 6px 14px; border-radius: 12px; align-self: flex-start; max-width: calc(100% - 140px); text-align: left; }
.call.has-video .call-info h2 { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-info h2 { margin: 0; font-size: 24px; }
.call-status { color: var(--muted); margin-top: 4px; min-height: 20px; }
.call-e2e { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; color: #9fb3aa; margin-top: 8px; } .call-e2e .ic { width: 13px; height: 13px; }
.call-ctrls { position: relative; z-index: 1; display: flex; gap: 18px; }
.call-btn { width: 62px; height: 62px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; backdrop-filter: blur(6px); }
.call-btn .ic { width: 26px; height: 26px; }
.call-btn.red { background: var(--danger); } .call-btn.green { background: #22a86b; } .call-btn.off { background: #fff; color: #111; }

/* mobile: single pane */
@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .main .chat { display: none; }
  .main.has-active .side { display: none; }
  .main.has-active .chat { display: flex; }
  .back { display: inline-grid; }
  .modal-wrap { padding: 0; align-items: end; }
  .modal, .modal.wide { max-width: none; border-radius: 18px 18px 0 0; max-height: 92dvh; }
  .modal-body { padding-bottom: calc(18px + var(--safe-b)); }
  .bubble { max-width: 86%; }
}
