:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1c232d;
  --line: #283039;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --danger: #e5534b;
  --ok: #3fb950;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #18222f 0%, var(--bg) 60%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* Верхняя панель сайта с вкладками */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 22px;
  background: rgba(13,17,23,.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.tabs { display: flex; gap: 6px; }
.tab {
  color: var(--muted); text-decoration: none;
  padding: 7px 14px; border-radius: 10px; font-size: 14px;
}
.tab:hover { background: var(--panel); color: var(--text); }
.tab.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.screen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.screen.hidden { display: none; }

/* Карточка входа */
.card {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.card h1 { margin: 0 0 8px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.card p { font-size: 13px; line-height: 1.5; margin: 0 0 18px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input[type=text], label input[type=password] {
  width: 100%; margin-top: 6px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 14px; outline: none;
}
label input:focus { border-color: var(--accent); }
input[type=color] { width: 52px; height: 34px; margin-top: 6px; padding: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; cursor: pointer; }
.hint { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.forget-btn { margin-top: 12px; width: 100%; }

button {
  cursor: pointer; border: none; border-radius: 10px; font-size: 14px;
  padding: 11px 14px; color: #fff; transition: transform .05s, background .15s;
}
button:active { transform: translateY(1px); }
.primary { background: var(--accent); width: 100%; font-weight: 600; }
.primary:hover { background: #3f7bef; }
.danger { background: var(--danger); }
.danger:hover { background: #cf463e; }
.ghost { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.ghost:hover { color: var(--text); }
.icon { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* Чат */
.chat-wrap {
  width: 100%; max-width: 860px; height: calc(100vh - 110px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel2);
  font-size: 14px;
}
.chat-actions { display: flex; align-items: center; gap: 10px; }
.chat-actions button { padding: 8px 12px; font-size: 13px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--danger); }

.head-left { display: flex; align-items: center; gap: 8px; }
.presence-sum { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); padding: 3px 9px; border-radius: 20px; }
.presence-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel2); min-height: 0; }
.presence-bar:empty { display: none; }
.pchip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; }
.pchip.off { opacity: .7; }
.pdot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.receipt { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.msg.me .receipt { text-align: right; }
#soundBtn.muted { opacity: .55; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 74%; display: flex; flex-direction: column; gap: 3px; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); padding: 0 4px; }
.msg .bubble {
  background: var(--panel2); border: 1px solid var(--line);
  padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap; border-left: 3px solid var(--accent);
}
.msg.me .bubble { border-left: none; border-right: 3px solid var(--accent); }
.msg .bubble img { max-width: 260px; max-height: 260px; border-radius: 10px; display: block; cursor: zoom-in; margin-top: 4px; }
.msg .author { font-weight: 600; }
.system { align-self: center; color: var(--muted); font-size: 12px; font-style: italic; padding: 4px; }

/* Композер */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--panel2); }
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 11px 12px; font-size: 14px; outline: none; font-family: inherit;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .icon, .composer .primary { width: 44px; height: 44px; padding: 0; font-size: 18px; flex: 0 0 auto; }

.attach-preview { padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel2); display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.attach-preview.hidden { display: none; }
.attach-preview img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }
.attach-preview button { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px var(--line); padding: 5px 9px; font-size: 12px; }

.hidden { display: none !important; }

/* Лайтбокс */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 50; cursor: zoom-out; padding: 30px; }
.lightbox img { max-width: 95%; max-height: 95%; border-radius: 10px; }

@media (max-width: 600px) {
  .chat-wrap { height: calc(100vh - 96px); border-radius: 0; border-left: none; border-right: none; }
  .tabs .tab:first-child, .tab:last-child { display: none; }
  .msg { max-width: 88%; }
}
