/* =============================================================================
   smeta.kuhnismak.ru — переписка с расчётным отделом фабрики.
   Мир страницы: мессенджер. Обои чата — фирменный красный фабрики (#C60C30, на тон глубже),
   входящие — белые, исходящие и быстрые ответы — угольные: ответ, которого коснулись,
   становится исходящим сообщением. Белые полосы сверху и снизу — шапка чата и строка ввода.
   Движение: один момент — номер улетает из строки ввода сообщением. Остальное меняется рывком.
   ============================================================================= */

@font-face {
  font-family: "Golos";
  src: url("fonts/golos-text-var.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --brand:   #C60C30;
  --brand-dk:#A70A28;
  --wall:    #B10B2B;
  --paper:   oklch(0.985 0.006 20);
  --paper-2: oklch(0.95 0.012 20);
  --hair:    oklch(0.2 0.03 20 / .12);
  --coal:    oklch(0.27 0.014 20);
  --coal-hi: oklch(0.34 0.018 20);
  --ink:     oklch(0.23 0.015 20);
  --ink-2:   oklch(0.44 0.022 20);
  --on-coal: oklch(0.975 0.006 20);
  --on-coal-2: oklch(0.8 0.012 20);
  --on-wall: oklch(0.97 0.015 20);

  --f: "Golos", "Segoe UI", system-ui, sans-serif;
  --gut: clamp(12px, 3.6vw, 22px);
  --ease: cubic-bezier(.16, 1, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: oklch(0.32 0.09 20) var(--wall);
  scrollbar-width: thin;
}
body {
  margin: 0;
  background: var(--wall) url("img/wall.svg") 0 0 / 260px 260px;
  color: var(--on-wall);   /* на обоях текст светлый; тёмный — только на белых поверхностях ниже */
  font: 400 1.0625rem/1.4 var(--f);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--coal); color: var(--on-coal); }
:focus-visible { outline: 2.5px solid var(--on-wall); outline-offset: 3px; }
.hd :focus-visible, .pin :focus-visible, .cmp :focus-visible, .msg :focus-visible { outline-color: var(--coal); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
p, h1, h2, ol, ul, dl, dd { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; height: auto; }
svg { display: block; }

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 46rem;
  margin-inline: auto;
}

/* --- Шапка чата -------------------------------------------------------------- */
.hd {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--hair), 0 8px 16px -10px oklch(0.14 0.012 20 / .5);
}
.hd__in {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px max(var(--gut), env(safe-area-inset-right)) 8px max(var(--gut), env(safe-area-inset-left));
}
.ava {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}
.hd__t { display: grid; flex: 1; min-width: 0; line-height: 1.2; }
.hd__t b { font-size: 1.0625rem; font-weight: 800; letter-spacing: -.01em; }
.hd__t span { font-size: .8125rem; color: var(--ink-2); }
.hd__t i { display: none; font-style: normal; }
/* станции пути: что есть → куда писать → телефон */
.rail { display: flex; gap: 4px; flex: none; }
.rail i { width: 18px; height: 4px; border-radius: 2px; background: oklch(0.87 0.012 20); }
.rail i.is-on { background: var(--brand); }

/* --- Закреплённое: условия фабрики ------------------------------------------- */
.pin { background: var(--paper); color: var(--ink); }
.pin__s {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px max(var(--gut), env(safe-area-inset-right)) 7px max(var(--gut), env(safe-area-inset-left));
  background: oklch(0.962 0.01 20);
  border-bottom: 1px solid var(--hair);
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.pin__s::-webkit-details-marker { display: none; }
.pin__i { width: 20px; height: 20px; flex: none; color: var(--brand); }
.pin__t { display: grid; flex: 1; min-width: 0; font-size: .8125rem; line-height: 1.3; }
.pin__t b { color: var(--brand); font-weight: 700; }
.pin__t span { color: var(--ink-2); }
.pin__c { width: 20px; height: 20px; flex: none; color: var(--ink-2); }
.pin[open] .pin__c { rotate: 180deg; }
.pin__b { padding: 4px max(var(--gut), env(safe-area-inset-right)) 18px max(var(--gut), env(safe-area-inset-left)); box-shadow: 0 1px 0 var(--hair); }
.who { display: none; }
.pin__h { margin: 16px 0 8px; font-size: 1rem; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.pin__h--a { display: none; }
.tt div {
  display: grid;
  grid-template-columns: 9.6rem minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--hair);
}
.tt dt { font-size: .875rem; color: var(--ink-2); }
.tt dd { font-size: .9375rem; font-weight: 600; line-height: 1.3; }
.media { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-width: 26rem; }
.media img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 8px; background: var(--paper-2); }
.pin__n { margin-top: 12px; font-size: .875rem; line-height: 1.45; color: var(--ink-2); }
.pin__n a { color: var(--ink); font-weight: 700; font-size: 1rem; }

/* --- Лента сообщений ---------------------------------------------------------- */
.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 10px max(var(--gut), env(safe-area-inset-right)) 14px max(var(--gut), env(safe-area-inset-left));
}
.day {
  align-self: center;
  margin: 2px 0 10px;
  padding: 3px 11px 4px;
  border-radius: 999px;
  background: oklch(0.2 0.06 20 / .38);
  color: var(--on-wall);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.2;
}
.thread { display: flex; flex-direction: column; gap: 5px; }
.msg {
  position: relative;
  max-width: min(86%, 30rem);
  padding: 8px 12px 6px 13px;
  border-radius: 18px;
  box-shadow: 0 1px 1.5px oklch(0.14 0.012 20 / .3);
  overflow-wrap: anywhere;
}
.msg--in  { align-self: flex-start; background: var(--paper); color: var(--ink); border-bottom-left-radius: 5px; }
.msg--out { align-self: flex-end; background: var(--coal); color: var(--on-coal); border-bottom-right-radius: 5px; }
.msg--in + .msg--out, .msg--out + .msg--in { margin-top: 6px; }
/* хвостик — у последнего сообщения подряд от одного собеседника */
.msg::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 11px;
  height: 15px;
  background: inherit;
}
.msg--in::after  { left: -6px;  clip-path: path("M11 0C11 8 6 14 0 15H11Z"); }
.msg--out::after { right: -6px; clip-path: path("M0 0C0 8 5 14 11 15H0Z"); }
.msg--in:has(+ .msg--in)::after, .msg--out:has(+ .msg--out)::after { display: none; }
.msg--in:has(+ .msg--in) { border-bottom-left-radius: 18px; }
.msg--out:has(+ .msg--out) { border-bottom-right-radius: 18px; }
.msg h1 {
  font-size: clamp(1.25rem, 5.4vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.018em;
  text-wrap: pretty;
}
.msg--lead { max-width: min(94%, 31rem); padding-top: 10px; }
.msg time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: .6875rem;
  line-height: 1;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.msg--out time { color: var(--on-coal-2); }
.msg time svg { width: 17px; height: 10px; }
.msg.is-new { animation: pop .14s var(--ease) both; }
.msg--in.is-new  { transform-origin: 0 100%; }
.msg--out.is-new { transform-origin: 100% 100%; }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
/* единственный «полёт»: номер уходит из строки ввода в ленту */
.msg--fly.is-new { animation: fly .38s var(--ease) both; }
@keyframes fly { from { opacity: .2; transform: translateY(54px) scale(.86); } }

.msg .acts { display: grid; gap: 6px; margin-top: 8px; }
.act {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background-color .15s;
}
.act--2 { background: var(--paper-2); color: var(--ink); }
@media (hover: hover) { .act:hover { background: var(--brand-dk); } .act--2:hover { background: oklch(0.91 0.016 20); } }
.album { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin: 2px -6px 6px -7px; }
.album img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 6px; background: var(--paper-2); }
.album img:first-child { border-top-left-radius: 12px; }
.album img:last-child { border-top-right-radius: 12px; }

/* --- Быстрые ответы: будущие исходящие сообщения ------------------------------ */
.quick { display: grid; gap: 7px; margin-top: 10px; }
.quick--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: 9px 12px 9px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--coal);
  color: var(--on-coal);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 8px -3px oklch(0.14 0.012 20 / .6);
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, transform .1s;
}
.q svg { width: 20px; height: 20px; flex: none; color: var(--on-coal-2); }
.q:active { transform: scale(.985); background: var(--coal-hi); }
@media (hover: hover) { .q:hover { background: var(--coal-hi); } }

.fallback {
  display: none;
  align-self: flex-start;
  max-width: 30rem;
  margin-top: 10px;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
}
.js-fail .fallback, .fallback--on { display: block; }
.js-fail .quick, .js-fail .cmp, .no-js .quick, .no-js .cmp { display: none; }

/* служебная подпись в конце ленты: чей чат, политика, оферта */
.sys {
  margin-top: auto;
  padding-top: 26px;
  color: oklch(0.93 0.035 20);
  font-size: .75rem;
  line-height: 1.45;
  text-align: center;
}
.sys p { max-width: 36em; margin-inline: auto; }

/* --- Строка ввода -------------------------------------------------------------- */
.cmp {
  position: sticky;
  bottom: 0;
  z-index: 6;
  padding: 8px max(var(--gut), env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(var(--gut), env(safe-area-inset-left));
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 -1px 0 var(--hair), 0 -8px 16px -10px oklch(0.14 0.012 20 / .5);
}
.cmp__row { display: flex; align-items: center; gap: 8px; }
.cmp__f {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  min-height: 46px;
  padding: 0 16px;
  border: 1.5px solid transparent;
  border-radius: 23px;
  background: var(--paper-2);
  cursor: text;
  transition: border-color .15s, background-color .15s, box-shadow .2s;
}
.cmp__f input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: 500 1.0625rem/1.2 var(--f);
  font-variant-numeric: tabular-nums;
  caret-color: var(--brand);
}
.cmp__f input::placeholder { color: var(--ink-2); opacity: 1; font-weight: 400; }
.cmp__f:focus-within, .cmp.is-awake .cmp__f { border-color: var(--brand); background: #fff; }
.cmp.is-awake .cmp__f { box-shadow: 0 0 0 4px oklch(0.52 0.2 20 / .16); }
.cmp__go {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, transform .1s;
}
.cmp__go svg { width: 24px; height: 24px; }
.cmp__go:active { transform: scale(.93); }
@media (hover: hover) { .cmp__go:hover { background: var(--brand-dk); } }
.cmp.is-busy .cmp__go { background: var(--ink-2); cursor: progress; }
.cmp__c { margin: 6px 4px 0; font-size: .75rem; line-height: 1.35; color: var(--ink-2); }
.cmp__err {
  position: relative;
  margin: 0 4px 8px;
  padding-left: 1.7em;
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.35;
}
.cmp__err::before {
  content: "";
  position: absolute;
  left: 0;
  top: .08em;
  width: 1.2em;
  height: 1.2em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5 22 20.5H2Z' fill='none' stroke='%23C60C30' stroke-width='2' stroke-linejoin='round'/%3E%3Cpath d='M12 10v5.2M12 17.6v.4' stroke='%23C60C30' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* --- Широкий экран: слева карточка фабрики, справа переписка ------------------- */
@media (min-width: 980px) {
  .app {
    display: grid;
    grid-template-columns: 23rem minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    max-width: 68rem;
  }
  .hd, .chat, .cmp { grid-column: 2; }
  .hd__in { padding-block: 11px; }
  .hd__t i { display: inline; }
  .pin {
    grid-column: 1;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    scrollbar-width: thin;
    border-right: 1px solid var(--hair);
    box-shadow: 8px 0 20px -14px oklch(0.14 0.012 20 / .5);
    z-index: 7;
  }
  .pin__s { display: none; }
  .pin__b { padding: 26px 24px 28px; box-shadow: none; }
  .who { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
  .who p { display: grid; line-height: 1.3; }
  .who p b { font-size: 1.375rem; font-weight: 800; letter-spacing: -.02em; }
  .who p span { font-size: .875rem; color: var(--ink-2); }
  .ava--xl { width: 64px; height: 64px; font-size: 2rem; }
  .pin__h { margin-top: 24px; }
  .pin__h--a { display: block; }
  .tt div { grid-template-columns: 8.4rem minmax(0, 1fr); }
  .chat { padding: 18px 28px 20px; }
  .msg { max-width: min(74%, 30rem); }
  .msg--lead { max-width: min(80%, 33rem); }
  .msg h1 { font-size: 1.625rem; }
  .quick { max-width: 26rem; }
  .cmp { padding: 12px 28px 14px; }
  .cmp__row, .cmp__c, .cmp__err { max-width: 34rem; }
}

@media (prefers-reduced-motion: reduce) {
  .msg.is-new, .msg--fly.is-new { animation: none; }
  .q, .cmp__go, .cmp__f, .act { transition: none; }
}
