:root {
  --blue: #3390ec;
  --blue-dark: #2b7fd4;
  --bg: #fff;
  --chat-bg: #8ba4b8;
  --chat-bg-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/svg%3E");
  --in: #fff;
  --out: #eeffde;
  --muted: #707579;
  --border: #dadce0;
  --danger: #e53935;
  --media-max-w: 280px;
  --media-max-h: 320px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); overflow: hidden; }
#app { height: 100%; }
.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }
.topbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: calc(8px + var(--safe-top)) 12px 8px;
  background: var(--blue); color: #fff;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-brand { gap: 8px; }
.topbar-logo { flex-shrink: 0; object-fit: contain; background: transparent !important; }
.icon-btn { border: 0; background: transparent; color: inherit; width: 40px; height: 40px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.login-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 14px; }
.logo { width: 128px; height: 128px; margin: 0 auto 8px; object-fit: contain; display: block; background: transparent !important; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.pw-clear { position:absolute; right:44px; bottom:13px; border:0; background:transparent; font-size:18px; cursor:pointer; padding:2px 6px; line-height:1; color:var(--muted); }
.field label { font-size: 13px; color: var(--muted); display:block; margin-bottom:6px; }
.field input { width:100%; border:1px solid var(--border); border-radius:12px; padding:14px 16px; font-size:16px; }
.pw-field { position:relative; }
.pw-field input { padding-right:48px !important; }
.pw-toggle { position:absolute; right:10px; bottom:13px; border:0; background:transparent; font-size:20px; cursor:pointer; padding:2px 6px; line-height:1; }
.login-hint { text-align:center; font-size:13px; color:var(--muted); margin:0; }
.btn { border:0; border-radius:12px; padding:14px; font-size:16px; font-weight:600; cursor:pointer; }
.btn-primary { background:var(--blue); color:#fff; width:100%; }
.error { color:var(--danger); text-align:center; min-height:20px; font-size:14px; }
.chat-list { flex:1; overflow-y:auto; -webkit-overflow-scrolling:touch; background:#fff; }
.chat-item { display:flex; gap:12px; padding:10px 14px; border-bottom:1px solid #ebebeb; cursor:pointer; align-items:center; }
.chat-item:active { background:#f4f4f5; }
.avatar { width:54px; height:54px; border-radius:50%; background:linear-gradient(135deg,#5b9bd5,var(--blue)); color:#fff; display:flex; align-items:center; justify-content:center; font-size:20px; font-weight:600; flex-shrink:0; }
.chat-meta { flex:1; min-width:0; }
.chat-title { font-weight:600; font-size:16px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-preview { color:var(--muted); font-size:14px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:2px; }
.chat-time { color:var(--muted); font-size:12px; flex-shrink:0; }
.chat-side { display:flex; flex-direction:column; align-items:flex-end; gap:6px; flex-shrink:0; }
.badge { min-width:22px; height:22px; padding:0 6px; border-radius:11px; background:var(--blue); color:#fff; font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; }
.chat-header { gap:8px; }
.chat-header-main { display:flex; align-items:center; gap:12px; flex:1; min-width:0; }
.chat-header-avatar { width:42px; height:42px; border-radius:50%; background:rgba(255,255,255,.22); color:#fff; display:flex; align-items:center; justify-content:center; font-size:18px; font-weight:700; flex-shrink:0; }
.chat-header-text { min-width:0; }
.chat-header-name { font-size:17px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-header-status { font-size:13px; opacity:.85; margin-top:1px; }
.messages { flex:1; overflow-y:auto; padding:10px 10px 16px; background-color:var(--chat-bg); background-image:var(--chat-bg-pattern); -webkit-overflow-scrolling:touch; }
.bubble-row { display:flex; margin-bottom:6px; padding:0 4px; }
.bubble-row.out { justify-content:flex-end; }
.bubble { max-width:min(420px, 78vw); padding:7px 11px 6px; border-radius:12px; box-shadow:0 1px 1px rgba(0,0,0,.08); word-wrap:break-word; position:relative; }
.bubble.has-media { padding:3px; max-width:calc(var(--media-max-w) + 6px); }
.bubble.in { background:var(--in); border-top-left-radius:4px; }
.bubble.out { background:var(--out); border-top-right-radius:4px; }
.bubble .sender { font-size:13px; font-weight:600; color:var(--blue); margin:4px 8px 2px; }
.bubble .text { font-size:16px; line-height:1.35; white-space:pre-wrap; padding:0 2px; }
.bubble .time { font-size:11px; color:var(--muted); text-align:right; margin-top:3px; padding:0 2px; }
.bubble .time.media-time { position:absolute; right:8px; bottom:6px; margin:0; padding:2px 6px; border-radius:10px; background:rgba(0,0,0,.45); color:#fff; font-size:11px; line-height:1.2; pointer-events:none; }
.bubble-media { display:block; overflow:hidden; border-radius:10px; line-height:0; max-width:var(--media-max-w); }
.bubble.in .bubble-media { border-top-left-radius:4px; }
.bubble.out .bubble-media { border-top-right-radius:4px; }
.bubble-media img, .bubble-media video { display:block; width:auto; height:auto; max-width:var(--media-max-w); max-height:var(--media-max-h); object-fit:cover; cursor:pointer; }
.bubble-media .msg-photo.loading-img { filter: blur(10px); transform: scale(1.03); transition: filter 0.2s ease, transform 0.2s ease; }
.bubble-media .msg-photo:not(.loading-img) { filter: none; transform: none; }
.bubble-media video { cursor:default; background:#000; }
.bubble .file-link { color:var(--blue); font-size:15px; word-break:break-all; display:inline-block; padding:4px 6px; }
.composer { flex:0 0 auto; display:flex; align-items:flex-end; gap:6px; padding:6px 8px calc(6px + var(--safe-bottom)); background:#fff; border-top:1px solid #e0e0e0; }
.composer textarea { flex:1; resize:none; border:0; border-radius:22px; padding:10px 14px; font-size:16px; font-family:inherit; max-height:120px; min-height:42px; background:#f0f2f5; }
.lightbox { position:fixed; inset:0; z-index:20; background:rgba(0,0,0,.92); display:flex; align-items:center; justify-content:center; padding:16px; }
.lightbox.hidden { display:none !important; }
.lightbox img { max-width:100%; max-height:100%; object-fit:contain; }
.lightbox-close { position:absolute; top:calc(12px + var(--safe-top)); right:12px; border:0; background:rgba(255,255,255,.15); color:#fff; width:40px; height:40px; border-radius:50%; font-size:20px; cursor:pointer; }
.composer .send, .composer .attach { width:40px; height:40px; border:0; border-radius:50%; background:var(--blue); color:#fff; font-size:18px; cursor:pointer; flex-shrink:0; }
.composer .attach { background:transparent; color:var(--muted); font-size:22px; }
.empty, .loading { padding:24px; text-align:center; color:var(--muted); }
.modal { position:fixed; inset:0; background:rgba(0,0,0,.45); display:none; align-items:center; justify-content:center; z-index:10; padding:16px; }
.modal.open { display:flex; }
.modal-box { background:#fff; border-radius:16px; width:100%; max-width:420px; max-height:80vh; overflow:hidden; display:flex; flex-direction:column; }
.modal-head { padding:16px; font-weight:700; border-bottom:1px solid #eee; }
.modal-body { overflow-y:auto; padding:8px; }
.user-pick { padding:12px 16px; border-bottom:1px solid #f0f0f0; cursor:pointer; }
.user-pick:active { background:#f5f5f5; }
.menu-btn { width:100%; text-align:left; border:0; background:#f5f7fa; border-radius:12px; padding:14px 16px; font-size:16px; margin-bottom:8px; cursor:pointer; }
.menu-btn:active { background:#e8ecf1; }
.user-check { display:block; padding:8px 4px; font-size:15px; cursor:pointer; }
.user-check input { margin-right:8px; }
.checks { max-height:200px; overflow-y:auto; border:1px solid var(--border); border-radius:12px; padding:8px 12px; }
.settings-body { flex:1; overflow-y:auto; padding:16px; }
.settings-profile { display:flex; gap:14px; align-items:center; padding:12px 0 20px; }
.settings-avatar { border-radius:18px; object-fit:contain; background:transparent; }
.settings-section { font-size:13px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; margin:16px 0 8px; }
.settings-row { display:flex; justify-content:space-between; align-items:center; padding:14px 0; border-bottom:1px solid #f0f0f0; font-size:16px; }
.settings-row input { width:22px; height:22px; }
.settings-foot { text-align:center; margin-top:24px; font-size:13px; }
.muted { color:var(--muted); }
.btn-danger { background:var(--danger); color:#fff; width:100%; margin-top:8px; }
.hidden { display:none !important; }
