:root {
  --rail: #1e1f22;
  --side: #2b2d31;
  --panel: #313338;
  --panel-2: #383a40;
  --hover: rgba(78,80,88,.3);
  --active: rgba(78,80,88,.48);
  --line: rgba(255,255,255,.06);
  --text: #f2f3f5;
  --text-2: #dbdee1;
  --muted: #949ba4;
  --faint: #80848e;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --yellow: #f0b232;
  --danger: #f23f43;
  --shadow: 0 8px 16px rgba(0,0,0,.24);
  --font: "gg sans", "Noto Sans", Inter, "Helvetica Neue", Helvetica, Arial, ui-sans-serif, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { font: 16px/1.375 var(--font); color: var(--text-2); background: var(--panel); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.ico { width: 24px; height: 24px; flex: none; fill: currentColor; pointer-events: none; }
.ico.small { width: 18px; height: 18px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 8px; background: #1a1b1e; background-clip: padding-box; }
.messages::-webkit-scrollbar { width: 16px; }
.messages::-webkit-scrollbar-thumb { border-width: 4px; }
.messages::-webkit-scrollbar-track { border: 4px solid transparent; border-radius: 8px; background: #2b2d31; background-clip: padding-box; }

/* Tooltips */
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; z-index: 90; padding: 8px 12px; border-radius: 4px; background: #111214; color: var(--text-2); font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .08s; }
[data-tip]::before { content: ""; position: absolute; z-index: 90; border: 6px solid transparent; opacity: 0; pointer-events: none; transition: opacity .08s; }
[data-tip]:hover::after, [data-tip]:hover::before { opacity: 1; }
.guild-rail [data-tip]::after { left: calc(100% + 16px); top: 50%; transform: translateY(-50%); }
.guild-rail [data-tip]::before { left: calc(100% + 4px); top: 50%; transform: translateY(-50%); border-right-color: #111214; }
.head-tools [data-tip]::after { right: 0; top: calc(100% + 8px); }
.head-tools [data-tip]::before { right: 10px; top: calc(100% - 4px); border-bottom-color: #111214; }

/* Login */
.login-shell { min-height: 100%; display: grid; place-items: center; padding: 24px; background: #5865f2 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1600' height='900' viewBox='0 0 1600 900'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0' stop-color='%235865f2'/%3E%3Cstop offset='1' stop-color='%233c45a5'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='1600' height='900' fill='url(%23g)'/%3E%3Ccircle cx='230' cy='180' r='260' fill='%23ffffff' fill-opacity='.05'/%3E%3Ccircle cx='1420' cy='760' r='320' fill='%23000000' fill-opacity='.08'/%3E%3Ccircle cx='1300' cy='120' r='120' fill='%23ffffff' fill-opacity='.06'/%3E%3C/svg%3E") center/cover; }
.login-card { width: min(480px, 100%); padding: 32px; border-radius: 5px; background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.2); text-align: center; }
.login-brand { width: 48px; height: 48px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 16px; background: var(--accent); color: white; }
.login-brand .ico { width: 30px; height: 30px; }
.login-card h1 { margin: 0; color: var(--text); font-size: 24px; font-weight: 600; }
.login-card .muted { margin: 8px 0 20px; }
.login-card label { display: block; margin-bottom: 8px; color: #b5bac1; font-size: 12px; font-weight: 700; text-align: left; letter-spacing: .02em; }
.login-card label .req { color: var(--danger); }
.login-card input { width: 100%; height: 40px; padding: 10px; border: 0; border-radius: 3px; color: var(--text-2); outline: none; background: #1e1f22; }
.login-card input:focus { box-shadow: 0 0 0 1px rgba(88,101,242,.6); }
.login-card button { width: 100%; height: 44px; margin-top: 20px; padding: 2px 16px; border: 0; border-radius: 3px; color: white; font-weight: 500; cursor: pointer; background: var(--accent); transition: background .17s; }
.login-card button:hover { background: var(--accent-hover); }
.error { min-height: 20px; margin: 8px 0 0; color: var(--danger); font-size: 13px; text-align: left; }
.login-hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; text-align: left; }

/* Shell */
.app-shell { width: 100%; height: 100dvh; display: grid; grid-template-columns: 72px 240px minmax(0, 1fr); overflow: hidden; background: var(--panel); }

/* Guild rail */
.guild-rail { z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow: visible; background: var(--rail); }
.rail-slot { position: relative; width: 72px; display: flex; justify-content: center; }
.rail-slot::before { content: ""; position: absolute; left: 0; top: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 4px; background: var(--text); transform: translateY(-50%) scale(0); transition: transform .15s, height .15s; }
.rail-slot:hover::before { height: 20px; transform: translateY(-50%) scale(1); }
.rail-slot.active::before { height: 40px; transform: translateY(-50%) scale(1); }
.rail-item { width: 48px; height: 48px; display: grid; place-items: center; border: 0; border-radius: 24px; background: var(--panel); color: var(--text-2); font-size: 15px; font-weight: 500; cursor: pointer; transition: border-radius .15s ease-out, background .15s, color .15s; }
.rail-item:hover, .rail-item.active { border-radius: 16px; background: var(--accent); color: white; }
.rail-item.rail-action { color: var(--green); }
.rail-item.rail-action:hover:not(:disabled) { background: var(--green); color: white; }
.rail-item.rail-action.danger { color: var(--danger); }
.rail-item.rail-action.danger:hover { background: var(--danger); color: white; }
.rail-item:disabled { cursor: default; }
.rail-item:disabled:hover { border-radius: 24px; background: var(--panel); color: var(--green); }
.rail-divider { width: 32px; height: 2px; border-radius: 1px; background: #35363c; }
.rail-spacer { flex: 1; }
#server-rail { display: contents; }
.server-initial { font-size: 14px; font-weight: 500; letter-spacing: .01em; }

/* Sidebar */
.sidebar { position: relative; z-index: 20; min-width: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: var(--side); }
.sidebar-head { flex: 0 0 48px; display: flex; align-items: center; gap: 6px; padding: 0 16px; box-shadow: 0 1px 0 rgba(0,0,0,.24), 0 1.5px 0 rgba(0,0,0,.05), 0 2px 0 rgba(0,0,0,.05); cursor: default; }
.sidebar-head:hover { background: rgba(78,80,88,.16); }
.sidebar-head h2 { flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 16px; font-weight: 600; }
.sidebar-head .ico { color: var(--text); }
.search-wrap { padding: 10px 10px 0; }
.search-wrap input { width: 100%; height: 28px; padding: 1px 6px; border: 0; border-radius: 4px; outline: none; color: var(--text-2); font-size: 14px; background: var(--rail); }
.search-wrap input::placeholder { color: var(--muted); }
.server-mode .search-wrap { display: none; }
.dm-nav { padding: 8px 8px 0; }
.server-mode .dm-nav { display: none; }
.destination-list { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 12px; scrollbar-width: thin; scrollbar-color: #1a1b1e transparent; }
.section-label { position: relative; display: flex; align-items: center; gap: 2px; margin: 0; padding: 18px 8px 4px 2px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; cursor: default; user-select: none; }
.section-label:hover { color: var(--text-2); }
.section-label .ico { width: 12px; height: 12px; }
.section-label .count { margin-left: auto; padding-right: 4px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.dm-list .section-label { padding-top: 18px; }
.dm-list .section-label .add { margin-left: auto; width: 16px; height: 16px; color: var(--muted); }
.destination { width: 100%; height: 42px; display: flex; align-items: center; gap: 12px; margin: 1px 0; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.destination .ico { color: var(--faint); }
.server-list .destination { height: 32px; gap: 6px; padding: 0 8px 0 6px; }
.destination:hover { color: var(--text-2); background: var(--hover); }
.destination:hover .ico { color: var(--text-2); }
.destination.active { color: var(--text); background: var(--active); }
.destination.active .ico { color: var(--text); }
.destination.static { color: var(--muted); }
.destination.static:disabled { cursor: default; }
.destination:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.destination .avatar { width: 32px; height: 32px; font-size: 12px; }
.destination-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.destination-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 500; }
.server-list .destination-copy strong { font-size: 16px; }
.destination-copy small { color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.destination .close { width: 16px; height: 16px; opacity: 0; color: var(--muted); }
.destination:hover .close { opacity: 1; }

/* Avatars */
.avatar { position: relative; flex: none; display: grid; place-items: center; border-radius: 50%; color: white; font-weight: 600; background: var(--accent); }
.avatar.c0 { background: #5865f2; } .avatar.c1 { background: #757e8a; } .avatar.c2 { background: #23a559; } .avatar.c3 { background: #f0b232; } .avatar.c4 { background: #f23f43; } .avatar.c5 { background: #eb459f; }
.avatar-andrix { background: var(--accent); }
.status { position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; border: 3px solid #232428; border-radius: 50%; background: var(--faint); }
.status.online { background: var(--green); }
.status.idle { background: var(--yellow); }

/* User panel */
.user-panel { flex: 0 0 52px; display: flex; align-items: center; gap: 2px; padding: 0 8px; background: #232428; }
.user-chip { flex: 1; min-width: 0; height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 2px; border: 0; border-radius: 4px; background: transparent; text-align: left; cursor: pointer; }
.user-chip:hover { background: rgba(78,80,88,.4); }
.user-chip .avatar.small { width: 32px; height: 32px; font-size: 13px; }
.user-copy { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.user-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 14px; font-weight: 600; }
.user-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 12px; }
.user-actions { display: flex; }
.user-actions button { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 4px; background: transparent; color: #b5bac1; cursor: pointer; }
.user-actions button .ico { width: 20px; height: 20px; }
.user-actions button:hover { background: rgba(78,80,88,.4); color: var(--text-2); }
.user-actions button:disabled { cursor: default; }

/* Chat panel */
.chat-panel { position: relative; min-width: 0; height: 100dvh; display: grid; grid-template-rows: 48px minmax(0, 1fr) auto; overflow: hidden; background: var(--panel); }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 16px; box-shadow: 0 1px 0 rgba(0,0,0,.24), 0 1.5px 0 rgba(0,0,0,.05), 0 2px 0 rgba(0,0,0,.05); }
.chat-symbol { display: grid; place-items: center; color: var(--faint); }
.chat-symbol .avatar { width: 24px; height: 24px; font-size: 10px; }
.chat-title-wrap { min-width: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.chat-title-wrap h2 { margin: 0; color: var(--text); font-size: 16px; font-weight: 600; white-space: nowrap; }
.head-divider { width: 1px; height: 24px; margin: 0 4px; background: #3f4147; }
.chat-title-wrap p { margin: 0; color: var(--text-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-tools { display: flex; align-items: center; gap: 4px; }
.head-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 4px; color: #b5bac1; background: transparent; cursor: pointer; }
.head-icon:hover { color: var(--text-2); }
.head-icon:disabled { cursor: default; }
.head-search { width: 144px; height: 24px; margin: 0 8px; display: flex; align-items: center; justify-content: space-between; padding: 0 4px 0 6px; border-radius: 4px; background: var(--rail); color: var(--muted); font-size: 14px; }
.head-search .ico { width: 16px; height: 16px; }
.mobile-menu { display: none; }

/* Messages */
.messages { min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 0 0 8px; scrollbar-gutter: stable; }
.channel-intro { margin: 16px 16px 8px; }
.channel-intro .intro-icon { width: 68px; height: 68px; display: grid; place-items: center; margin: 32px 0 16px; border-radius: 50%; background: #41434a; color: var(--text); }
.channel-intro .intro-icon .ico { width: 42px; height: 42px; }
.channel-intro .intro-icon.avatar { width: 80px; height: 80px; font-size: 30px; }
.channel-intro h1 { margin: 0 0 8px; color: var(--text); font-size: 32px; font-weight: 700; line-height: 1.25; }
.channel-intro p { margin: 0; color: #b5bac1; font-size: 16px; }
.day-divider { position: relative; display: flex; align-items: center; justify-content: center; height: 0; margin: 24px 16px 8px; border-top: 1px solid #3f4147; }
.day-divider span { padding: 2px 4px; background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; line-height: 13px; }
.message { position: relative; padding: 2px 48px 2px 72px; }
.message.first { margin-top: 17px; padding-top: 2px; min-height: 44px; }
.message:hover { background: rgba(2,2,2,.06); }
.message .avatar { position: absolute; left: 16px; top: 2px; width: 40px; height: 40px; font-size: 15px; }
.message-meta { display: flex; align-items: baseline; gap: 4px; line-height: 22px; }
.message-meta strong { margin-right: 4px; color: var(--text); font-size: 16px; font-weight: 500; cursor: pointer; }
.message-meta strong:hover { text-decoration: underline; }
.message-meta time { color: var(--muted); font-size: 12px; }
.message-content { color: var(--text-2); font-size: 16px; line-height: 22px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.cont .hover-time { position: absolute; left: 0; top: 4px; width: 56px; padding-right: 8px; color: var(--muted); font-size: 11px; line-height: 22px; text-align: right; opacity: 0; }
.message.cont:hover .hover-time { opacity: 1; }
.message.mine .message-meta strong { color: #a5b2ff; }
.bot-tag { margin-left: 2px; padding: 0 4px; border-radius: 3px; background: var(--accent); color: white; font-size: 10px; font-weight: 600; line-height: 15px; vertical-align: 1px; }
.msg-actions { position: absolute; right: 16px; top: -16px; display: none; align-items: center; border: 1px solid rgba(0,0,0,.2); border-radius: 4px; background: var(--panel); box-shadow: 0 0 0 1px rgba(255,255,255,.04), var(--shadow); }
.message:hover .msg-actions { display: flex; }
.msg-actions button { width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; color: #b5bac1; cursor: pointer; }
.msg-actions button:hover { background: var(--hover); color: var(--text-2); }
.msg-actions button .ico { width: 20px; height: 20px; }
.empty-state { align-self: center; justify-self: center; max-width: 440px; padding: 30px; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 24px 0 8px; color: var(--text); font-size: 17px; font-weight: 600; }
.empty-state p { margin: 0; font-size: 15px; }
.empty-state small { display: block; margin-top: 6px; color: var(--faint); }
.messages .empty-state { margin: 80px auto 0; }
.empty-orbit { width: 96px; height: 96px; display: grid; place-items: center; margin: auto; border-radius: 50%; background: var(--side); color: var(--faint); }
.empty-orbit .ico { width: 56px; height: 56px; }

/* Composer */
.composer { padding: 0 16px 24px; }
.composer-box { display: flex; align-items: flex-start; padding: 0 0 0 16px; border-radius: 8px; background: var(--panel-2); }
.add-button { width: 24px; height: 24px; margin: 10px 16px 0 -6px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #b5bac1; color: var(--panel-2); cursor: pointer; }
.add-button .ico { width: 18px; height: 18px; }
.add-button:hover { background: var(--text-2); }
.add-button:disabled { cursor: default; opacity: .6; }
.composer textarea { flex: 1; min-height: 44px; max-height: 50vh; padding: 11px 0; resize: none; border: 0; outline: 0; color: var(--text-2); font-size: 16px; line-height: 22px; background: transparent; }
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:disabled { cursor: not-allowed; opacity: .55; }
.composer-tools { display: flex; align-items: center; gap: 2px; padding: 0 10px 0 6px; height: 44px; }
.composer-tools .tool { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 4px; background: transparent; color: #b5bac1; cursor: pointer; }
.composer-tools .tool:hover { color: var(--text-2); }
.composer-tools .tool:disabled { cursor: default; }
.composer-tools .gif { width: auto; padding: 0 4px; font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.composer-tools .send { color: var(--accent); }
.composer-tools .send:hover { color: #7983f5; }
.composer-tools .send:disabled { color: var(--faint); cursor: wait; }
#char-count { color: var(--muted); font-size: 12px; margin-right: 6px; }
#char-count.over { color: var(--danger); }
.send-state { height: 16px; margin: 6px 0 0; color: var(--muted); font-size: 12px; }

/* Misc */
.new-messages { position: absolute; left: 16px; right: 16px; top: 48px; z-index: 5; height: 24px; padding: 0 16px; border: 0; border-radius: 0 0 8px 8px; background: var(--accent); color: white; font-size: 14px; font-weight: 500; text-align: left; cursor: pointer; }
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.messages .spinner { margin: 0 auto; }
.nav-error { margin: 12px 0; padding: 12px; border-radius: 4px; color: var(--muted); font-size: 14px; background: var(--rail); }
.nav-error button, .retry-messages { display: inline-block; height: 32px; margin-top: 10px; padding: 0 16px; border: 0; border-radius: 3px; color: white; font-size: 14px; font-weight: 500; background: var(--accent); cursor: pointer; }
.nav-error button:hover, .retry-messages:hover { background: var(--accent-hover); }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 32px; transform: translateX(-50%); max-width: 420px; padding: 10px 16px; border-radius: 8px; background: #111214; color: var(--text-2); font-size: 14px; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.6); }

/* Responsive */
@media (max-width: 1100px) { .head-search { display: none; } }
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 72px minmax(0,1fr); }
  .sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; left: 72px; width: min(240px, calc(100vw - 72px)); transform: translateX(-130%); box-shadow: var(--shadow); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .chat-panel { grid-column: 2; }
  .mobile-menu { display: grid; }
  .chat-title-wrap p, .head-divider, .head-tools [data-tip]:disabled { display: none; }
  .message { padding-right: 16px; }
  .composer { padding: 0 8px 12px; }
}
@media (max-width: 480px) {
  .app-shell { grid-template-columns: 56px minmax(0,1fr); }
  .guild-rail { padding-top: 8px; }
  .rail-slot { width: 56px; }
  .rail-item { width: 40px; height: 40px; border-radius: 20px; }
  .rail-item:hover, .rail-item.active { border-radius: 12px; }
  .sidebar { left: 56px; width: calc(100vw - 56px); }
  .chat-head { padding-left: 8px; }
  .message { padding-left: 56px; }
  .message .avatar { left: 10px; width: 36px; height: 36px; }
  .message.cont .hover-time { display: none; }
  .composer-tools .tool:not(.send) { display: none; }
  .channel-intro h1 { font-size: 24px; }
}
