/* ==========================================================================
   chatbox — ретро-терминал, чёрно-белый.
   Цвет в интерфейсе есть ровно в одном месте: ники и звания. Всё остальное
   различается формой — рамками, инверсией, штриховкой, жирностью.
   ========================================================================== */

/* ---------- тёмная тема (по умолчанию) ---------- */

:root {
  --bg:        #0a0a0b;
  --surface:   #131313;   /* ВАЖНО: под этот цвет сервер считает контраст ников */
  --raised:    #1b1b1c;
  --hover:     #272729;
  --line:      #3c3c3f;
  --line-soft: #2a2a2c;
  --text:      #eaeaec;
  --muted:     #97979b;

  --accent:    #eaeaec;   /* «акцент» = инверсия: светлое на тёмном */
  --accent-ink:#0a0a0b;
  --accent-dim:#2a2a2c;

  --danger:    #f4f4f6;   /* самый светлый — всегда в паре с рамкой или инверсией */
  --warn:      #d5d5d8;
  --ok:        #b6b6ba;

  --shadow:    #000000;
  --hi:        #ffffff;   /* блик в эффектах ника */
  --ink-mix:   #111111;   /* к чему притемняются ники в светлой теме */

  --font-ui: 'Pixelify Sans', 'Handjet', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --sidebar-w: 268px;

  color-scheme: dark;
}

/* ---------- светлая тема ---------- */

:root[data-theme='light'] {
  --bg:        #dedede;
  --surface:   #f2f2f2;
  --raised:    #e8e8e8;
  --hover:     #d8d8d8;
  --line:      #9a9a9a;
  --line-soft: #bcbcbc;
  --text:      #121212;
  --muted:     #5e5e5e;

  --accent:    #121212;
  --accent-ink:#f2f2f2;
  --accent-dim:#cfcfcf;

  --danger:    #000000;
  --warn:      #1f1f1f;
  --ok:        #3a3a3a;

  --shadow:    #a8a8a8;
  --hi:        #101010;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font-ui);
  letter-spacing: 0.2px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }

a { color: var(--text); text-underline-offset: 3px; }
a:hover { text-decoration: none; }

::selection { background: var(--text); color: var(--bg); }

h1, h2, h3 { font-weight: 700; letter-spacing: 0.5px; }

/* ---------- скроллбары ---------- */

* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 12px; height: 12px; }
*::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--bg); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- экраны ---------- */

.screen { min-height: 100dvh; }

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

.boot { display: flex; align-items: center; gap: 8px; }
.boot-line { letter-spacing: 2px; }
.caret {
  display: inline-block;
  width: 10px;
  height: 18px;
  background: var(--text);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 0%, 49% { opacity: 1 } 50%, 100% { opacity: 0 } }

/* ---------- карточки ---------- */

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 24px;
}

.setup-card { max-width: 460px; }
.setup-card h1 { margin: 0; font-size: 20px; }

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.brand-dot {
  width: 12px;
  height: 12px;
  background: var(--text);
  flex: none;
  animation: blink 1.6s steps(1) infinite;
}

/* ---------- формы ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.form-inline .field { flex: 1 1 130px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.field > span em { font-style: normal; text-transform: none; opacity: 0.75; }

input[type='text'], input[type='email'], input[type='password'],
input[type='number'], input[type='search'], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--line);
  padding: 9px 11px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }
input:disabled, select:disabled, textarea:disabled, button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.code-input {
  font-family: var(--font-mono);
  font-size: 24px;
  letter-spacing: 10px;
  text-align: center;
}

.field-note { font-size: 12.5px; color: var(--muted); min-height: 1em; }
.field-note.is-error { color: var(--danger); font-weight: 700; }
.field-note.is-ok { color: var(--ok); }

.hint { margin: 0; font-size: 13.5px; color: var(--muted); }

.font-custom { display: flex; flex-direction: column; gap: 8px; }

/* ---------- кнопки ---------- */

.btn {
  background: var(--raised);
  border: 2px solid var(--line);
  padding: 9px 14px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 14px;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform 0.06s, box-shadow 0.06s, background 0.12s;
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(0.92); }

.btn-link {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--muted);
  padding: 2px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0.2px;
  text-decoration: underline;
}
.btn-link:hover { color: var(--text); background: none; }
.btn-link:active { transform: none; }

.btn-ghost {
  background: none;
  border: 2px solid transparent;
  box-shadow: none;
  color: var(--muted);
  text-align: left;
  padding: 6px 8px;
  font-size: 14px;
  display: block;
  width: 100%;
}
.btn-ghost:hover { background: var(--raised); color: var(--text); border-color: var(--line-soft); }
.btn-ghost:active { transform: none; }

/* Опасное действие отличается не цветом, а пунктиром. */
.btn-danger { border-style: dashed; border-color: var(--danger); color: var(--danger); font-weight: 700; }

.btn-sm { padding: 4px 8px; font-size: 12.5px; box-shadow: 2px 2px 0 var(--shadow); }
.btn-tiny { padding: 3px 7px; font-size: 11px; box-shadow: 2px 2px 0 var(--shadow); }

.icon-btn {
  background: none;
  border: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 1px;
  padding: 4px 7px;
}
.icon-btn:hover { background: var(--raised); color: var(--text); border-color: var(--line-soft); }

/* ---------- вкладки ---------- */

.tabs {
  display: flex;
  border: 2px solid var(--line);
  margin-bottom: 18px;
  background: var(--bg);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  border-right: 2px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.tab:last-child { border-right: none; }
.tab:hover { color: var(--text); background: var(--hover); }
.tab.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ---------- плашки ---------- */

.alert {
  border: 2px solid var(--line);
  background: var(--raised);
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 14px;
  white-space: pre-line;
}
/* Ошибка — инверсия: в чёрно-белом это единственный способ кричать. */
.alert.is-error {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 700;
}
.alert.is-error::before { content: '! '; }
.alert.is-ok { border-style: double; border-width: 4px; }
.alert.is-ok::before { content: 'OK '; font-weight: 700; }

.section-head {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  border-bottom: 2px solid var(--line-soft);
  padding-bottom: 5px;
}

/* ==========================================================================
   ники: цвет, звание, эффекты — единственное цветное пятно в интерфейсе
   ========================================================================== */

.nick-wrap { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; }

/* Цвет хранится один — подобранный под тёмный фон. В светлой теме его
   притемняем через color-mix: оттенок сохраняется, читаемость возвращается,
   и при переключении темы ничего не нужно перерисовывать. */
.tint { color: var(--nick, currentColor); }
:root[data-theme='light'] .tint { color: color-mix(in srgb, var(--nick) 58%, var(--ink-mix)); }

.nick { font-weight: 700; }

.nick-prefix {
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid currentColor;
  padding: 0 4px;
  flex: none;
}

.tag-admin {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border: 1px solid currentColor;
  padding: 0 3px;
  flex: none;
}

/* --- базовые эффекты --- */

.fx-pulse { animation: fx-pulse 1.8s ease-in-out infinite; }
@keyframes fx-pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.5 } }

.fx-flicker { animation: fx-flicker 3.4s steps(1) infinite; }
@keyframes fx-flicker {
  0%, 90%, 100% { opacity: 1 }
  91% { opacity: 0.35 }
  92% { opacity: 1 }
  95% { opacity: 0.2 }
  96% { opacity: 1 }
}

.fx-scan {
  color: transparent;
  background-image: linear-gradient(180deg, var(--nick) 0 42%, var(--hi) 46% 54%, var(--nick) 58% 100%);
  background-size: 100% 320%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: fx-scan 2.6s linear infinite;
}
@keyframes fx-scan { from { background-position: 0 100% } to { background-position: 0 -220% } }

/* --- редкие эффекты --- */

.fx-glow { color: var(--nick); animation: fx-glow 2.2s ease-in-out infinite; }
@keyframes fx-glow {
  0%, 100% { text-shadow: 0 0 3px var(--nick) }
  50% { text-shadow: 0 0 9px var(--nick), 0 0 20px var(--nick) }
}

.fx-shimmer {
  color: transparent;
  background-image: linear-gradient(100deg, var(--nick) 0 38%, var(--hi) 50%, var(--nick) 62% 100%);
  background-size: 280% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: fx-shimmer 2.8s linear infinite;
}
@keyframes fx-shimmer { from { background-position: 140% 0 } to { background-position: -140% 0 } }

.fx-rainbow {
  color: transparent;
  background-image: linear-gradient(90deg, #ff6b81, #f2cc60, #7ee787, #56d4dd, #8ab4f8, #d2a8ff, #ff6b81);
  background-size: 320% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: fx-rainbow 4.5s linear infinite;
}
@keyframes fx-rainbow { from { background-position: 0 0 } to { background-position: 320% 0 } }
:root[data-theme='light'] .fx-rainbow { filter: brightness(0.7) saturate(1.35); }

/* Градиентным эффектам нужен прозрачный текст, иначе градиент под ним не
   виден. В светлой теме правило `[data-theme] .tint` перебивает их по
   специфичности, поэтому прозрачность приходится вернуть явно. */
:root[data-theme='light'] .fx-scan,
:root[data-theme='light'] .fx-shimmer,
:root[data-theme='light'] .fx-rainbow { color: transparent; }

.fx-neon {
  color: var(--hi);
  text-shadow: 0 0 2px var(--nick), 0 0 7px var(--nick), 0 0 16px var(--nick);
  animation: fx-neon 5s steps(1) infinite;
}
:root[data-theme='light'] .fx-neon {
  color: color-mix(in srgb, var(--nick) 45%, var(--ink-mix));
  text-shadow: 0 0 4px color-mix(in srgb, var(--nick) 70%, transparent);
}
@keyframes fx-neon {
  0%, 86%, 100% { opacity: 1 }
  87% { opacity: 0.45 }
  88% { opacity: 1 }
  92% { opacity: 0.3 }
  93% { opacity: 1 }
}

.fx-glitch { position: relative; color: var(--nick); }
:root[data-theme='light'] .fx-glitch { color: color-mix(in srgb, var(--nick) 58%, var(--ink-mix)); }
.fx-glitch::before,
.fx-glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  pointer-events: none;
  opacity: 0;
}
.fx-glitch::before { color: #ff4d6d; animation: fx-glitch-a 2.8s steps(1) infinite; }
.fx-glitch::after { color: #4dd2ff; animation: fx-glitch-b 2.8s steps(1) infinite; }
@keyframes fx-glitch-a {
  0%, 86%, 100% { opacity: 0; transform: none }
  87% { opacity: 0.85; transform: translate(-2px, -1px) }
  89% { opacity: 0.85; transform: translate(2px, 1px) }
  91% { opacity: 0 }
}
@keyframes fx-glitch-b {
  0%, 86%, 100% { opacity: 0; transform: none }
  88% { opacity: 0.85; transform: translate(2px, 1px) }
  90% { opacity: 0.85; transform: translate(-2px, 0) }
  92% { opacity: 0 }
}

/* --- выбор эффекта в настройках --- */

.effects { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.effect-btn {
  background: var(--bg);
  border: 2px solid var(--line);
  padding: 7px 6px;
  cursor: pointer;
  font-size: 13px;
  text-align: center;
  overflow: hidden;
}
.effect-btn:hover { border-color: var(--text); }
.effect-btn.is-active { border-color: var(--text); background: var(--accent-dim); }
.effect-btn.is-locked { opacity: 0.5; cursor: not-allowed; border-style: dashed; }
.effect-btn .lock { display: block; font-size: 10px; color: var(--muted); letter-spacing: 1px; }

/* ---------- палитра ---------- */

.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.is-active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }

.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type='color'] {
  width: 46px;
  height: 38px;
  padding: 2px;
  background: var(--bg);
  border: 2px solid var(--line);
  cursor: pointer;
}
.hex-input { width: 110px; font-family: var(--font-mono); text-transform: lowercase; }
.preview { font-weight: 700; }

input[type='range'] {
  flex: 1;
  min-width: 120px;
  accent-color: var(--text);
  background: transparent;
}

/* Личный диск виден только тому, кому он выдан. */
.private-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 2px dashed var(--line-soft);
  padding-top: 8px;
  margin-top: 2px;
}

#files-scope { margin-bottom: 0; }

/* ==========================================================================
   основной экран
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 2px solid var(--line);
  min-height: 0;
  padding: 14px;
  gap: 14px;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar .brand { font-size: 17px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  background: none;
  border: 2px solid transparent;
  padding: 8px 10px;
  text-align: left;
  color: var(--muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 14px;
}
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.storage { display: flex; flex-direction: column; gap: 6px; }
.storage-bar { height: 12px; background: var(--bg); border: 2px solid var(--line); padding: 1px; }
.storage-fill { height: 100%; width: 0; background: var(--text); transition: width 0.3s steps(12); }
/* Предупреждение — штриховка, переполнение — мигание. Цвета тут нет. */
.storage-fill.is-warn {
  background-image: repeating-linear-gradient(45deg, var(--text) 0 3px, transparent 3px 7px);
  background-color: var(--muted);
}
.storage-fill.is-full { background: var(--text); animation: blink 1.1s steps(1) infinite; }
.storage-text { font-size: 12px; color: var(--muted); }

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-head .btn-tiny { margin-left: auto; }

.online { flex: 1 1 40%; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.online-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.online-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 2px; }
.online-list li.is-clickable { cursor: pointer; }
.online-list li.is-clickable:hover { background: var(--raised); }
.online-dot { width: 8px; height: 8px; background: var(--text); flex: none; }

/* ---------- личные чаты ---------- */

.dms { flex: 1 1 60%; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.dm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dm-item {
  padding: 5px 7px;
  border: 2px solid transparent;
  cursor: pointer;
}
.dm-item:hover { background: var(--raised); border-color: var(--line-soft); }
.dm-item.is-active { background: var(--raised); border-color: var(--text); }
.dm-head { display: flex; align-items: baseline; gap: 6px; }
.dm-head .nick-wrap { flex: 1; min-width: 0; overflow: hidden; }
.dm-time { font-size: 10.5px; color: var(--muted); font-family: var(--font-mono); flex: none; }
.dm-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

/* Непрочитанное — инверсия, потому что цветом кричать нечем. */
.unread {
  background: var(--text);
  color: var(--bg);
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 5px;
  flex: none;
  font-family: var(--font-mono);
}

.nav-item.is-dm::after { content: ' ·'; }

.dm-picker { margin-top: 12px; max-height: 50dvh; overflow-y: auto; border: 2px solid var(--line); }

.scope {
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-foot {
  border-top: 2px solid var(--line-soft);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.me { font-size: 14px; }
.me small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; word-break: break-all; }
.sidebar-actions { display: flex; flex-direction: column; gap: 2px; }

/* ---------- правая часть ---------- */

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 2px solid var(--line);
  background: var(--bg);
  min-height: 54px;
}
.topbar .tabs { margin: 0; flex: 1; }
.topbar-storage { font-size: 12px; color: var(--muted); }

.conn { margin-left: auto; font-size: 11.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.conn[data-state='online'] { color: var(--text); }
.conn[data-state='connecting'] { animation: blink 1.2s steps(1) infinite; }
.conn[data-state='offline'] {
  background: var(--text);
  color: var(--bg);
  padding: 1px 5px;
  font-weight: 700;
}

.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }

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

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.loader { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }

.msg {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 5px 8px 5px 62px;
  border-left: 3px solid transparent;
  position: relative;
}
.msg:hover { background: var(--raised); border-left-color: var(--line); }
/* Сообщение, где упомянули тебя, помечается сплошной полосой слева. */
.msg.is-mention { background: var(--raised); border-left-color: var(--text); }
/* Подсветка после перехода по цитате. */
.msg.is-flash { background: var(--accent-dim); border-left-color: var(--text); }

.msg-main { min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-left: -54px; }
.msg-time { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }

/* Столбик: подряд идущие сообщения одного человека теряют шапку,
   а время уходит в левое поле и показывается при наведении. */
.msg.is-compact { padding-top: 1px; padding-bottom: 1px; }
.msg-gutter {
  position: absolute;
  left: 8px;
  top: 2px;
  width: 46px;
  text-align: right;
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.12s;
}
.msg:hover .msg-gutter { opacity: 1; }

.msg-actions { display: flex; gap: 2px; align-self: start; opacity: 0; transition: opacity 0.12s; }
.msg:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; }

/* ---------- ответы ---------- */

.reply-quote {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  border-left: 3px solid var(--line);
  padding: 1px 0 1px 7px;
  margin-bottom: 3px;
  margin-left: -54px;
  cursor: pointer;
  max-width: 560px;
}
.reply-quote:hover { border-left-color: var(--text); color: var(--text); }
.reply-quote.is-gone { cursor: default; font-style: italic; }
.reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.reply-bar,
.attach-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-bottom: 2px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--muted);
}
.reply-label {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10.5px;
  border: 1px solid var(--line);
  padding: 0 4px;
  flex: none;
}
.reply-to { display: flex; align-items: baseline; gap: 6px; min-width: 0; flex: 1; }
.attach-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-progress { font-family: var(--font-mono); flex: none; }

/* ---------- карточка ссылки ---------- */

.embed-slot:empty { display: none; }
.embed {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 6px;
  max-width: 480px;
  background: var(--bg);
  border: 2px solid var(--line);
  border-left-width: 5px;
  padding: 8px 10px;
  text-decoration: none;
  color: inherit;
}
.embed:hover { border-left-color: var(--text); }
.embed-image {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border: 1px solid var(--line-soft);
  flex: none;
  background: var(--raised);
}
.embed-body { min-width: 0; }
.embed-site {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.embed-title { font-weight: 700; font-size: 14px; margin-top: 2px; }
.embed-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* Картинку в чат можно просто бросить на ленту. */
#pane-chat.is-drop { outline: 3px dashed var(--text); outline-offset: -6px; }

.msg-day {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  border-top: 2px solid var(--line-soft);
  border-bottom: 2px solid var(--line-soft);
  padding: 2px 14px;
  margin: 12px 0 6px;
}

/* ---------- упоминания ---------- */

.mention { font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.mention.is-me {
  background: var(--text);
  color: var(--bg);
  padding: 0 3px;
  text-decoration: none;
}

.mention-pop {
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 4px -4px 0 var(--shadow);
  z-index: 20;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.mention-item:last-child { border-bottom: none; }
.mention-item.is-active { background: var(--accent); color: var(--accent-ink); }
.mention-item.is-active .tint { color: var(--accent-ink); }

/* ---------- «печатает» ---------- */

.composer-wrap { position: relative; border-top: 2px solid var(--line); background: var(--bg); }

.typing {
  display: flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 14px 0;
  font-size: 12px;
  color: var(--muted);
}
.dots { display: inline-flex; gap: 3px; margin-left: 5px; align-items: flex-end; height: 10px; }
.dots i {
  width: 4px;
  height: 4px;
  background: currentColor;
  display: block;
  animation: dot 1.2s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0) }
  35% { opacity: 1; transform: translateY(-4px) }
}

.composer {
  display: flex;
  gap: 10px;
  padding: 8px 14px 12px;
  align-items: flex-end;
}
.composer textarea { resize: none; max-height: 170px; overflow-y: auto; }

/* ---------- карточка файла в чате ---------- */

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  background: var(--bg);
  border: 2px solid var(--line);
  padding: 8px 10px;
  max-width: 440px;
  text-decoration: none;
  color: inherit;
}
a.file-card:hover { border-color: var(--text); }
.file-card .file-icon { font-family: var(--font-mono); flex: none; }
.file-card .file-meta { min-width: 0; flex: 1; }
.file-card .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .file-sub { font-size: 12px; color: var(--muted); }
.file-card.is-gone { opacity: 0.5; }

.file-card.is-image { flex-direction: column; align-items: stretch; gap: 8px; cursor: zoom-in; }
.card-preview {
  display: block;
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  border: 2px solid var(--line-soft);
  background: var(--raised);
}
.card-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- файлы ---------- */

#pane-files { overflow-y: auto; padding: 16px; gap: 14px; }

.files-toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.files-toolbar input[type='search'] { flex: 1 1 200px; }
.files-toolbar select { flex: 0 0 auto; width: auto; }

.dropzone {
  border: 2px dashed var(--line);
  padding: 22px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.dropzone p { margin: 0 0 4px; }
.dropzone.is-over { border-color: var(--text); background: var(--accent-dim); color: var(--text); }

.uploads { display: flex; flex-direction: column; gap: 8px; }
.upload {
  background: var(--raised);
  border: 2px solid var(--line);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.upload-top { display: flex; align-items: center; gap: 10px; }
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-pct { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.upload-bar { height: 10px; background: var(--bg); border: 2px solid var(--line); padding: 1px; }
.upload-fill { height: 100%; width: 0; background: var(--text); transition: width 0.2s steps(10); }
.upload.is-error .upload-fill {
  background-image: repeating-linear-gradient(45deg, var(--text) 0 3px, transparent 3px 7px);
  background-color: var(--muted);
}
.upload-stats {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}
.upload-error { font-size: 12.5px; color: var(--danger); font-weight: 700; }

.files-list { display: flex; flex-direction: column; gap: 6px; }
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--raised);
  border: 2px solid var(--line);
  padding: 9px 11px;
}
.file-row .fr-main { min-width: 0; flex: 1; }
.file-row .fr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fr-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.file-row .fr-size { font-size: 13px; color: var(--muted); font-family: var(--font-mono); flex: none; }
.file-row .fr-actions { display: flex; gap: 6px; flex: none; }
.files-empty { color: var(--muted); text-align: center; padding: 20px; }

.thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border: 2px solid var(--line-soft);
  background: var(--bg);
  flex: none;
  cursor: zoom-in;
  image-rendering: auto;
}
.thumb-stub {
  width: 46px;
  height: 46px;
  border: 2px solid var(--line-soft);
  background: var(--bg);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- просмотр картинки ---------- */

.lightbox-inner {
  position: relative;
  max-width: min(1100px, 94vw);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 2px solid var(--line);
  padding: 6px 10px;
}
.lightbox-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.lightbox-actions { display: flex; align-items: center; gap: 8px; flex: none; }
#lightbox-img {
  max-width: 100%;
  max-height: calc(90dvh - 60px);
  object-fit: contain;
  border: 2px solid var(--line);
  background: var(--surface);
}

/* ---------- модальные окна ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); }
:root[data-theme='light'] .modal-backdrop { background: rgba(40, 40, 40, 0.45); }
.modal-card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 8px 8px 0 var(--shadow);
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 88dvh;
  overflow-y: auto;
}
.modal-wide { max-width: 800px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; text-transform: uppercase; letter-spacing: 1px; }
.sep { border: none; border-top: 2px solid var(--line-soft); margin: 20px 0; }

/* ---------- админка ---------- */

.admin-pane { display: flex; flex-direction: column; gap: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.stat { background: var(--raised); border: 2px solid var(--line); padding: 10px; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 18px; font-weight: 700; margin-top: 4px; }

.table { display: flex; flex-direction: column; gap: 6px; }
.trow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--raised);
  border: 2px solid var(--line);
  padding: 9px 11px;
  font-size: 14px;
}
.trow .tmain { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.trow .tline { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.trow .tsub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.trow .tactions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }

.style-editor {
  grid-column: 1 / -1;
  border-top: 2px solid var(--line-soft);
  margin-top: 8px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.style-editor .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.style-editor .row .field { flex: 1 1 130px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkline input { width: auto; }

/* Состояния различаются начертанием рамки, а не цветом. */
.badge {
  font-size: 10.5px;
  padding: 0 5px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }
.badge.is-banned { border-style: dashed; border-color: var(--text); color: var(--text); }
.badge.is-pending { border-style: dotted; color: var(--text); }
.mono { font-family: var(--font-mono); }

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

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: var(--raised);
  border: 2px solid var(--line);
  border-left-width: 6px;
  border-left-color: var(--muted);
  padding: 10px 12px;
  font-size: 13.5px;
  box-shadow: 4px 4px 0 var(--shadow);
  animation: toast-in 0.14s steps(3);
}
.toast.is-error { border-left-color: var(--text); border-left-style: dashed; font-weight: 700; }
.toast.is-ok { border-left-color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) } }

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

.only-mobile { display: none; }

@media (max-width: 880px) {
  body { font-size: 15px; }

  .only-mobile { display: block; }
  .tabs.only-mobile { display: flex; }

  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(304px, 88vw);
    z-index: 60;
    transform: translateX(-104%);
    transition: transform 0.18s steps(6);
    box-shadow: 8px 0 0 var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .sidebar .nav { display: none; }

  .messages { padding: 10px 4px; }
  .msg { padding-left: 44px; }
  .msg-head, .reply-quote { margin-left: -36px; }
  .msg-gutter { left: 4px; width: 32px; }
  .scope { display: none; }
  .embed { max-width: none; }
  .card-preview { max-height: 220px; }

  #pane-files { padding: 12px; }
  .composer { padding: 8px 10px 10px; }
  .typing { padding: 1px 10px 0; }
  .reply-bar, .attach-bar { padding: 5px 10px; }
  .card { padding: 18px; }
  .modal-card { padding: 16px; }
  .toasts { left: 16px; right: 16px; max-width: none; }

  .file-row { flex-wrap: wrap; }
  .file-row .fr-main { flex: 1 1 100%; order: 1; }
  .thumb, .thumb-stub { order: 0; }
  .file-row .fr-size { order: 2; }
  .file-row .fr-actions { order: 3; margin-left: auto; }
}

/* ==========================================================================
   «меньше движения»: все анимации выключаются, цвет ника остаётся статичным
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .fx-scan, .fx-shimmer, .fx-rainbow { color: var(--nick); background-image: none; }
  :root[data-theme='light'] .fx-scan,
  :root[data-theme='light'] .fx-shimmer,
  :root[data-theme='light'] .fx-rainbow {
    color: color-mix(in srgb, var(--nick) 58%, var(--ink-mix));
  }
  .fx-glitch::before, .fx-glitch::after { display: none; }
  .caret, .brand-dot, .conn, .storage-fill { opacity: 1 !important; }
  .dots i { opacity: 0.6 !important; }
}
