:root{
  --bg:#f7f3f8;
  --surface:#fffafd;
  --surface-2:#f0edf6;
  --surface-3:#e7f4ee;
  --text:#1d1b20;
  --muted:#696673;
  --primary:#5b5ce2;
  --on-primary:#ffffff;
  --secondary:#006a67;
  --tertiary:#b3261e;
  --accent:#ffb300;
  --outline:rgba(29,27,32,.12);
  --mine:#dff7df;
  --other:#ffffff;
  --toast:rgba(255,250,253,.96);
  --shadow:0 22px 56px rgba(44,38,58,.14);
  --soft-shadow:0 8px 22px rgba(44,38,58,.08);
  font-family:ui-rounded,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;
}
:root[data-theme="dark"]{
  --bg:#141316;
  --surface:#211f26;
  --surface-2:#2d2a34;
  --surface-3:#183b35;
  --text:#f4eff4;
  --muted:#cac4d0;
  --primary:#c6c4ff;
  --on-primary:#202060;
  --secondary:#7ddad3;
  --tertiary:#ffb4ab;
  --accent:#ffd36b;
  --outline:rgba(244,239,244,.14);
  --mine:#244a34;
  --other:#2b2930;
  --toast:rgba(33,31,38,.96);
  --shadow:0 22px 56px rgba(0,0,0,.34);
  --soft-shadow:0 8px 22px rgba(0,0,0,.22);
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  overflow:hidden;
  color:var(--text);
  background:linear-gradient(135deg,#f8f1f4 0%,#eef7f1 48%,#f7f0ff 100%);
  transition:background .2s ease,color .2s ease;
}
:root[data-theme="dark"] body{background:linear-gradient(135deg,#151318 0%,#111d1a 52%,#1a1723 100%)}
[hidden]{display:none!important}
button,input,textarea{font:inherit}
button{border:0;cursor:pointer}
button:focus-visible,input:focus-visible,textarea:focus-visible{outline:3px solid color-mix(in srgb,var(--primary) 34%,transparent);outline-offset:2px}
.glass{background:color-mix(in srgb,var(--surface) 92%,transparent);border:1px solid var(--outline);box-shadow:var(--shadow)}

.login-shell{min-height:100%;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(320px,.95fr);gap:24px;align-items:center;padding:clamp(18px,4vw,60px)}
.brand-card,.login-card{border-radius:28px;padding:36px}
.brand-card h1{font-size:clamp(36px,7vw,74px);margin:16px 0 10px;letter-spacing:0;line-height:1.04}
.brand-card p{font-size:20px;color:var(--muted);line-height:1.8}
.logo-bubble{width:86px;height:86px;border-radius:30px;background:linear-gradient(135deg,var(--primary),var(--secondary));color:var(--on-primary);display:grid;place-items:center;font-size:42px;font-weight:900;box-shadow:var(--soft-shadow)}
.safe-line{display:inline-flex;margin-top:18px;border-radius:999px;padding:10px 16px;background:var(--surface-3);color:var(--secondary);font-weight:800}
.login-card{max-width:480px;width:100%;justify-self:center;display:grid;gap:18px}
.sso-card h2{margin:0;font-size:28px}
.sso-desc{margin:0;color:var(--muted);line-height:1.8}
.auth-actions{display:grid;gap:12px}
.auth-link{display:flex;align-items:center;justify-content:center;text-decoration:none}
.sso-note{margin:0;color:var(--muted);font-size:12px;line-height:1.6;word-break:break-all}
.sso-note code{padding:2px 6px;border-radius:8px;background:var(--surface-2);color:var(--primary)}
.msg{min-height:22px;color:var(--tertiary)}

.app-shell{height:100%;display:grid;grid-template-columns:320px minmax(0,1fr);gap:14px;padding:14px}
.sidebar,.workspace{border-radius:28px;min-height:0}
.sidebar{display:flex;flex-direction:column;padding:14px;gap:12px}
.me{display:grid;grid-template-columns:52px minmax(0,1fr);gap:12px;align-items:center;padding:12px;border-radius:22px;background:var(--surface)}
.avatar{width:48px;height:48px;border-radius:18px;background:var(--avatar,var(--primary));color:white;display:grid;place-items:center;font-weight:900;font-size:22px;flex:0 0 auto;box-shadow:var(--soft-shadow)}
.avatar img,.room-avatar img{width:100%;height:100%;object-fit:cover;border-radius:inherit;display:block}
.me strong{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.me span{display:block;color:var(--muted);font-size:13px;margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.soft,.ghost,.theme-toggle{border-radius:999px;padding:12px 14px;background:var(--surface-2);color:var(--primary);font-weight:900}
.soft:hover,.theme-toggle:hover,.room:hover,.tool:hover,.view-tab:hover{filter:brightness(.98);transform:translateY(-1px)}
.ghost{margin-top:auto;background:transparent;color:var(--muted);border:1px solid var(--outline)}
.room-title{color:var(--muted);font-weight:900;padding:6px 8px 0}
.rooms{display:grid;gap:8px;overflow:auto;padding-right:2px}
.room{display:grid;grid-template-columns:38px minmax(0,1fr) auto;gap:10px;align-items:center;padding:10px;border-radius:20px;background:transparent;color:var(--text);text-align:left;transition:.16s ease}
.room.active{background:var(--surface-3);color:var(--secondary);font-weight:900}
.room span:nth-child(2){overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.room small{font-size:11px;color:var(--muted)}
.room-avatar{width:38px;height:38px;border-radius:15px;background:var(--room-avatar,var(--secondary));color:#fff;display:grid;place-items:center;font-size:16px;font-weight:900}
.room-avatar.lg{width:76px;height:76px;border-radius:26px;font-size:30px;box-shadow:var(--soft-shadow)}

.workspace{display:grid;grid-template-rows:auto minmax(0,1fr);overflow:hidden}
.chat-head{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:14px 18px;border-bottom:1px solid var(--outline)}
.chat-head h2{margin:0;font-size:24px;line-height:1.18}
.chat-head p{margin:4px 0 0;color:var(--muted);font-size:13px}
.view-tabs{display:flex;gap:8px;padding:5px;border-radius:999px;background:var(--surface-2);flex:0 0 auto}
.view-tab{min-width:94px;border-radius:999px;padding:10px 14px;background:transparent;color:var(--muted);font-weight:900}
.view-tab.active{background:var(--surface);color:var(--primary);box-shadow:var(--soft-shadow)}

.chat-view{min-height:0;display:grid;grid-template-rows:minmax(0,1fr) auto}
.messages{padding:18px;overflow:auto;display:flex;flex-direction:column;gap:12px}
.day-tip{align-self:center;color:var(--muted);background:var(--surface-2);border-radius:999px;padding:6px 12px;font-size:12px}
.msg-row{display:flex;gap:10px;align-items:flex-start;max-width:min(78%,820px);animation:pop .18s ease-out}
.msg-row.mine{align-self:flex-end;flex-direction:row-reverse}
.bubble{padding:11px 14px;border-radius:8px 22px 22px 22px;background:var(--other);box-shadow:var(--soft-shadow);line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere}
.mine .bubble{background:var(--mine);border-radius:22px 8px 22px 22px}
.meta{display:flex;gap:6px;align-items:center;margin-bottom:4px;color:var(--muted);font-size:12px}
.badge{background:var(--accent);color:#241a00;border-radius:999px;padding:2px 7px;font-weight:900}
.file-card{display:grid;gap:8px}
.file-card button{justify-self:start;border-radius:999px;background:var(--surface-2);color:var(--primary);padding:8px 12px;font-weight:900}
.decrypt-warn{color:var(--tertiary);font-size:12px}

.composer{position:relative;display:grid;grid-template-columns:auto auto minmax(0,1fr) auto;gap:10px;align-items:end;padding:12px 14px;border-top:1px solid var(--outline);background:color-mix(in srgb,var(--surface) 84%,transparent)}
input,textarea{width:100%;border:1px solid var(--outline);background:var(--surface);color:var(--text);border-radius:18px;padding:13px 15px;outline:none}
textarea{min-height:48px;max-height:160px;resize:none;line-height:1.45}
.tool{width:46px;height:46px;border-radius:18px;background:var(--surface-2);color:var(--primary);font-weight:900}
.primary,.send{background:var(--primary);color:var(--on-primary);border-radius:999px;padding:13px 20px;font-weight:900}
.send{min-height:46px}
.emoji-panel{position:absolute;left:14px;bottom:70px;display:grid;grid-template-columns:repeat(8,40px);gap:6px;padding:12px;border-radius:22px;background:var(--surface);box-shadow:var(--shadow);border:1px solid var(--outline)}
.emoji-panel button{width:40px;height:40px;border-radius:14px;background:var(--surface-2);font-size:20px}

.voice-view{min-height:0;display:grid;grid-template-rows:minmax(0,1fr) auto;padding:18px;gap:14px}
.voice-lobby{min-height:0;display:grid;align-content:center;justify-items:center;text-align:center;gap:12px;border-radius:28px;background:var(--surface-2);padding:24px}
.voice-lobby h3{margin:0;font-size:26px}
.voice-lobby p{margin:0;max-width:420px;color:var(--muted);line-height:1.7}
.voice-room-avatar{width:92px;height:92px;border-radius:32px;background:linear-gradient(135deg,var(--primary),var(--secondary));color:var(--on-primary);display:grid;place-items:center;font-size:34px;font-weight:900;box-shadow:var(--soft-shadow)}
.voice-stage{min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 280px;gap:14px}
.voice-card{position:relative;overflow:hidden;border-radius:28px;background:#08080a;border:1px solid var(--outline);box-shadow:var(--soft-shadow)}
.voice-card video{width:100%;height:100%;min-height:260px;object-fit:cover;display:block;background:#08080a}
.voice-card.local video{min-height:180px}
.voice-label{position:absolute;left:12px;bottom:12px;border-radius:999px;padding:6px 10px;background:rgba(0,0,0,.52);color:#fff;font-size:12px;font-weight:900}
.voice-console{display:flex;align-items:center;justify-content:space-between;gap:14px;padding:14px;border-radius:24px;background:var(--surface-2)}
.voice-console h3{margin:0;font-size:20px}
.voice-console p{margin:4px 0 0;color:var(--muted);font-size:13px}
.call-actions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.call-actions button{min-width:48px;height:48px;border-radius:18px;background:var(--surface);color:var(--primary);font-weight:900;box-shadow:var(--soft-shadow)}
.call-actions .danger{width:auto;padding:0 16px;color:#fff;background:var(--tertiary)}
.volume-control{margin-top:8px;display:grid;grid-template-columns:auto 150px;gap:10px;align-items:center;color:var(--muted);font-size:13px}
.volume-control input{padding:0;border:0;background:transparent}

.panel-view{min-height:0;overflow:auto;padding:18px;display:grid;align-content:start;gap:14px}
.panel-head{display:flex;align-items:flex-start;justify-content:space-between;gap:14px}
.panel-head h3,.group-card h3{margin:0;font-size:22px}
.panel-head p,.group-card p{margin:5px 0 0;color:var(--muted);font-size:13px}
.file-mode{display:flex;gap:10px;flex-wrap:wrap}
.file-mode label{display:flex;grid-auto-flow:column;align-items:center;gap:6px;border-radius:999px;background:var(--surface-2);padding:9px 12px;color:var(--text);font-weight:800}
.file-mode input{width:auto}
.storage-bar{height:10px;border-radius:999px;background:var(--surface-2);overflow:hidden}
.storage-bar span{display:block;width:0%;height:100%;border-radius:inherit;background:linear-gradient(90deg,var(--secondary),var(--primary));transition:width .2s ease}
.file-list,.member-list{display:grid;gap:10px}
.file-item,.member-item{display:grid;grid-template-columns:48px minmax(0,1fr) auto;gap:12px;align-items:center;padding:12px;border-radius:20px;background:var(--surface);border:1px solid var(--outline)}
.file-item strong,.member-item strong{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.file-item span,.member-item span{display:block;color:var(--muted);font-size:12px;margin-top:3px}
.file-item button,.member-item button{border-radius:999px;background:var(--surface-2);color:var(--primary);padding:8px 12px;font-weight:900}
.group-grid{display:grid;grid-template-columns:minmax(280px,.85fr) minmax(320px,1.15fr);gap:14px;align-items:start}
.group-card{display:grid;gap:14px;padding:16px;border-radius:24px;background:var(--surface);border:1px solid var(--outline)}
.group-avatar-editor{display:grid;gap:12px}
.color-row{display:flex;gap:8px;flex-wrap:wrap}
.color-swatch{width:34px;height:34px;border-radius:14px;border:2px solid var(--surface);box-shadow:0 0 0 1px var(--outline);cursor:pointer}
.color-swatch.active{box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 45%,transparent)}
.admin-form{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px}

.theme-toggle.floating{position:fixed;right:18px;top:18px;z-index:10;box-shadow:var(--shadow)}
.mini{padding:10px 16px;border-radius:999px}
.modal-backdrop{position:fixed;inset:0;z-index:100;display:grid;place-items:center;padding:18px;background:rgba(0,0,0,.28);backdrop-filter:blur(12px)}
.modal-card{width:min(440px,100%);border-radius:28px;padding:24px;display:grid;gap:16px}
.modal-card h3{margin:0;font-size:24px}
.modal-card p{margin:0;color:var(--muted);line-height:1.7}
.modal-actions{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap}
.toast-stack{position:fixed;right:18px;bottom:18px;z-index:120;display:grid;gap:10px;max-width:min(420px,calc(100vw - 36px))}
.toast{transform:translateY(8px);opacity:0;transition:.22s ease;border:1px solid var(--outline);box-shadow:var(--shadow);background:var(--toast);color:var(--text);padding:12px 14px;border-radius:20px;line-height:1.55}
.toast.show{transform:none;opacity:1}
.toast.success{border-color:color-mix(in srgb,var(--secondary) 38%,transparent)}
.toast.warn{border-color:color-mix(in srgb,var(--accent) 55%,transparent)}
.toast.error{border-color:color-mix(in srgb,var(--tertiary) 42%,transparent)}

@keyframes pop{from{transform:translateY(8px) scale(.98);opacity:0}to{transform:none;opacity:1}}
@media(max-width:980px){
  body{overflow:auto}
  .app-shell{height:100dvh;grid-template-columns:1fr;padding:10px}
  .sidebar{position:fixed;z-index:5;left:10px;right:10px;bottom:10px;max-height:42dvh;transform:translateY(calc(100% - 72px));transition:.2s;border-radius:26px}
  .sidebar:hover,.sidebar:focus-within{transform:translateY(0)}
  .workspace{height:100%;border-radius:24px}
  .chat-head{align-items:flex-start;flex-direction:column}
  .view-tabs{width:100%}
  .view-tab{flex:1}
  .msg-row{max-width:92%}
  .voice-stage{grid-template-columns:1fr}
  .voice-card video,.voice-card.local video{min-height:210px}
  .voice-console{align-items:flex-start;flex-direction:column}
  .call-actions{width:100%;justify-content:flex-start}
  .panel-head{flex-direction:column}
  .group-grid{grid-template-columns:1fr}
  .admin-form{grid-template-columns:1fr}
  .composer{grid-template-columns:auto auto minmax(0,1fr)}
  .send{grid-column:1 / -1}
  .brand-card{display:none}
  .login-shell{grid-template-columns:1fr}
}
@media(max-width:520px){
  .emoji-panel{grid-template-columns:repeat(6,40px);max-width:calc(100vw - 36px);overflow:auto}
  .login-card{border-radius:24px;padding:24px}
  .theme-toggle.floating{right:12px;top:12px;padding:10px 12px}
  .toast-stack{left:12px;right:12px;bottom:12px;max-width:none}
}
