:root {
  --bg-rail: #1e1f22;
  --bg-sidebar: #2b2d31;
  --bg-main: #313338;
  --bg-members: #2b2d31;
  --bg-input: #383a40;
  --bg-float: #111214;
  --bg-modal: #313338;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #da373c;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --text-faint: #80848e;
  --text-bright: #f2f3f5;
  --divider: #26282c;
  --interactive: #b5bac1;
  --interactive-hover: #dbdee1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "gg sans", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 16px;
}

.hidden { display: none !important; }
button { font-family: inherit; }

/* Базовые SVG-иконки */
svg.ic { width: 20px; height: 20px; display: block; flex-shrink: 0; }

/* ---------- Экран входа ---------- */
.login {
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #2b2d31 0%, #1e1f22 100%);
}
.login-card {
  background: var(--bg-main);
  padding: 32px; border-radius: 8px; width: 420px; max-width: 92vw; text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.logo { font-size: 26px; font-weight: 700; letter-spacing: -.5px; color: var(--text-bright); }
.logo span { color: var(--accent); }
.tagline { color: var(--text-muted); font-size: 14px; margin: 8px 0 22px; line-height: 1.5; }
.login-card input, .field-input {
  width: 100%; padding: 10px 12px; border-radius: 4px; border: 1px solid #1e1f22;
  background: #1e1f22; color: var(--text-bright); font-size: 15px; outline: none; transition: border-color .15s;
}
.login-card input:focus, .field-input:focus { border-color: var(--accent); }
.login-card input + input { margin-top: 12px; }
.err { color: #fa777c; font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.login-btns { display: flex; gap: 8px; margin-top: 18px; }
.login-btns button { flex: 1; }
.login-card button.ghost { background: transparent; color: var(--text); text-decoration: underline; }
.login-card button.ghost:hover { background: transparent; color: var(--text-bright); }
.hint { color: var(--text-muted); font-size: 12px; text-align: left; margin-top: 12px; line-height: 1.45; }
.login-card button {
  width: 100%; margin-top: 16px; padding: 11px; border: none; border-radius: 4px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500; cursor: pointer; transition: background .15s;
}
.login-card button:hover { background: var(--accent-hover); }

.login-server-line {
  display: flex; align-items: center; gap: 8px; margin-top: 18px;
  padding: 9px 12px; border-radius: 4px; background: #1e1f22;
  font-size: 12px; color: var(--text-muted);
}
.server-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
#serverLineText { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
#changeServer { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0 2px; margin: 0; width: auto; transition: color .15s; }
#changeServer:hover { color: var(--text-bright); background: none; }

/* ---------- Оверлей подключения ---------- */
.conn-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-main);
  display: flex; align-items: center; justify-content: center;
}
.conn-card { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.conn-spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid #ffffff14; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.conn-title { font-size: 18px; font-weight: 600; color: var(--text-bright); }
.conn-sub { font-size: 14px; color: var(--text-muted); text-align: center; max-width: 280px; line-height: 1.5; }

/* ---------- Раскладка ---------- */
.app { display: flex; height: 100vh; }

.rail {
  width: 72px; background: var(--bg-rail); display: flex; flex-direction: column;
  align-items: center; padding: 12px 0; gap: 8px; overflow-y: auto;
}
.rail::-webkit-scrollbar { display: none; }
.rail-sep { width: 32px; height: 2px; background: #35363c; border-radius: 1px; flex-shrink: 0; }
.rail-home, .rail-add, .server-icon {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-sidebar); color: var(--text-bright); cursor: pointer; font-weight: 600; font-size: 17px;
  transition: border-radius .15s ease, background .15s ease; user-select: none; flex-shrink: 0; position: relative;
}
.rail-home:hover, .rail-add:hover, .server-icon:hover { border-radius: 16px; background: var(--accent); color: #fff; }
.rail-home.active, .server-icon.active { border-radius: 16px; background: var(--accent); color: #fff; }
/* индикатор активного слева (как в Discord) */
.rail-home::before, .server-icon::before {
  content: ''; position: absolute; left: -12px; width: 4px; height: 0; background: #fff;
  border-radius: 0 4px 4px 0; transition: height .15s ease;
}
.rail-home.active::before, .server-icon.active::before { height: 36px; }
.rail-home:hover::before, .server-icon:hover::before { height: 18px; }
.rail-add { color: var(--green); font-size: 24px; }
.rail-servers { display: flex; flex-direction: column; gap: 8px; }

.sidebar { width: 240px; background: var(--bg-sidebar); display: flex; flex-direction: column; }
.server-header {
  padding: 0 16px; height: 48px; font-weight: 600; font-size: 15px; color: var(--text-bright);
  box-shadow: 0 1px 0 rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.06); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.server-header:hover { background: #35373c; }

.channels { flex: 1; overflow-y: auto; padding: 8px 8px; }
.channel-group-label {
  font-size: 12px; text-transform: uppercase; color: var(--text-muted);
  padding: 16px 8px 4px; font-weight: 600; letter-spacing: .02em;
  display: flex; justify-content: space-between; align-items: center;
}
.channel-group-label .add-ch { cursor: pointer; font-size: 16px; }
.channel-group-label .add-ch:hover { color: var(--text-bright); }
.channel {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px;
  color: var(--text-muted); cursor: pointer; font-size: 16px; font-weight: 500; margin: 1px 0; position: relative;
}
.channel:hover { background: rgba(78,80,88,.3); color: var(--interactive-hover); }
.channel.active { background: rgba(78,80,88,.6); color: var(--text-bright); }
.channel.unread { color: var(--text-bright); }
.channel.unread::before { content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%); width: 8px; height: 8px; background: var(--text-bright); border-radius: 50%; }
.channel .ch-icon { opacity: .8; font-size: 18px; width: 20px; text-align: center; color: var(--text-faint); display: flex; align-items: center; justify-content: center; }
.channel .ch-icon svg { width: 20px; height: 20px; }
.channel .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .badge {
  background: var(--red); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 8px; padding: 0 5px; min-width: 16px; height: 16px; line-height: 16px; text-align: center;
}
.server-icon .badge { position: absolute; }
.voice-members { padding: 0 8px 4px 28px; }
.voice-member { font-size: 15px; color: var(--text-muted); padding: 3px 0; display: flex; align-items: center; gap: 8px; }
.voice-member .vm-av { width: 24px; height: 24px; font-size: 11px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; overflow: hidden; }
.voice-member.speaking .vm-av { box-shadow: 0 0 0 2px var(--green); }

.voice-bar {
  background: #232428; padding: 8px; display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.voice-status { display: flex; align-items: center; gap: 8px; min-width: 0; }
.voice-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; box-shadow: 0 0 6px var(--green); }
.voice-connected { color: var(--green); font-size: 12px; font-weight: 700; }
.voice-channel { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.user-bar { background: #232428; padding: 8px; display: flex; align-items: center; gap: 6px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 14px; flex-shrink: 0; cursor: pointer; background-size: cover; overflow: hidden;
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: var(--text-bright); font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-tag { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mic-btn { background: none; border: none; color: var(--interactive); cursor: pointer; padding: 6px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.mic-btn:hover { background: rgba(78,80,88,.3); color: var(--interactive-hover); }
.mic-btn svg { width: 20px; height: 20px; }
/* переключение иконок микрофона/звука по состоянию */
.mic-btn .ic-off { display: none; }
.mic-btn.muted { color: #f23f43; }
.mic-btn.muted .ic-on { display: none; }
.mic-btn.muted .ic-off { display: block; }
.mic-btn.active-off { color: #f23f43; }
.mic-btn.active-off .ic-on { display: none; }
.mic-btn.active-off .ic-off { display: block; }

.main { flex: 1; display: flex; flex-direction: column; background: var(--bg-main); min-width: 0; }
.topbar {
  height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.06); flex-shrink: 0; z-index: 2;
}
.hash { color: var(--text-faint); display: flex; align-items: center; }
.hash svg { width: 22px; height: 22px; }
.channel-title { color: var(--text-bright); font-weight: 600; font-size: 16px; }
.channel-topic { color: var(--text-muted); font-size: 13px; border-left: 1px solid #3f4147; padding-left: 10px; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-sep { flex: 1; }
.icon-btn { background: none; border: none; color: var(--interactive); cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.icon-btn:hover { color: var(--interactive-hover); }
.icon-btn svg { width: 22px; height: 22px; }
.net-badge { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.messages { flex: 1; overflow-y: auto; padding: 16px 16px 0; display: flex; flex-direction: column; }
.msg { display: flex; gap: 16px; padding: 2px 16px 2px 16px; margin: 0 -16px; position: relative; }
.msg:hover { background: rgba(2,2,2,.06); }
.msg.grouped { padding-top: 0; padding-bottom: 0; margin-top: 1px; }
.msg .avatar { width: 40px; height: 40px; font-size: 16px; cursor: pointer; margin-top: 2px; }
.msg.grouped .avatar { visibility: hidden; height: 0; margin: 0; }
.msg.grouped .msg-head { display: none; }
.msg-gutter { width: 40px; flex-shrink: 0; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 500; font-size: 16px; cursor: pointer; }
.msg-author:hover { text-decoration: underline; }
.msg-time { font-size: 12px; color: var(--text-faint); font-weight: 500; }
.msg-edited { font-size: 10px; color: var(--text-faint); }
.msg-text { color: var(--text); word-wrap: break-word; white-space: pre-wrap; line-height: 1.375; font-size: 16px; }
.msg-text a { color: #00a8fc; text-decoration: none; }
.msg-text a:hover { text-decoration: underline; }
.msg-text code { background: #2b2d31; padding: .1em .3em; border-radius: 4px; font-family: Consolas, "Courier New", monospace; font-size: 85%; }
.msg-text pre { background: #2b2d31; border: 1px solid #1f2023; padding: 8px; border-radius: 4px; overflow-x: auto; margin: 4px 0; }
.msg-text pre code { background: none; padding: 0; }
.mention { background: rgba(88,101,242,.3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }

.reply-ref { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-muted); margin-bottom: 2px; }
.reply-ref::before { content: ''; width: 28px; height: 10px; border-left: 2px solid #4e5058; border-top: 2px solid #4e5058; border-radius: 6px 0 0 0; margin-left: 18px; align-self: flex-end; }
.reply-ref b { color: var(--text); font-weight: 500; }

.attach-img { max-width: 400px; max-height: 320px; border-radius: 8px; margin-top: 6px; display: block; cursor: pointer; }
.attach-file {
  display: inline-flex; align-items: center; gap: 8px; background: #2b2d31; border: 1px solid #1f2023;
  border-radius: 8px; padding: 10px 14px; margin-top: 6px; color: var(--text); text-decoration: none;
}
.attach-file:hover { border-color: var(--accent); }
.attach-file .fi { font-size: 22px; }
.attach-file .fmeta small { color: var(--text-muted); display: block; }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.reaction {
  display: flex; align-items: center; gap: 6px; background: #2b2d31; border: 1px solid transparent;
  border-radius: 8px; padding: 1px 8px; font-size: 14px; cursor: pointer; min-height: 24px;
}
.reaction:hover { border-color: #4e5058; }
.reaction.mine { background: rgba(88,101,242,.15); border-color: var(--accent); }
.reaction .rc { color: var(--text-muted); font-weight: 600; font-size: 13px; }
.reaction.mine .rc { color: #c9cdfb; }

.msg-actions {
  position: absolute; top: -16px; right: 16px; background: var(--bg-main); border: 1px solid rgba(0,0,0,.2);
  border-radius: 6px; display: none; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.msg:hover .msg-actions { display: flex; }
.msg-actions button { background: none; border: none; color: var(--interactive); cursor: pointer; padding: 6px; display: flex; align-items: center; }
.msg-actions button:hover { color: var(--interactive-hover); }
.msg-actions button.danger:hover { color: #f23f43; }
.msg-actions svg { width: 18px; height: 18px; }

.reply-bar {
  margin: 0 16px -1px; background: #2b2d31; padding: 7px 12px; border-radius: 8px 8px 0 0;
  display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-muted);
}
.reply-bar button { background: none; border: none; color: var(--text-muted); cursor: pointer; }

.composer { padding: 0 16px 24px; }
.composer-box {
  display: flex; align-items: flex-end; gap: 4px; background: var(--bg-input);
  border-radius: 8px; padding: 0 8px;
}
.composer textarea {
  flex: 1; resize: none; max-height: 200px; min-height: 44px; line-height: 1.375; padding: 11px 4px;
  overflow-y: auto; background: transparent; border: none; outline: none; color: var(--text-bright); font-size: 16px;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-btn { background: none; border: none; color: var(--interactive); cursor: pointer; padding: 10px 6px; display: flex; align-items: center; }
.composer-btn:hover { color: var(--interactive-hover); }
.composer-btn svg { width: 24px; height: 24px; }
.composer-send { background: none; border: none; color: var(--interactive); cursor: pointer; padding: 10px 6px; display: flex; align-items: center; }
.composer-send svg { width: 24px; height: 24px; }
.composer-send:hover { color: var(--accent); }
.composer-send:disabled { opacity: .4; cursor: default; }
.composer-send:disabled:hover { color: var(--interactive); }

.members { width: 240px; background: var(--bg-members); padding: 16px 8px; overflow-y: auto; }
.members-title { font-size: 12px; text-transform: uppercase; color: var(--text-muted); font-weight: 600; padding: 0 8px 8px; letter-spacing: .02em; }
.member-list { display: flex; flex-direction: column; gap: 2px; }
.member { display: flex; align-items: center; gap: 12px; padding: 5px 8px; border-radius: 4px; cursor: pointer; }
.member:hover { background: rgba(78,80,88,.3); }
.member .av-wrap { position: relative; }
.member .avatar { width: 32px; height: 32px; font-size: 13px; }
.member-name { color: var(--text-muted); font-size: 16px; font-weight: 500; }
.member:hover .member-name { color: var(--interactive-hover); }
.member.me .member-name { color: var(--text-bright); }
.member .status-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--green);
  border: 3px solid var(--bg-members); position: absolute; bottom: -2px; right: -2px;
}
.member:hover .status-dot { border-color: #313338; }
.member .status-dot.offline { background: #80848e; }
.member .status-dot.idle { background: var(--yellow); }
.member .status-dot.dnd { background: var(--red); }
.member .mcustom { font-size: 12px; color: var(--text-muted); }

/* ---------- Слои ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--bg-modal); width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.modal-head { padding: 16px; font-size: 20px; font-weight: 600; color: var(--text-bright); display: flex; justify-content: space-between; align-items: center; }
.modal-head .x { cursor: pointer; color: var(--text-muted); font-size: 20px; }
.modal-head .x:hover { color: var(--text-bright); }
.modal-body { padding: 0 16px 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; text-transform: uppercase; color: #b5bac1; font-weight: 700; margin-bottom: 8px; letter-spacing: .02em; }
.field-input { width: 100%; }
select.field-input { appearance: none; cursor: pointer; }
.btn { padding: 10px 16px; border: none; border-radius: 4px; background: var(--accent); color: #fff; font-weight: 500; font-size: 14px; cursor: pointer; transition: background .15s; }
.btn:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #a12d2f; }
.btn-ghost { background: transparent; border: 1px solid #4e5058; color: var(--text); }
.btn-ghost:hover { background: rgba(78,80,88,.3); }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-chip { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.color-chip.sel { border-color: #fff; }

.popover { position: fixed; z-index: 60; background: var(--bg-float); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); padding: 8px; }
.profile-card { width: 300px; padding: 0; overflow: hidden; }
.profile-banner { height: 60px; }
.profile-inner { padding: 0 16px 16px; margin-top: -38px; }
.profile-card .avatar { width: 80px; height: 80px; font-size: 32px; border: 6px solid var(--bg-float); cursor: default; }
.profile-name { color: var(--text-bright); font-size: 20px; font-weight: 700; margin-top: 8px; }
.profile-status { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.profile-actions { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.profile-actions .btn { width: 100%; padding: 8px; font-size: 14px; }

/* Добавление в друзья */
.add-friend-row { display: flex; gap: 8px; padding: 8px 8px 4px; }
.add-friend-row input {
  flex: 1; padding: 8px 10px; border-radius: 4px; border: 1px solid #1e1f22;
  background: #1e1f22; color: var(--text-bright); font-size: 14px; outline: none;
}
.add-friend-row input:focus { border-color: var(--accent); }
.add-friend-row input::placeholder { color: var(--text-faint); }
.add-friend-row button {
  width: 36px; height: 36px; border: none; border-radius: 4px;
  background: var(--accent); color: #fff; font-size: 22px; line-height: 1;
  cursor: pointer; font-weight: 400; flex-shrink: 0; transition: background .15s;
}
.add-friend-row button:hover { background: var(--accent-hover); }

.friend-req { pointer-events: auto; }
.fr-btn {
  border: none; border-radius: 50%; width: 26px; height: 26px; font-size: 13px;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: background .15s; margin-left: 2px; background: #2b2d31; color: var(--text);
}
.fr-btn.ok:hover { background: var(--green); color: #fff; }
.fr-btn.no:hover { background: var(--red); color: #fff; }

/* Тост-уведомление */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111214; color: var(--text-bright); padding: 12px 20px;
  border-radius: 8px; font-size: 14px; font-weight: 500; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.emoji-picker { width: 320px; height: 300px; overflow-y: auto; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-picker .em { font-size: 22px; text-align: center; padding: 4px; cursor: pointer; border-radius: 4px; }
.emoji-picker .em:hover { background: #393c41; }

.ctxmenu { position: fixed; z-index: 70; background: var(--bg-float); border-radius: 4px; padding: 6px 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); min-width: 188px; }
.ctxmenu .item { padding: 8px; border-radius: 2px; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; }
.ctxmenu .item:hover { background: var(--accent); color: #fff; }
.ctxmenu .item.danger { color: #f23f43; }
.ctxmenu .item.danger:hover { background: var(--red); color: #fff; }
.ctxmenu .sep { height: 1px; background: var(--divider); margin: 4px 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #131416; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 820px) {
  .members { display: none; }
  .sidebar { width: 200px; }
}
