:root {
  --bg-chat: #313338;
  --bg-side: #2b2d31;
  --bg-dark: #1e1f22;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #f23f43;
  --ok: #23a55a;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-chat);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

[hidden] { display: none !important; }

.boot {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; background: var(--bg-dark);
  color: var(--muted); font-size: 14px;
}
.boot img { border-radius: 18px; }
.boot[hidden] { display: none; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.4em; margin: 4px 0 8px; font-size: 13px; }

/* ---------- вход ---------- */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #4650c9 0%, transparent 60%), var(--bg-dark);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--bg-chat);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 26px; color: var(--text-strong); text-align: center; }
.auth-card p { text-align: center; margin: 0 0 16px; }
.auth-card .error { text-align: left; }

.auth-card label { display: block; margin-bottom: 14px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.auth-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg-dark); border: 1px solid transparent; border-radius: 6px;
  text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }

.tabs { display: flex; gap: 4px; background: var(--bg-dark); padding: 4px; border-radius: 8px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 6px; }
.tab.active { background: var(--bg-active); color: var(--text-strong); }

.btn { border: 0; border-radius: 6px; padding: 10px 16px; background: var(--bg-active); }
.btn.primary { background: var(--accent); color: #fff; width: 100%; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled { opacity: 0.6; cursor: default; }

/* ---------- каркас приложения ---------- */

#app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  height: 100vh;
  height: 100dvh;
}

.backdrop { display: none; }

.sidebar { background: var(--bg-side); display: flex; flex-direction: column; min-height: 0; }
.side-head {
  height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--bg-dark); color: var(--text-strong);
}
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--ok); }
.conn.off { background: var(--danger); }

.side-section {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 8px 4px 16px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}

.icon-btn {
  border: 0; background: transparent; color: var(--muted); width: 30px; height: 30px;
  border-radius: 6px; font-size: 16px; line-height: 1; padding: 0;
}
.icon-btn:hover { color: var(--text-strong); background: var(--bg-hover); }

.channels { flex: 1; overflow-y: auto; padding: 4px 8px; }
.channel {
  display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: transparent;
  text-align: left; padding: 6px 8px; border-radius: 6px; color: var(--muted); cursor: pointer;
}
.channel:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.channel .hash { opacity: 0.7; }
.channel .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel:hover { background: var(--bg-hover); color: var(--text); }
.channel.active { background: var(--bg-active); color: var(--text-strong); }
.channel.unread { color: var(--text-strong); font-weight: 600; }
.channel .badge {
  background: var(--danger); color: #fff; border-radius: 10px; min-width: 18px; height: 18px;
  padding: 0 5px; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.channel .del { display: none; width: 22px; height: 22px; font-size: 14px; }
.channel:hover .del { display: inline-block; }

.side-foot {
  display: flex; align-items: center; gap: 8px; padding: 8px; background: #232428; min-height: 52px;
}
.me-info { flex: 1; min-width: 0; }
.me-name { color: var(--text-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px; user-select: none;
}

/* ---------- чат ---------- */

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-chat); }
.chat-head {
  height: 48px; padding: 0 12px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--bg-dark); flex: none;
}
.chat-head .hash { color: var(--muted); font-size: 22px; }
.chat-head h2 { margin: 0; font-size: 16px; color: var(--text-strong); }
.menu-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; overscroll-behavior: contain; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; padding: 0 16px; }
.older { text-align: center; color: var(--muted); font-size: 12px; padding: 4px; }

.msg { display: flex; gap: 14px; padding: 2px 16px 2px 16px; }
.msg:hover { background: rgba(2, 2, 2, 0.06); }
.msg.first { margin-top: 14px; }
.msg .gutter { flex: none; width: 40px; }
.msg .avatar { width: 40px; height: 40px; font-size: 16px; }
.msg .body { min-width: 0; flex: 1; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 600; color: var(--text-strong); }
.msg time { color: var(--muted); font-size: 12px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text a { color: #00a8fc; text-decoration: none; }
.msg .text a:hover { text-decoration: underline; }

.composer { padding: 0 16px 16px; flex: none; }
.composer textarea {
  display: block; width: 100%; resize: none; max-height: 200px; padding: 11px 14px;
  background: #383a40; border: 0; border-radius: var(--radius); line-height: 1.35;
}
.composer textarea:focus { outline: none; }
.composer textarea:disabled { opacity: 0.6; }

/* ---------- участники ---------- */

.members { background: var(--bg-side); overflow-y: auto; padding: 8px; }
.members h3 {
  margin: 16px 8px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.member { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 6px; color: var(--muted); }
.member:hover { background: var(--bg-hover); }
.member.online { color: var(--text); }
.member.offline .avatar { opacity: 0.45; }
.member .avatar { position: relative; }
.member .dot {
  position: absolute; right: -3px; bottom: -3px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 3px var(--bg-side);
}
.member .tag { font-size: 10px; background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: auto; }

/* ---------- диалог и уведомление ---------- */

dialog {
  border: 0; border-radius: 12px; padding: 0; background: var(--bg-chat); color: var(--text);
  width: min(420px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { padding: 20px; }
dialog h3 { margin: 0 0 8px; color: var(--text-strong); }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog input {
  display: block; width: 100%; padding: 10px 12px; background: var(--bg-dark);
  border: 1px solid transparent; border-radius: 6px; margin-bottom: 16px;
}
dialog input:focus { outline: none; border-color: var(--accent); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog .actions .btn.primary { width: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #111214; color: var(--text-strong); padding: 10px 16px; border-radius: 8px;
  pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- адаптив ---------- */

@media (max-width: 1000px) {
  #app { grid-template-columns: 240px minmax(0, 1fr); }
  .members { display: none; }
}

@media (max-width: 700px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-block; }
  .sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 85vw);
    transform: translateX(-100%); transition: transform 0.2s;
  }
  body.sidebar-open .sidebar { transform: none; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 10; }
  body.sidebar-open .backdrop { display: block; }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .msg { gap: 10px; padding: 2px 12px; }
}
