/* ATRIUM — ночной атриум: тёплый камень, бронза, гравировка */
:root {
  --bg: #0c0b09;
  --panel: #131110;
  --panel-2: #1a1715;
  --line: rgba(214, 178, 116, 0.10);
  --line-strong: rgba(214, 178, 116, 0.22);
  --ink: #e9e2d4;
  --muted: #8f8674;
  --accent: #d6a85a;
  --accent-ink: #16130d;
  --olive: #86a37e;
  --danger: #c96f5a;
  --bubble-in: #1c1916;
  --bubble-mine: rgba(214, 168, 90, 0.13);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(1200px 800px at 70% -10%, rgba(214, 168, 90, 0.05), transparent 60%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
h4 { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.2em; color: var(--muted); margin: 10px 0 8px; }
code { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }
.hidden-input { display: none; }

/* ---- марка ---- */
.brand-mark, .boot-mark, .chat-empty-mark {
  width: 44px; height: 44px;
  border: 1px solid var(--accent);
  position: relative;
  margin: 0 auto;
}
.brand-mark::before, .boot-mark::before, .chat-empty-mark::before {
  content: ""; position: absolute; inset: 8px;
  border: 1px solid var(--line-strong);
}
.brand-mark::after, .boot-mark::after, .chat-empty-mark::after {
  content: ""; position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%);
  width: 12px; height: 10px; background: var(--bg);
  border-left: 1px solid var(--accent); border-right: 1px solid var(--accent);
}

/* ---- загрузка ---- */
.boot {
  height: 100%; display: flex; flex-direction: column; gap: 18px;
  align-items: center; justify-content: center;
}
.boot-text {
  font-family: var(--mono); letter-spacing: 0.45em; text-indent: 0.45em;
  font-size: 13px; color: var(--muted);
  animation: bootpulse 1.6s ease-in-out infinite;
}
@keyframes bootpulse { 50% { opacity: 0.4; } }

/* ---- auth ---- */
.auth-wrap {
  height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px;
  overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 36px 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { text-align: center; margin-bottom: 10px; display: flex; flex-direction: column; gap: 12px; }
.brand-name {
  font-family: var(--mono); font-size: 20px; font-weight: 500;
  letter-spacing: 0.45em; text-indent: 0.45em; color: var(--ink);
}
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.auth-card h2 { font-size: 16px; font-weight: 600; text-align: center; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--muted);
}
.field input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; color: var(--ink); width: 100%;
}
.field input:focus { border-color: var(--accent); outline: none; }

.btn {
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 10px 14px; font-size: 14px; text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.danger { color: var(--danger); border-color: rgba(201, 111, 90, 0.35); }
.btn.danger:hover { border-color: var(--danger); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 130px; }
.auth-error { display: none; color: var(--danger); font-size: 13px; }
.auth-error.show { display: block; }
.fatal { padding: 40px; text-align: center; color: var(--danger); }

/* ---- каркас ---- */
.layout { display: flex; height: 100%; }
.sidebar {
  width: 320px; min-width: 260px; flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column;
}
.chatpane { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.side-brand {
  font-family: var(--mono); font-size: 13px; letter-spacing: 0.4em; text-indent: 0.4em;
  color: var(--accent);
}
.side-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 15px; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

.chat-list { flex: 1; overflow-y: auto; padding: 6px; }
.chat-item {
  display: flex; gap: 10px; align-items: center; padding: 9px 10px;
  border-radius: 10px; cursor: pointer; transition: background 0.12s;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--bubble-mine); }
.chat-item-mid { flex: 1; min-width: 0; }
.chat-item-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chat-item-time { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.badge {
  min-width: 19px; height: 19px; border-radius: 10px; background: var(--accent);
  color: var(--accent-ink); font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.empty-hint { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 6px; }

.side-foot {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.side-me { flex: 1; min-width: 0; }
.side-me-name { font-size: 13.5px; font-weight: 600; }
.side-me-user { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); transition: background 0.3s; }
.ws-dot.up { background: var(--olive); }

/* ---- аватарки ---- */
.avatar {
  border-radius: 10px; overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.85); font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 26px; height: 26px; font-size: 10px; border-radius: 7px; }
.avatar-sm { width: 34px; height: 34px; font-size: 12px; }
.avatar-md { width: 44px; height: 44px; font-size: 15px; }
.avatar-lg { width: 72px; height: 72px; font-size: 24px; border-radius: 16px; }
.avatar-group span { font-size: 19px; color: var(--accent); }
.chat-item-av { position: relative; }
.chat-item-av.online::after {
  content: ""; position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--olive); border: 2px solid var(--panel);
}

/* ---- чат ---- */
.chat-empty {
  flex: 1; display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center; color: var(--muted); font-size: 14px;
}
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: rgba(19, 17, 16, 0.8); backdrop-filter: blur(10px);
}
.back-btn { display: none; font-size: 22px; }
.chat-head-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-head-title { font-weight: 600; font-size: 15px; }
.chat-head-sub { font-size: 12px; color: var(--muted); }
.chat-head-sub .typing { color: var(--accent); }
.chat-head-actions { display: flex; gap: 2px; }

.chat-scroll {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 3px;
  overscroll-behavior: contain;
}
.chat-begin { text-align: center; color: var(--muted); font-size: 12.5px; padding: 30px 20px; }
.day-sep { text-align: center; margin: 14px 0 8px; }
.day-sep span {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.15em;
  color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 20px;
}

.msg-row { display: flex; gap: 8px; align-items: flex-end; animation: msgin 0.14s ease-out; }
.msg-row.mine { justify-content: flex-end; }
@keyframes msgin { from { opacity: 0; transform: translateY(4px); } }
.msg-av { flex-shrink: 0; }
.bubble {
  max-width: min(62ch, 78%);
  background: var(--bubble-in);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 7px 11px 5px;
  position: relative;
  font-size: 14.5px;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.msg-row.mine .bubble {
  background: var(--bubble-mine);
  border-color: rgba(214, 168, 90, 0.2);
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: 4px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 0 100%, 0 10px);
}
.bubble-author { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-deleted, .bubble-locked { color: var(--muted); font-style: italic; font-size: 13px; }
.bubble-meta {
  display: flex; gap: 5px; justify-content: flex-end; align-items: center;
  font-family: var(--mono); font-size: 9.5px; color: var(--muted); margin-top: 3px;
}
.ticks { letter-spacing: -0.08em; }
.ticks.read { color: var(--accent); }
.edited { font-style: italic; }

.quote {
  border-left: 2px solid var(--accent); padding: 2px 8px; margin-bottom: 5px;
  background: rgba(214, 168, 90, 0.06); border-radius: 4px; font-size: 12.5px;
}
.quote-author { color: var(--accent); font-weight: 600; font-size: 11.5px; }
.quote-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }

.bubble-img {
  max-width: 100%; width: 360px; border-radius: 8px; display: block;
  cursor: zoom-in; background: var(--panel-2); margin: 2px 0;
}
.file-chip {
  display: flex; gap: 10px; align-items: center; cursor: pointer;
  padding: 6px 4px; border-radius: 8px; min-width: 180px;
}
.file-chip:hover { background: rgba(255, 255, 255, 0.03); }
.file-ico { font-size: 22px; }
.file-meta { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 4px 0; }
.voice-play {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  color: var(--accent-ink); font-size: 13px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.voice-bar { flex: 1; height: 3px; border-radius: 2px; background: var(--line-strong); overflow: hidden; }
.voice-fill { height: 100%; width: 0; background: var(--accent); }
.voice-time { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.react-chip {
  font-size: 12px; padding: 2px 7px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.react-chip.my { border-color: var(--accent); background: var(--bubble-mine); }

/* ---- композер ---- */
.composer-holder { border-top: 1px solid var(--line); background: var(--panel); }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 10px 12px; }
.composer textarea {
  flex: 1; resize: none; background: var(--bg); border: 1px solid var(--line);
  border-radius: 18px; padding: 9px 14px; max-height: 160px; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); outline: none; }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: var(--accent-ink); font-size: 15px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: filter 0.15s;
}
.send-btn:hover { filter: brightness(1.1); }
.composer .icon-btn { width: 36px; height: 36px; }
.voice-btn.recording { color: var(--danger); animation: recpulse 1s infinite; }
@keyframes recpulse { 50% { opacity: 0.5; } }
.composer-bar:not(:empty) { padding: 8px 14px 0; }
.bar-chip {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}
.bar-chip.rec { color: var(--ink); }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: recpulse 1s infinite; }
.chatpane.dragging::after {
  content: "Отпусти, чтобы отправить"; position: absolute; inset: 10px;
  border: 2px dashed var(--accent); border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 11, 9, 0.85); font-size: 15px; color: var(--accent); z-index: 5;
  pointer-events: none;
}

/* ---- модалки ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5, 4, 3, 0.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 14px; animation: modalin 0.16s ease-out;
}
@keyframes modalin { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 0;
}
.modal-head h3 { font-size: 16px; }
.modal-head h3:empty { display: none; }
.modal-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.menu-modal { max-width: 320px; }

.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; }
.seg-btn { flex: 1; padding: 8px; font-size: 13.5px; color: var(--muted); }
.seg-btn.active { background: var(--bubble-mine); color: var(--ink); }

.user-pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; }
.user-pick {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer;
}
.user-pick:hover { background: var(--panel-2); }
.user-pick.picked { background: var(--bubble-mine); }
.user-pick-name { flex: 1; font-size: 14px; }
.user-pick-check { color: var(--accent); font-weight: 700; width: 18px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.member-name { flex: 1; font-size: 14px; }

.invite-list { display: flex; flex-direction: column; gap: 6px; }
.invite-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.invite-fresh { text-align: center; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.invite-code {
  font-family: var(--mono); font-size: 22px; letter-spacing: 0.08em; color: var(--accent);
}
.settings-me { display: flex; align-items: center; gap: 14px; }
.safety-row { display: flex; flex-direction: column; gap: 3px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.safety-name { font-weight: 600; font-size: 13.5px; }
.safety-code { font-size: 12.5px; color: var(--muted); letter-spacing: 0.05em; }

.emoji-row { display: flex; gap: 2px; justify-content: space-between; }
.emoji-btn { font-size: 22px; padding: 6px; border-radius: 8px; }
.emoji-btn:hover { background: var(--panel-2); }
.menu-list { display: flex; flex-direction: column; }
.menu-item { text-align: left; padding: 10px 12px; border-radius: 8px; font-size: 14.5px; }
.menu-item:hover { background: var(--panel-2); }
.menu-item.danger { color: var(--danger); }

/* ---- звонок ---- */
.call-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 7, 5, 0.96);
  display: flex; flex-direction: column;
}
.call-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; }
.call-stage video#call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.call-peer { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.call-peer-name { font-size: 20px; font-weight: 600; }
.call-state { font-family: var(--mono); font-size: 13px; color: var(--muted); letter-spacing: 0.1em; }
.call-pip {
  position: absolute; right: 16px; top: 16px; width: 130px; border-radius: 10px;
  border: 1px solid var(--line-strong); z-index: 3; background: var(--panel);
}
.call-controls { display: flex; gap: 18px; justify-content: center; padding: 26px 0 40px; }
.call-btn {
  width: 58px; height: 58px; border-radius: 50%; font-size: 22px;
  background: var(--panel-2); border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s, background 0.15s;
}
.call-btn:hover { transform: scale(1.06); }
.call-btn.off { background: var(--bg); color: var(--muted); }
.call-btn.accept { background: var(--olive); color: #10130e; border: 0; }
.call-btn.reject { background: var(--danger); color: #170b08; border: 0; }

/* ---- лайтбокс, тосты ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(5, 4, 3, 0.92);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 6px; }
.toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 200; align-items: center;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--ink);
  padding: 9px 16px; border-radius: 10px; font-size: 13.5px; max-width: 90vw;
  animation: msgin 0.15s ease-out; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.toast-warn { border-color: rgba(201, 111, 90, 0.5); }
.toast.out { opacity: 0; transition: opacity 0.3s; }

body.ws-down .chatpane::before {
  content: "переподключение…"; position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  text-align: center; font-family: var(--mono); font-size: 10px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--accent-ink); background: var(--accent); padding: 3px;
}

/* ---- мобильный ---- */
@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: 0; }
  .chatpane { position: fixed; inset: 0; background: var(--bg); z-index: 10; transform: translateX(100%); transition: transform 0.2s ease-out; }
  body.chat-open .chatpane { transform: none; }
  .back-btn { display: inline-flex; }
  .bubble { max-width: 84%; }
  .call-pip { width: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
