*{box-sizing:border-box;margin:0;padding:0;-webkit-tap-highlight-color:transparent}

/* ── THEMES ── */
:root{
  --bg:#0f0f0f;--surface:#181818;--surface2:#222;
  --border:#2c2c2c;--accent:#4f8cff;--accent-dim:#1a2e55;
  --text:#f0f0f0;--subtext:#7a7a7a;--subtext2:#444;
  --bubble-me:#1a3460;--bubble-other:#1e1e1e;
  --reply-bg:#ffffff0f;--danger:#ff4f4f;
  --radius:18px;--safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-top:env(safe-area-inset-top,0px);
}
[data-theme="light"]{
  --bg:#f0f2f5;--surface:#fff;--surface2:#f5f5f5;
  --border:#e0e0e0;--accent:#2563eb;--accent-dim:#dbeafe;
  --text:#111;--subtext:#888;--subtext2:#bbb;
  --bubble-me:#2563eb;--bubble-other:#fff;
  --reply-bg:#0000000a;--danger:#dc2626;
}
[data-theme="light"] .msg-row.me .bubble{color:#fff}
[data-theme="light"] .bubble{border-color:#e5e7eb}

html,body{height:100%;background:var(--bg);color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:15px;overflow:hidden}

/* ── SETUP ── */
#setup-modal{position:fixed;inset:0;background:rgba(0,0,0,.9);display:flex;
  align-items:center;justify-content:center;z-index:200;padding:24px}
.modal-box{background:var(--surface);border:1px solid var(--border);border-radius:22px;
  padding:30px 24px;width:100%;max-width:360px;text-align:center}
.modal-box h2{font-size:22px;margin-bottom:8px}
.modal-box p{color:var(--subtext);font-size:14px;margin-bottom:20px;line-height:1.5}
.device-options{display:flex;gap:10px;margin-bottom:20px}
.device-btn{flex:1;padding:16px 10px;background:var(--bg);border:2px solid var(--border);
  border-radius:16px;color:var(--text);font-size:14px;cursor:pointer;transition:.2s}
.device-btn:hover,.device-btn.selected{border-color:var(--accent);background:var(--accent-dim)}
.device-btn .icon{font-size:30px;margin-bottom:6px}
.pin-section{margin-bottom:16px}
.pin-section label{font-size:13px;color:var(--subtext);display:block;margin-bottom:6px}
.pin-input{width:100%;background:var(--bg);border:1px solid var(--border);border-radius:10px;
  padding:10px 14px;color:var(--text);font-size:16px;text-align:center;
  letter-spacing:6px;outline:none;font-family:monospace}
.pin-input:focus{border-color:var(--accent)}
.setup-btn{width:100%;padding:14px;background:var(--accent);border:none;border-radius:14px;
  color:#fff;font-size:16px;font-weight:600;cursor:pointer;transition:.2s}
.setup-btn:hover{opacity:.9}
.setup-btn:disabled{opacity:.4;cursor:default}

/* ── PIN LOCK ── */
#pin-lock{position:fixed;inset:0;background:var(--bg);display:none;flex-direction:column;
  align-items:center;justify-content:center;z-index:190;gap:16px;padding:24px}
#pin-lock h2{font-size:22px}
#pin-lock p{color:var(--subtext);font-size:14px}
.pin-dots{display:flex;gap:12px;margin:8px 0}
.pin-dot{width:14px;height:14px;border-radius:50%;border:2px solid var(--border);
  transition:.2s;background:transparent}
.pin-dot.filled{background:var(--accent);border-color:var(--accent)}
.numpad{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;max-width:280px;width:100%}
.num-btn{padding:18px;background:var(--surface);border:1px solid var(--border);
  border-radius:14px;color:var(--text);font-size:20px;cursor:pointer;transition:.15s;
  font-weight:500}
.num-btn:active{transform:scale(.93);background:var(--accent-dim)}
.pin-error{color:var(--danger);font-size:13px;min-height:18px}

/* ── LAYOUT ── */
#app{display:flex;flex-direction:column;height:var(--app-height, 100dvh)}
.app-shell{display:grid;grid-template-columns:330px 1fr;height:var(--app-height, 100dvh);background:var(--bg)}
.screen{min-height:var(--app-height, 100dvh)}
.auth-screen{display:flex;align-items:center;justify-content:center;background:var(--bg);padding:24px}
html.has-token #auth-screen{display:none}
.auth-input{letter-spacing:0;text-align:left;margin-bottom:10px;font-family:inherit}
.setup-btn.secondary{background:var(--surface2);border:1px solid var(--border);color:var(--text);margin-top:8px}
.setup-btn.small{padding:9px 12px;border-radius:10px;font-size:14px;margin:0}
.setup-btn.left{text-align:left}
.form-error{min-height:18px;margin-top:10px;color:var(--danger);font-size:13px}
.chat-list{border-right:1px solid var(--border);background:var(--surface);overflow-y:auto}
.list-header{position:static;justify-content:space-between;min-height:58px}
.list-header h1{font-size:22px;margin-bottom:0;line-height:1.15}
.header-actions{display:flex;align-items:center;gap:6px}
.search-input{width:100%;background:var(--bg);border:1px solid var(--border);border-radius:10px;
  color:var(--text);padding:10px 12px;font:inherit;outline:none}
.search-input:focus{border-color:var(--accent)}
.search-results{padding-top:8px}
.panel{display:grid;gap:8px}
.person-row,.chat-item,.invite-row{display:flex;align-items:center;gap:10px;padding:10px;border-radius:8px}
.person-row:hover,.chat-item:hover,.chat-item.active{background:var(--surface2)}
.invite-copy{width:100%;border:0;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer}
.invite-copy:hover{background:var(--surface2)}
.person-main,.chat-main{min-width:0;flex:1}
.person-name,.chat-name{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.person-meta,.chat-last{color:var(--subtext);font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.avatar{width:34px;height:34px;border-radius:50%;border:1px solid var(--border);background:var(--surface2);
  color:var(--text);display:flex;align-items:center;justify-content:center;flex-shrink:0;
  font-size:13px;font-weight:700;overflow:hidden;cursor:pointer}
.avatar img{width:100%;height:100%;object-fit:cover;display:block}
.avatar.large{width:54px;height:54px;font-size:18px;background:var(--bg)}
.avatar.xlarge{width:86px;height:86px;font-size:28px;margin:4px auto 12px}
.header-avatar{width:38px;height:38px;font-size:14px}
.profile-edit-row{display:flex;align-items:center;gap:10px}
.profile-card{text-align:center;display:grid;gap:6px}
.profile-hero{text-align:center;display:grid;gap:5px;padding:2px 0 12px}
.profile-title{font-size:20px;font-weight:700;line-height:1.2}
.profile-subtitle{color:var(--subtext);font-size:13px}
.profile-subtitle.online{color:#3ecf8e}
.profile-info-list{display:grid;gap:0;margin-top:12px;border-top:1px solid var(--border)}
.profile-info-row{min-height:38px;display:grid;grid-template-columns:34px 1fr;align-items:center;
  gap:12px;padding:8px 2px;color:var(--text);text-align:left}
.profile-info-row span{color:var(--subtext);font-size:18px;text-align:center}
.profile-info-row b{font-size:14px;font-weight:500}
.profile-share-row{width:100%;border:0;border-top:1px solid var(--border);background:transparent;
  font:inherit;cursor:pointer;margin-top:4px}
.profile-share-row:hover{background:var(--surface2)}
.group-card{display:grid;gap:8px}
.group-members{display:grid;gap:4px}
.group-member-row{padding:9px 0}
.profile-action-list{display:grid;gap:8px;padding:10px 0;border-top:1px solid var(--border)}
.profile-action-row{display:grid;grid-template-columns:34px 1fr;gap:10px;align-items:center;
  width:100%;border:0;background:transparent;color:var(--text);font:inherit;text-align:left;padding:6px 0}
.profile-action-row>span{color:var(--subtext);font-size:18px;text-align:center}
.profile-action-button{cursor:pointer}
.profile-action-button:hover{background:var(--surface2)}
.profile-list-title{color:var(--subtext);font-size:12px;text-transform:uppercase;letter-spacing:.04em}
.profile-actions{display:grid;grid-template-columns:1fr;gap:8px;margin-top:12px}
.online-dot{width:8px;height:8px;border-radius:50%;background:var(--subtext2);flex-shrink:0}
.online-dot.on{background:#3ecf8e;box-shadow:0 0 6px #3ecf8e88}
.mini-btn{border:1px solid var(--border);background:var(--bg);color:var(--text);border-radius:8px;padding:7px 9px;cursor:pointer}
.mini-btn.danger{color:var(--danger)}
.person-actions{display:flex;align-items:center;gap:6px;flex-shrink:0}
.pick-btn{min-width:34px;font-weight:700}
.pick-btn.active{background:var(--accent);border-color:var(--accent);color:#fff}
.selected-users{display:flex;flex-wrap:wrap;gap:6px;min-height:34px;align-items:center}
.selected-chip{border:1px solid var(--border);background:var(--surface2);color:var(--text);
  border-radius:999px;padding:7px 10px;font:inherit;font-size:13px;cursor:pointer;
  max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.selected-chip span{color:var(--subtext);padding-left:4px}
.tool-hint{color:var(--subtext);font-size:12px;line-height:1.35}
.chat-view{display:grid;grid-template-rows:auto minmax(0,1fr) auto auto auto;min-width:0;height:var(--app-height, 100dvh);min-height:0;overflow:hidden}
.mobile-only{display:none}
.tools-overlay{position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:220;
  display:none;align-items:stretch;justify-content:flex-start}
.tools-overlay.open{display:flex}
.tools-drawer{width:min(86vw,360px);height:100%;background:var(--surface);
  border-right:1px solid var(--border);padding:calc(12px + max(var(--safe-top), 0px)) 12px calc(12px + var(--safe-bottom));
  box-shadow:14px 0 34px rgba(0,0,0,.35);overflow:auto;touch-action:pan-y}
.tools-head{display:flex;align-items:center;gap:10px;margin-bottom:14px}
.tools-head h3{font-size:17px;flex:1}
.menu-list{display:grid;gap:2px}
.menu-panel{border:0}
.menu-panel summary{list-style:none}
.menu-panel summary::-webkit-details-marker{display:none}
.menu-row{width:100%;min-height:44px;display:grid;grid-template-columns:34px 1fr auto;
  align-items:center;gap:10px;padding:8px 8px;border:0;border-radius:8px;background:transparent;
  color:var(--text);font:inherit;font-size:15px;font-weight:600;text-align:left;cursor:pointer}
.menu-row:hover{background:var(--surface2)}
.menu-row:focus{outline:none}
.menu-row:focus-visible{background:var(--surface2);box-shadow:inset 0 0 0 1px var(--border)}
.menu-action{appearance:none}
.menu-icon{width:26px;height:26px;display:flex;align-items:center;justify-content:center;
  color:var(--subtext);font-size:18px;line-height:1}
.menu-panel[open]>.menu-row{background:transparent}
.menu-panel[open]>.menu-row span:last-of-type{color:var(--text)}
.menu-panel[open]>.tool-section{margin:2px 0 10px 18px;padding:6px 0;
  border:0;border-radius:0;background:transparent}
.menu-panel[open]>.tool-section>*{max-width:100%}
.menu-panel[open]>.tool-section .tool-section{margin-left:0}
.menu-panel[open]>.tool-section .search-input,
.menu-panel[open]>.tool-section .setup-btn,
.menu-panel[open]>.tool-section .logout-btn,
.menu-panel[open]>.tool-section .toggle-row{border-radius:8px}
.menu-panel[open]>.tool-section .setup-btn.secondary.left{min-height:34px;padding:8px 0;
  border:0;background:transparent;color:var(--text);text-align:left}
.menu-panel[open]>.tool-section .setup-btn.secondary.left:hover{background:transparent;color:var(--accent)}
.menu-panel[open]>.tool-section .person-row{padding:8px 0;border-radius:0}
.menu-panel[open]>.tool-section .person-row:hover{background:transparent}
.admin-menu{margin-top:8px;padding-top:8px}
.menu-switch{width:48px;height:26px;border-radius:999px;background:var(--bg);border:1px solid var(--border);
  position:relative;transition:.18s}
.menu-switch::after{content:"";position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;
  background:var(--subtext);transition:.18s}
.menu-row.active .menu-switch{background:#f5d74d;border-color:#f5d74d}
.menu-row.active .menu-switch::after{left:25px;background:#1b1b1b}
.tool-category{display:grid;gap:8px;padding:12px 0;border-top:1px solid var(--border)}
.tool-category:first-of-type{border-top:none;padding-top:0}
.tool-section{display:grid;gap:9px;padding:10px;border:1px solid var(--border);
  border-radius:10px;background:var(--bg)}
.tool-category .tool-section+.tool-section{margin-top:2px}
.tool-row{display:grid;grid-template-columns:1fr auto;gap:8px}
.category-title{font-size:13px;color:var(--text);font-weight:700}
.section-title{font-size:12px;color:var(--subtext);text-transform:uppercase;letter-spacing:.04em}
.tool-footer{margin-top:auto;padding-top:14px;border-top:1px solid var(--border)}
.logout-btn{width:100%;padding:11px 12px;background:transparent;border:1px solid var(--border);
  color:var(--subtext);border-radius:10px;font:inherit;cursor:pointer;text-align:left}
.logout-btn:hover{color:var(--text);background:var(--surface2)}
.toggle-row{display:grid;grid-template-columns:1fr 46px;align-items:center;gap:12px;
  padding:12px 11px;border:1px solid var(--border);border-radius:10px;background:var(--surface2);
  color:var(--text);font:inherit;text-align:left;cursor:pointer;touch-action:manipulation}
.toggle-row strong{display:block;font-size:14px;font-weight:600}
.toggle-row small{display:block;margin-top:2px;color:var(--subtext);font-size:12px}
.toggle-row i{width:46px;height:26px;border-radius:999px;background:var(--bg);border:1px solid var(--border);
  position:relative;transition:.18s}
.toggle-row i::after{content:"";position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;
  background:var(--subtext);transition:.18s}
.toggle-row.active i{background:var(--accent);border-color:var(--accent)}
.toggle-row.active i::after{left:23px;background:#fff}
.toggle-row.muted{opacity:.65}
.admin-overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:250;
  display:none;align-items:flex-end;justify-content:center}
.admin-overlay.open{display:flex}
.profile-overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:245;
  display:none;align-items:flex-end;justify-content:center}
.profile-overlay.open{display:flex}
.admin-sheet,.profile-sheet{width:100%;max-width:520px;max-height:72vh;overflow:auto;background:var(--surface);
  border:1px solid var(--border);border-radius:18px 18px 0 0;
  padding:14px 14px calc(14px + var(--safe-bottom));box-shadow:0 -12px 32px rgba(0,0,0,.45);
  touch-action:pan-y;overscroll-behavior:contain}
.admin-head{display:flex;align-items:center;gap:10px;margin-bottom:12px}
.admin-head h3{font-size:16px;flex:1}
.admin-head .bar-close{width:38px;height:38px;border-radius:50%;background:var(--surface2)}
.action-list{display:grid;gap:8px}
.action-list button{width:100%;padding:12px;background:var(--surface2);border:1px solid var(--border);
  color:var(--text);border-radius:10px;font:inherit;cursor:pointer;text-align:left}
.action-list button.danger{color:var(--danger)}

/* ── HEADER ── */
header{background:var(--surface);border-bottom:1px solid var(--border);
  padding:12px 14px;display:flex;align-items:center;gap:10px;
  position:sticky;top:0;z-index:10;flex-shrink:0}
.chat-view>header{position:relative;top:auto;z-index:12}
header h1{font-size:17px;font-weight:600;flex:1}
.hdr-btn{background:none;border:none;color:var(--subtext);font-size:18px;
  cursor:pointer;padding:4px 6px;border-radius:8px;transition:.15s}
.hdr-btn:hover{color:var(--text);background:var(--surface2)}
.device-tag{font-size:12px;color:var(--subtext);background:var(--surface2);
  padding:3px 10px;border-radius:20px}
.device-tag.online{color:#3ecf8e;background:#3ecf8e1c}
.device-tag.typing{color:var(--accent);background:transparent;font-style:italic}
.lock-icon{font-size:13px;color:#3ecf8e}

/* ── MESSAGES ── */
#messages{min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:12px 10px 6px;
  display:flex;flex-direction:column;gap:3px;scroll-behavior:smooth}
#messages::-webkit-scrollbar{width:3px}
#messages::-webkit-scrollbar-thumb{background:var(--border);border-radius:3px}

.msg-row{display:flex;flex-direction:column;position:relative;transition:transform .15s}
.msg-row.me{align-items:flex-end}
.msg-row.other{align-items:flex-start}

.bubble{max-width:80%;padding:9px 13px;border-radius:var(--radius);
  line-height:1.5;word-break:break-word;position:relative}
.msg-row.me .bubble{background:var(--bubble-me);border-bottom-right-radius:5px;color:#cfe0ff}
.msg-row.other .bubble{background:var(--bubble-other);border:1px solid var(--border);
  border-bottom-left-radius:5px}
.bubble.deleted{opacity:.45;font-style:italic}
.bubble.video-bubble{padding:0;background:transparent!important;border:0!important;
  border-radius:0;overflow:visible;color:#fff}
.msg-row .bubble.video-bubble + .meta{display:none}

/* Forward label */
.fwd-label{font-size:11px;color:var(--accent);margin-bottom:4px;font-weight:500}

/* Reply quote */
.reply-quote{background:var(--reply-bg);border-left:3px solid var(--accent);
  border-radius:6px;padding:5px 9px;margin-bottom:7px;cursor:pointer}
.reply-quote .rq-name{font-weight:600;color:var(--accent);margin-bottom:1px;font-size:12px}
.reply-quote .rq-text{color:var(--subtext);white-space:nowrap;overflow:hidden;
  text-overflow:ellipsis;max-width:220px;font-size:13px}

/* Image */
.bubble img{max-width:100%;border-radius:10px;display:block;cursor:zoom-in;max-height:300px;object-fit:cover}

/* Voice */
.voice-player{display:flex;align-items:center;gap:8px;min-width:220px}
.play-btn{width:34px;height:34px;border-radius:50%;background:var(--accent);
  border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;
  flex-shrink:0;color:#fff;transition:transform .15s}
.play-btn svg{width:18px;height:18px;display:block;fill:currentColor}
.play-btn:active{transform:scale(.9)}
.voice-wave{height:26px;display:flex;align-items:center;gap:2px;flex:1;min-width:112px;opacity:.72}
.voice-wave i{width:2px;border-radius:999px;background:currentColor;opacity:.55}
.msg-row.me .voice-wave{color:#d7e4ff}
.msg-row.other .voice-wave{color:var(--subtext)}
.voice-duration{font-size:13px;color:var(--subtext);min-width:36px;text-align:right}
.video-note-card{position:relative;width:min(64vw,260px);aspect-ratio:1;
  display:flex;align-items:center;justify-content:center;overflow:visible;margin-bottom:8px}
.video-note{width:100%;aspect-ratio:1;border-radius:50%;display:block;object-fit:cover;
  background:#050505;border:1px solid rgba(255,255,255,.08);overflow:hidden;
  box-shadow:0 8px 28px rgba(0,0,0,.28);pointer-events:none}
.video-note::-webkit-media-controls,
.video-note::-webkit-media-controls-panel,
.video-note::-webkit-media-controls-play-button,
.video-note::-webkit-media-controls-start-playback-button{display:none!important;
  -webkit-appearance:none!important;opacity:0!important}
.video-note-info{position:absolute;left:50%;bottom:8px;min-width:54px;height:28px;
  transform:translateX(-50%);display:flex;align-items:center;justify-content:center;
  color:#f3f5ff;font-weight:700;text-shadow:0 1px 3px rgba(0,0,0,.8);
  background:rgba(20,22,31,.58);border-radius:14px;padding:0 10px;pointer-events:none}
audio{display:none}

/* File */
.file-card{display:flex;align-items:center;gap:10px;text-decoration:none;
  color:inherit;padding:2px 0}
.file-card.encrypted-file{width:100%;border:0;background:transparent;font:inherit;text-align:left;cursor:pointer}
.file-icon{font-size:28px;flex-shrink:0}
.file-info .fname{font-size:14px;font-weight:500;white-space:nowrap;
  overflow:hidden;text-overflow:ellipsis;max-width:180px}
.file-info .fsize{font-size:12px;color:var(--subtext);margin-top:2px}

/* Meta + read receipts */
.meta{font-size:11px;color:var(--subtext);margin-top:2px;padding:0 3px;
  display:flex;align-items:center;gap:4px}
.msg-row.me .meta{justify-content:flex-end}
.edited-tag{font-size:10px;color:var(--subtext2)}
.ticks{font-size:13px;line-height:1;color:var(--subtext)}
.ticks.read{color:var(--accent)}

/* ── CONTEXT MENU ── */
#ctx-menu{position:fixed;background:var(--surface);border:1px solid var(--border);
  border-radius:14px;padding:6px;z-index:100;box-shadow:0 8px 28px rgba(0,0,0,.5);
  min-width:170px;display:none}
#ctx-menu button{display:flex;align-items:center;gap:8px;width:100%;padding:9px 12px;
  background:none;border:none;color:var(--text);font-size:14px;cursor:pointer;
  border-radius:8px;text-align:left;transition:.15s}
#ctx-menu button:hover{background:var(--surface2)}
#ctx-menu button.danger{color:var(--danger)}
#ctx-menu .sep{height:1px;background:var(--border);margin:4px 0}

/* ── TYPING ── */
#typing{display:none}

/* ── REPLY BAR ── */
#reply-bar{background:var(--surface);border-top:1px solid var(--border);
  padding:8px 14px;display:none;align-items:center;gap:8px;flex-shrink:0}
#reply-bar.active{display:flex}
.reply-preview .rp-name{font-size:12px;color:var(--accent);font-weight:600}
.reply-preview .rp-text{font-size:13px;color:var(--subtext);white-space:nowrap;
  overflow:hidden;text-overflow:ellipsis;max-width:220px}
.bar-close{background:none;border:none;color:var(--subtext);font-size:20px;
  cursor:pointer;padding:0 4px;line-height:1;flex-shrink:0}

/* ── EDIT BAR ── */
#edit-bar{background:var(--surface);border-top:1px solid var(--border);
  padding:8px 14px;display:none;align-items:center;gap:8px;flex-shrink:0}
#edit-bar.active{display:flex}
.edit-label{font-size:13px;color:var(--accent);flex:1}
#voice-record-bar{display:none;align-items:center;gap:12px;background:var(--surface);
  border-top:1px solid var(--border);padding:10px 14px;flex-shrink:0}
#voice-record-bar.active{display:flex}
#video-note-preview{display:none;width:54px;height:54px;border-radius:50%;object-fit:cover;
  background:#050505;border:2px solid var(--accent);flex-shrink:0}
#voice-record-bar.video-active #video-note-preview{display:block}
.record-dot{width:10px;height:10px;border-radius:50%;background:var(--danger);animation:pulse 1s infinite}
#voice-record-time{font-size:22px;font-weight:700;letter-spacing:0;color:var(--text);min-width:76px}
.record-label{font-size:13px;color:var(--subtext);flex:1}
#voice-record-bar button{border:0;background:transparent;color:var(--accent);font:inherit;
  font-weight:700;padding:8px;cursor:pointer}

/* ── INPUT BAR ── */
#inputbar{background:var(--surface);border-top:1px solid var(--border);
  padding:10px 10px calc(10px + var(--safe-bottom));
  display:flex;gap:6px;align-items:flex-end;flex-shrink:0;position:relative;z-index:12}
#msg-input{flex:1;background:var(--bg);border:1px solid var(--border);
  border-radius:22px;padding:10px 14px;color:var(--text);font-size:15px;
  outline:none;resize:none;max-height:120px;line-height:1.4;
  transition:border-color .2s;font-family:inherit}
#msg-input:focus{border-color:var(--accent)}
#msg-input::placeholder{color:var(--subtext)}
.icon-btn{width:42px;height:42px;background:none;border:1px solid var(--border);
  border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;
  color:var(--subtext);flex-shrink:0;transition:.2s;font-size:18px}
.icon-btn:hover{border-color:var(--accent);color:var(--accent)}
.icon-btn:active{transform:scale(.9)}
#send-btn{width:42px;height:42px;background:var(--accent);border:none;border-radius:50%;
  cursor:pointer;display:flex;align-items:center;justify-content:center;
  color:#fff;flex-shrink:0;transition:.15s;font-size:18px}
#send-btn svg{width:19px;height:19px;display:block;fill:currentColor}
#send-btn.voice-mode svg{width:20px;height:20px}
.record-meter{width:25px;height:25px;display:flex;align-items:center;justify-content:center;gap:2px}
.record-meter i,.record-meter b{display:block;width:3px;border-radius:999px;background:currentColor;
  transition:height .08s ease}
.record-meter i:nth-child(1){height:var(--meter-1,7px);opacity:.7}
.record-meter i:nth-child(2){height:var(--meter-2,12px);opacity:.9}
.record-meter b{width:8px;height:8px;border-radius:2px;opacity:1}
.record-meter i:nth-child(4){height:var(--meter-4,12px);opacity:.9}
.record-meter i:nth-child(5){height:var(--meter-5,7px);opacity:.7}
#send-btn.voice-mode{background:none;border:1px solid var(--border);color:var(--subtext)}
#send-btn.recording{background:var(--danger)!important;border-color:var(--danger)!important;
  color:#fff!important;animation:pulse 1s infinite}
#send-btn:active{transform:scale(.9)}
#send-btn:disabled{background:var(--border);cursor:default;opacity:.5}

/* ── SETTINGS PANEL ── */
#settings-panel{position:fixed;inset:0;background:rgba(0,0,0,.6);z-index:150;
  display:none;align-items:flex-end;justify-content:center}
#settings-panel.open{display:flex}
.settings-sheet{background:var(--surface);border-radius:22px 22px 0 0;
  padding:20px 20px calc(20px + var(--safe-bottom));width:100%;max-width:480px}
.settings-sheet h3{font-size:17px;font-weight:600;margin-bottom:16px;text-align:center}
.settings-row{display:flex;align-items:center;justify-content:space-between;
  padding:12px 0;border-bottom:1px solid var(--border)}
.settings-row:last-child{border-bottom:none}
.settings-row label{font-size:15px;color:var(--text)}
.settings-row span{font-size:13px;color:var(--subtext);margin-top:2px}
/* Toggle */
.toggle{position:relative;width:48px;height:26px;flex-shrink:0}
.toggle input{opacity:0;width:0;height:0}
.toggle-slider{position:absolute;inset:0;background:var(--border);border-radius:13px;
  cursor:pointer;transition:.3s}
.toggle-slider:before{content:'';position:absolute;width:20px;height:20px;left:3px;bottom:3px;
  background:#fff;border-radius:50%;transition:.3s}
.toggle input:checked+.toggle-slider{background:var(--accent)}
.toggle input:checked+.toggle-slider:before{transform:translateX(22px)}

/* ── LIGHTBOX ── */
#lightbox{position:fixed;inset:0;background:rgba(0,0,0,.93);z-index:300;
  display:none;align-items:center;justify-content:center;cursor:zoom-out}
#lightbox img{max-width:95vw;max-height:95vh;border-radius:8px;object-fit:contain}

/* ── VIDEO VIEWER ── */
#video-viewer{position:fixed;inset:0;background:rgba(0,0,0,.94);z-index:370;
  display:none;align-items:center;justify-content:center;padding:24px;cursor:pointer}
#video-viewer.open{display:flex}
#video-viewer-player{width:min(92vw,620px);height:min(92vw,620px);border-radius:50%;
  object-fit:cover;background:#050505;box-shadow:0 24px 80px rgba(0,0,0,.65);cursor:default}
.viewer-close{position:absolute;top:calc(14px + var(--safe-top));right:18px;width:42px;height:42px;
  border-radius:50%;border:1px solid rgba(255,255,255,.16);background:rgba(24,24,28,.76);
  color:#fff;font-size:22px;z-index:1}

/* ── VIDEO RECORD ── */
#video-record-overlay{position:fixed;inset:0;z-index:380;display:none;overflow:hidden;color:#fff}
#video-record-overlay.active{display:block}
.video-record-dim{position:absolute;inset:0;background:rgba(0,0,0,.78);backdrop-filter:blur(2px)}
.video-record-stage{position:absolute;left:50%;top:13%;width:min(88vw,560px);aspect-ratio:1;
  transform:translateX(-50%);display:flex;align-items:center;justify-content:center}
#video-note-full-preview{width:100%;height:100%;border-radius:50%;object-fit:cover;background:#111;
  box-shadow:0 26px 80px rgba(0,0,0,.55)}
.video-progress{position:absolute;top:-18px;left:50%;width:110px;height:7px;border-radius:999px;
  background:#fff;transform:translateX(-50%) rotate(12deg);box-shadow:0 0 10px rgba(255,255,255,.35);
  z-index:1}
.video-record-tools{position:absolute;left:18px;bottom:100px;display:flex;background:#232532;
  border:1px solid rgba(255,255,255,.08);border-radius:24px;overflow:hidden}
.video-record-tools button{width:56px;height:52px;border:0;background:transparent;color:#fff;
  font-size:28px;font-weight:800}
#video-record-pause{position:absolute;right:26px;bottom:150px;width:58px;height:58px;border-radius:50%;
  border:0;background:#31364d;color:#fff;font-size:26px;font-weight:900}
.video-record-bottom{position:absolute;left:18px;right:86px;bottom:26px;height:68px;
  border-radius:20px;background:#232532;display:flex;align-items:center;gap:18px;padding:0 20px;
  box-shadow:0 12px 34px rgba(0,0,0,.35)}
.video-record-bottom .record-dot{flex:0 0 auto}
.video-record-bottom strong{font-size:27px;min-width:94px;letter-spacing:0}
.video-record-bottom button{margin-left:auto;border:0;background:transparent;color:#9fb4ff;
  font-size:20px;font-weight:800;letter-spacing:0}
#video-record-send{position:absolute;right:-10px;bottom:10px;width:118px;height:118px;border-radius:50%;
  border:10px solid rgba(72,126,255,.32);background:var(--accent);color:#fff;font-size:54px;
  font-weight:900;display:flex;align-items:center;justify-content:center;box-shadow:0 18px 50px rgba(45,103,255,.45)}

/* ── CONFIRM ── */
.confirm-overlay{position:fixed;inset:0;background:rgba(0,0,0,.58);z-index:360;
  display:none;align-items:center;justify-content:center;padding:22px}
.confirm-overlay.open{display:flex}
.confirm-sheet{width:100%;max-width:360px;background:var(--surface);border:1px solid var(--border);
  border-radius:14px;padding:18px;box-shadow:0 18px 44px rgba(0,0,0,.45)}
.confirm-sheet h3{font-size:17px;margin-bottom:8px}
.confirm-sheet p{color:var(--subtext);font-size:14px;line-height:1.45;white-space:pre-line}
.confirm-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:18px}
.confirm-actions .mini-btn{min-height:42px;background:var(--surface2)}

/* ── TOAST ── */
#upload-toast{position:fixed;bottom:110px;left:50%;transform:translateX(-50%);
  background:var(--surface);border:1px solid var(--border);border-radius:12px;
  padding:10px 16px;font-size:13px;z-index:150;display:none;align-items:center;gap:8px;
  white-space:nowrap}
#upload-toast.show{display:flex}

/* ── EMPTY ── */
#empty-state{flex:1;display:flex;flex-direction:column;align-items:center;
  justify-content:center;color:var(--subtext);gap:8px;pointer-events:none}
#empty-state svg{opacity:.15}

@keyframes fadeUp{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
@keyframes pulse{0%,100%{box-shadow:0 0 0 0 rgba(255,79,79,.4)}50%{box-shadow:0 0 0 8px rgba(255,79,79,0)}}

@media (max-width:760px){
  .app-shell{display:block;width:100vw;overflow:hidden}
  .chat-list,.chat-view{height:var(--app-height, 100dvh);width:100vw}
  .chat-list{border-right:none}
  .list-header,.chat-view>header{padding-top:calc(12px + max(var(--safe-top), 28px))}
  .chat-view{display:none}
  .app-shell.chat-open .chat-list{display:none}
  .app-shell.chat-open .chat-view{display:grid}
  .mobile-only{display:inline-flex}
  .search-input{min-width:0}
  .setup-btn.small{min-height:42px}
  .video-record-stage{top:15%;width:92vw}
}
