/* lappla-talk — лента общего канала. Профиль work: плотно, цвета только из токенов ниже. */

:root {
  color-scheme: dark;
  --bg: #13141c;
  --s1: #191a25;
  --s2: #20222f;
  --s3: #2a2d3e;
  --fg: #c8d0f0;
  --mute: #8b92b4;
  --dim: #5d6384;
  --line: #262938;
  --line2: #34384d;
  --acc: #7aa2f7;
  --on-acc: #10111a;
  --acc-soft: rgb(122 162 247 / 0.14);
  --ok: #9ece6a;
  --err: #f7768e;
  /* тона различают участников между собой */
  --t1: #7aa2f7;
  --t2: #bb9af7;
  --t3: #9ece6a;
  --t4: #e0af68;
  --t5: #7dcfff;
  --t6: #f7768e;
  --shadow: 0 10px 28px rgb(0 0 0 / 0.38);
  --r: 6px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --font: system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f2ec;
    --s1: #fbfaf6;
    --s2: #ecebe4;
    --s3: #e0ded5;
    --fg: #23242c;
    --mute: #5f6273;
    --dim: #92949f;
    --line: #e2e0d8;
    --line2: #d2d0c6;
    --acc: #3557c9;
    --on-acc: #ffffff;
    --acc-soft: rgb(53 87 201 / 0.1);
    --ok: #3d8a2f;
    --err: #c2334f;
    --t1: #3557c9;
    --t2: #8241c2;
    --t3: #3d8a2f;
    --t4: #a8620c;
    --t5: #1f7f9e;
    --t6: #c2334f;
    --shadow: 0 10px 28px rgb(40 36 20 / 0.16);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--acc); text-decoration: none; }
a:hover { background: var(--acc-soft); border-radius: 3px; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; border-radius: 4px; }

.brand { font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.brand span { color: var(--acc); padding: 0 1px; }

/* --- кнопки */
.btn {
  border: 1px solid var(--line2);
  background: var(--s2);
  border-radius: var(--r);
  padding: 7px 14px;
  cursor: pointer;
  transition: background var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--s3); }
.btn:active, .icon-btn:active, .send:active, .chip:active { transform: scale(0.97); }
.btn-acc { background: var(--acc); border-color: var(--acc); color: var(--on-acc); font-weight: 600; }
.btn-acc:hover { background: var(--acc); filter: brightness(1.08); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--mute);
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--s2); color: var(--fg); }
.icon-btn.on { color: var(--acc); }
.icon-btn svg { width: 17px; height: 17px; }

/* --- вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 22px;
  background: var(--s1);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card .brand { font-size: 18px; }
.login-note { margin: 0 0 4px; color: var(--mute); font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line2);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--fg);
  font: 13px var(--mono);
}
.login-card input:focus { outline: none; border-color: var(--acc); }
.login-err { margin: 0; min-height: 1.2em; color: var(--err); font-size: 12px; }

/* --- каркас */
.app { height: 100dvh; display: flex; flex-direction: column; position: relative; }
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--s1);
  min-width: 0;
}
.people { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.bar-actions { display: flex; gap: 2px; margin-left: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}
.chip:hover { background: var(--s2); }
.chip.is-to { border-color: var(--acc); background: var(--acc-soft); }
.chip .you { color: var(--dim); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--dim); flex: none; }
.dot.on { background: var(--ok); border-color: var(--ok); }
.glyph { font-style: normal; font-size: 0.8em; margin-right: 3px; }

.offline {
  padding: 5px 16px;
  font-size: 12px;
  color: var(--err);
  background: var(--s1);
  border-bottom: 1px solid var(--line);
}

/* --- лента */
.feed { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 12px; outline: none; }
.list { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.older { display: block; margin: 4px auto 10px; }
.empty { max-width: 460px; margin: 18vh auto 0; padding: 0 16px; text-align: center; color: var(--mute); font-size: 13px; }
.empty b { color: var(--fg); }
.day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 6px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.msg {
  position: relative;
  padding: 6px 10px 8px;
  margin: 0 -10px;
  border-radius: var(--r);
  transition: background var(--dur-fast) ease;
}
.msg:hover { background: var(--s1); }
.msg.flash { background: var(--acc-soft); transition: background 900ms ease; }
.msg + .msg { margin-top: 2px; }
.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
}
.who { font-weight: 650; font-size: 13px; color: var(--tone, var(--fg)); white-space: nowrap; }
.tone-1 { --tone: var(--t1); }
.tone-2 { --tone: var(--t2); }
.tone-3 { --tone: var(--t3); }
.tone-4 { --tone: var(--t4); }
.tone-5 { --tone: var(--t5); }
.tone-6 { --tone: var(--t6); }
.to { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-to { color: var(--tone); }
.ref, .reply-ref {
  border: 0;
  padding: 0 2px;
  margin: 0 -2px;
  border-radius: 3px;
  background: transparent;
  color: var(--acc);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ref:hover, .reply-ref:hover { background: var(--acc-soft); }
.time { color: var(--dim); white-space: nowrap; }
.spacer { flex: 1; }
.seen { color: var(--dim); font-size: 11px; letter-spacing: -0.12em; white-space: nowrap; }
.seen.all { color: var(--acc); }
.num { color: var(--dim); font-size: 11px; white-space: nowrap; }
.msg-actions {
  position: absolute;
  top: 2px;
  right: 6px;
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--s2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) ease;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg-actions .icon-btn { width: 26px; height: 24px; }
.msg-actions .icon-btn svg { width: 15px; height: 15px; }

/* --- markdown */
.md { margin-top: 2px; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 6px; }
.md .h { font-weight: 700; margin: 10px 0 4px; }
.md .h1, .md .h2 { font-size: 15px; }
.md ul, .md ol { margin: 2px 0 6px; padding-left: 22px; }
.md li { margin: 1px 0; }
.md li.d1 { margin-left: 18px; list-style-type: circle; }
.md li.d2, .md li.d3 { margin-left: 36px; list-style-type: square; }
.md blockquote { margin: 4px 0 6px; padding: 0 0 0 10px; border-left: 2px solid var(--line2); color: var(--mute); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md code {
  font: 12.5px var(--mono);
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--s2);
}
.md del { color: var(--dim); }
.code { margin: 4px 0 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--s1); overflow: hidden; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 2px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
}
.code-head button {
  border: 0;
  background: transparent;
  color: var(--mute);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.code-head button:hover { background: var(--s2); color: var(--acc); }
.code pre { margin: 0; padding: 8px 10px; overflow-x: auto; }
.code pre code { padding: 0; background: none; font-size: 12.5px; line-height: 1.45; }
.tbl-wrap { overflow-x: auto; margin: 4px 0 8px; }
.md table { border-collapse: collapse; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--s1); font-weight: 600; }
.md .al-r { text-align: right; }
.md .al-c { text-align: center; }

.jump {
  position: absolute;
  right: 22px;
  bottom: 84px;
  padding: 5px 11px;
  border: 1px solid var(--acc);
  border-radius: var(--r);
  background: var(--acc);
  color: var(--on-acc);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* --- поле ввода */
.composer {
  border-top: 1px solid var(--line);
  background: var(--s1);
  padding: 8px max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.composer-in { max-width: 980px; margin: 0 auto; }
.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 3px 4px 3px 10px;
  border-left: 2px solid var(--acc);
  background: var(--s2);
  border-radius: 0 var(--r) var(--r) 0;
  font-size: 12px;
  color: var(--mute);
  min-width: 0;
}
.reply-bar .quote { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar b { color: var(--fg); font-weight: 600; }
.compose-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color var(--dur-fast) ease;
}
.compose-row:focus-within { border-color: var(--acc); }
.to-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r);
  background: var(--s2);
  color: var(--mute);
  font-size: 12px;
  cursor: pointer;
  max-width: 40%;
}
.to-btn:hover { background: var(--s3); color: var(--fg); }
.to-btn.set { background: var(--acc-soft); color: var(--acc); }
.to-btn .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-row textarea {
  flex: 1;
  min-width: 0;
  min-height: 30px;
  max-height: 40vh;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--fg);
  font: 14px/1.45 var(--font);
  padding: 5px 4px;
}
.compose-row textarea::placeholder { color: var(--dim); }
.send {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 30px;
  border: 0;
  border-radius: var(--r);
  background: var(--acc);
  color: var(--on-acc);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) ease;
}
.send:disabled { opacity: 0.4; cursor: default; }
.send svg { width: 16px; height: 16px; }
.hint { margin-top: 4px; font-size: 11px; color: var(--dim); }
.hint kbd { font: 10.5px var(--mono); padding: 0 4px; border: 1px solid var(--line2); border-radius: 3px; }

/* --- всплывающее: панель у кнопки, меню, тултип, тосты */
.pop {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  max-width: min(340px, calc(100vw - 16px));
  padding: 4px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--s1);
  box-shadow: var(--shadow);
  animation: pop-in var(--dur-base) var(--ease-out);
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } }
.pop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}
.pop-item > span:first-child { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.pop-item:hover, .pop-item:focus-visible { background: var(--s2); outline: none; }
.pop-item.sel { color: var(--acc); }
.pop-item .sub { margin-left: auto; color: var(--dim); font-size: 11px; }
.pop-sep { height: 1px; margin: 4px 6px; background: var(--line); }
.pop-text { padding: 8px 10px; font-size: 12.5px; color: var(--mute); max-width: 320px; }
.pop-text p { margin: 0 0 6px; }
.pop-text p:last-child { margin: 0; }
.pop-text b { color: var(--fg); }
.pop-text code { font: 11.5px var(--mono); background: var(--s2); padding: 0 3px; border-radius: 3px; }

.tip {
  position: fixed;
  z-index: 50;
  max-width: 280px;
  padding: 6px 9px;
  border: 1px solid var(--line2);
  border-radius: var(--r);
  background: var(--s2);
  color: var(--mute);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: pop-in 140ms var(--ease-out);
}
.tip b { color: var(--acc); font-weight: 600; }

.toasts {
  position: fixed;
  z-index: 60;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  justify-items: center;
  pointer-events: none;
}
.toast {
  padding: 7px 14px;
  border: 1px solid var(--line2);
  border-radius: var(--r);
  background: var(--s2);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast.err { border-color: var(--err); color: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

@media (prefers-reduced-motion: reduce) {
  .pop, .tip, .toast { animation-duration: 1ms; }
  .msg.flash { transition-duration: 300ms; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .bar { gap: 8px; }
  .bar > .brand { display: none; }
  .hint { display: none; }
  .jump { right: 16px; }
  .msg-actions { top: -4px; }
}
