:root {
  --bg: #0f1115;
  --bg2: #151922;
  --bg3: #1d2330;
  --panel: rgba(21, 25, 34, 0.95);
  --text: #e8ecf4;
  --muted: #aab4c8;
  --accent: #5865f2;
  --danger: #e0564a;
  --success: #31d07f;
  --warn: #f5c451;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 12px 34px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #1b2234, var(--bg) 55%);
}
button, input, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.compact-col { display: grid; gap: 6px; place-items: center; }

.screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(520px, 96vw);
  background: rgba(23, 27, 36, .96);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 8px 0; font-size: 24px; }
.brand { font-weight: 800; letter-spacing: .4px; }
.tabs { display: flex; gap: 8px; margin: 14px 0; }
.tab, .btn, .mini-btn, .icon-btn {
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
}
.tab {
  flex: 1;
  border-radius: 10px;
  padding: 10px 12px;
}
.tab.active { background: rgba(88,101,242,.18); border-color: rgba(88,101,242,.35); }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.form input, textarea {
  background: #10141b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.form input:focus, textarea:focus { outline: 2px solid rgba(88,101,242,.38); border-color: transparent; }
.btn {
  border-radius: 10px;
  padding: 9px 12px;
}
.btn.primary { background: var(--accent); border-color: transparent; font-weight: 700; }
.btn:hover, .tab:hover, .mini-btn:hover, .icon-btn:hover { filter: brightness(1.07); }

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 88px 320px 1fr;
}
.servers-panel {
  background: rgba(15,17,21,.96);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  gap: 10px;
}
.logo, .server {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 16px;
  color: #fff;
  border: 1px solid var(--border);
  background: var(--bg3);
}
.logo { background: linear-gradient(135deg, var(--accent), #8b4cff); font-weight: 800; }
.server { cursor: pointer; position: relative; }
.server.active { border-color: rgba(88,101,242,.45); background: rgba(88,101,242,.16); }
.server-list { display: grid; gap: 10px; width: 100%; place-items: center; }
.server.logout { margin-top: auto; }
.server-toolbar { width: 100%; }
.mini-btn {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; padding: 0;
}
.mini-btn.danger { background: rgba(224,86,74,.18); border-color: rgba(224,86,74,.28); }

.channels-panel {
  background: rgba(20,24,33,.96);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto 1fr 1fr auto;
  min-height: 0;
}
.panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.01);
}
.channel-section {
  padding: 10px 10px 0;
  min-height: 0;
  overflow: auto;
}
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.section-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: .5px;
}
.channel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.channel-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
}
.channel-main {
  width: 100%; text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.channel-main:hover { background: rgba(255,255,255,.04); }
.channel-main.active { background: rgba(88,101,242,.16); border-color: rgba(88,101,242,.25); }
.channel-title-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.channel-meta { color: var(--muted); font-size: 11px; }
.channel-actions { display: flex; gap: 4px; }
.channel-actions .mini-btn { width: 24px; height: 24px; border-radius: 7px; }

.self-card {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: grid;
  grid-template-columns: 38px 1fr repeat(4, 32px);
  gap: 6px;
  align-items: center;
  background: rgba(0,0,0,.14);
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #5865f2, #00c2ff);
  font-weight: 700;
}
.self-meta { min-width: 0; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  padding: 0;
}
.icon-btn.active { background: rgba(88,101,242,.22); border-color: rgba(88,101,242,.45); }
.icon-btn.danger { background: rgba(224,86,74,.2); border-color: rgba(224,86,74,.35); }
.icon-btn.warn { background: rgba(245,196,81,.18); border-color: rgba(245,196,81,.25); }

.main-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 100vh;
}
.main-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}
.card {
  background: rgba(23,27,36,.9);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.chat-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 100px);
}
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.chat-head h3 { margin: 0; font-size: 16px; }
.messages {
  border: 1px solid rgba(255,255,255,.04);
  border-radius: 12px;
  background: rgba(255,255,255,.01);
  padding: 10px;
  overflow: auto;
  min-height: 320px;
  display: grid;
  align-content: start;
  gap: 8px;
}
.message {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
}
.message:hover { background: rgba(255,255,255,.02); }
.message .avatar-sm {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(88,101,242,.22);
  border: 1px solid rgba(88,101,242,.25);
  font-weight: 700;
}
.message-top { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.message-name { font-weight: 700; }
.message-time { color: var(--muted); font-size: 12px; }
.message-body { white-space: pre-wrap; line-height: 1.35; word-break: break-word; }
.message.mine .avatar-sm { background: rgba(49,208,127,.18); border-color: rgba(49,208,127,.22); }
.message-empty {
  color: var(--muted); text-align: center; padding: 18px 10px;
  border: 1px dashed rgba(255,255,255,.08); border-radius: 10px;
}
.chat-form { display: grid; gap: 8px; margin-top: 10px; }
.chat-form textarea { resize: vertical; min-height: 56px; max-height: 180px; }
.chat-form-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-cards { display: grid; gap: 12px; align-content: start; max-height: calc(100vh - 100px); overflow: auto; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed rgba(255,255,255,.05); }
.kv span { color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li {
  border: 1px solid rgba(255,255,255,.05);
  background: rgba(255,255,255,.02);
  border-radius: 10px;
  padding: 9px 10px;
}
.list li .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 3px 8px; border-radius: 999px; font-size: 12px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
}
.badge.success { background: rgba(49,208,127,.13); border-color: rgba(49,208,127,.2); }
.badge.warn { background: rgba(224,86,74,.14); border-color: rgba(224,86,74,.22); }
.badge.speaking { background: rgba(245,196,81,.14); border-color: rgba(245,196,81,.22); }
.badge.online { background: rgba(49,208,127,.12); border-color: rgba(49,208,127,.18); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #7a8599; display: inline-block; }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(49,208,127,.13); }
.status-dot.speaking { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,196,81,.14); }

.toast {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  background: rgba(23,27,36,.98); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  box-shadow: var(--shadow); border-radius: 12px; padding: 12px 14px; max-width: min(380px, 92vw);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent); }

@media (max-width: 1220px) {
  .layout { grid-template-columns: 78px 290px 1fr; }
  .main-grid { grid-template-columns: 1fr; }
  .side-cards { max-height: none; overflow: visible; }
  .chat-card { min-height: 520px; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .servers-panel, .channels-panel { display: none; }
  .main-panel { min-height: 100vh; }
  .main-grid { padding: 10px; }
}

.btn:disabled, .mini-btn:disabled, .icon-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.status-dot.idle { background: #f5c451; box-shadow: 0 0 0 3px rgba(245,196,81,.14); }
.status-dot.dnd { background: #ef5350; box-shadow: 0 0 0 3px rgba(239,83,80,.15); }
.status-dot.invisible { background: #6b7280; }
