/* Экран 390x844 - как у iPhone, на котором сняты замеры Telegram; корпус +13px с каждой стороны */
.phone-fit { position: relative; z-index: 1; width: calc(416px * var(--k, .8)); height: calc(870px * var(--k, .8)); flex: none; }
.phone { width: 416px; height: 870px; transform: scale(var(--k, .8)); transform-origin: 0 0; border-radius: 62px; padding: 13px;
  background: #1c1f1e; box-shadow: 0 0 0 2px #3a3f3d, 0 50px 90px -20px rgba(6, 40, 26, .55), 0 18px 36px -12px rgba(6, 40, 26, .4); }
.screen { position: relative; width: 100%; height: 100%; border-radius: 50px; overflow: hidden; font-family: var(--ios); color: #000;
  background: linear-gradient(160deg, #9fd9cf 0%, #b7e3b1 45%, #e3eda6 100%); }
.island { position: absolute; top: 11px; left: 50%; width: 122px; height: 35px; margin-left: -61px; background: #000; border-radius: 20px; z-index: 6; }
.status { position: absolute; top: 0; left: 0; right: 0; height: 54px; padding: 18px 34px 0 46px; display: flex; justify-content: space-between;
  font: 600 16px/1 var(--ios); z-index: 5; }
.status .r { display: flex; gap: 6px; align-items: center; }

.view { position: absolute; inset: 0; display: flex; flex-direction: column; padding-top: 54px; transition: opacity .45s, transform .45s; }
html.js .view:not(.is-on) { opacity: 0; transform: translateX(24px); pointer-events: none; }
html:not(.js) .view ~ .view { opacity: 0; transform: translateX(24px); pointer-events: none; position: absolute; inset: 0; }

/* Telegram iOS (зелёная тема прототипа), замеры 390×844 */
.view[data-skin="tg"] {
  --tg-accent: #2a8f78;
  --tg-hint: #8e8e93;
  --tg-glass-light: rgba(244, 250, 255, .74);
  --tg-glass-rim: rgba(255, 255, 255, .9);
  --tg-glass-dark: rgba(20, 70, 50, .55);
  --tg-glass-blur: blur(14px) saturate(1.6);
  --tg-header-top: 57px; /* шапка absolute, padding .view её не сдвигает */
  --tg-capsule-h: 44px;
  --tg-side: 16px;
  --tg-input-h: 40px;
  --tg-input-side: 26px;
  --tg-input-side-kb: 8px;
  --tg-input-gap: 6px;
  --tg-input-bottom: 28px;
  --tg-bubble-max-w: 337px;
}

.view[data-skin="tg"] .chat-head {
  position: absolute;
  top: var(--tg-header-top);
  left: var(--tg-side);
  right: var(--tg-side);
  z-index: 10;
  height: var(--tg-capsule-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  padding: 0;
}
.view[data-skin="tg"] .back {
  width: auto;
  height: var(--tg-capsule-h);
  min-width: var(--tg-capsule-h);
  padding: 0 9px 0 8px;
  border-radius: 22px;
  font-size: 0;
  display: flex;
  align-items: center;
  gap: 2px;
}
.view[data-skin="tg"] .back::before {
  content: "";
  width: 26px;
  height: 26px;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 4 7 12l8 8'/%3E%3C/svg%3E");
}
.view[data-skin="tg"] .title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  flex: none;
  max-width: 224px;
  height: var(--tg-capsule-h);
  padding: 0 28px;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.view[data-skin="tg"] .title b {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 600;
  line-height: 20px;
}
.view[data-skin="tg"] .title small.nowrap,
.view[data-skin="tg"] .title small {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 16px;
  color: var(--tg-hint);
}
.view[data-skin="tg"] .ava {
  width: var(--tg-capsule-h);
  height: var(--tg-capsule-h);
  border: 2.5px solid rgba(255, 255, 255, .75);
  background-clip: padding-box;
}

.view[data-skin="tg"] .chat {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 7px;
  padding: 58px 10px 120px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 90px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 90px);
}
.view[data-skin="tg"]:has(.composer .rkb:not(.is-hidden)) .chat { padding-bottom: 220px; }

.view[data-skin="tg"] .day {
  align-self: center;
  font: 500 13px/20px var(--ios);
  color: #fff;
  background: var(--tg-glass-dark);
  backdrop-filter: var(--tg-glass-blur);
  padding: 1px 9px;
  border-radius: 11px;
  margin: 4px 0 10px;
}

.view[data-skin="tg"] .msg {
  max-width: var(--tg-bubble-max-w);
  padding: 6px 11px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 22.6px;
}
.view[data-skin="tg"] .msg .t {
  margin: 6px 0 -2px 10px;
  font-size: 12px;
  line-height: 16px;
}
.view[data-skin="tg"] .msg--in { background: #fff; border-bottom-left-radius: 6px; }
.view[data-skin="tg"] .msg--out { background: #e2fdc6; border-bottom-right-radius: 6px; }
.view[data-skin="tg"] .msg--out .t { color: var(--tg-accent); }

.view[data-skin="tg"] .msg--photo { padding: 4px; background: #fff; }
.view[data-skin="tg"] .msg--photo img { display: block; width: min(260px, var(--tg-bubble-max-w)); height: auto; border-radius: 14px; }

.view[data-skin="tg"] .msg blockquote {
  margin: 8px 0 0;
  padding: 4px 0 2px 10px;
  border-left: 3px solid var(--tg-accent);
  font-size: 15px;
  line-height: 19px;
}
.view[data-skin="tg"] .ikb {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  align-self: flex-start;
  max-width: var(--tg-bubble-max-w);
  width: 100%;
}
.view[data-skin="tg"] .ikb .row { display: flex; gap: 2px; width: 100%; }
/* Как в Telegram: пузырь с инлайн-клавиатурой растягивается на её ширину, кнопки не шире пузыря */
.view[data-skin="tg"] .msg:has(+ .ikb), .view[data-skin="tg"] .msg:has(+ .ikb) + .ikb { width: min(100%, var(--tg-bubble-max-w)); max-width: var(--tg-bubble-max-w); }
.view[data-skin="tg"] .ikb span {
  flex: 1;
  min-width: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 500;
  background: var(--tg-glass-dark);
  backdrop-filter: var(--tg-glass-blur);
  color: #fff;
}
.view[data-skin="tg"] .ikb .row:last-child span:first-child { border-bottom-left-radius: 7px; }
.view[data-skin="tg"] .ikb .row:last-child span:last-child { border-bottom-right-radius: 7px; }

.view[data-skin="tg"] .typing {
  align-self: flex-start;
  background: #fff;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  padding: 10px 14px;
  display: flex;
  gap: 2px;
  align-items: center;
}
.view[data-skin="tg"] .typing i {
  width: 4.5px;
  height: 4.5px;
  border-radius: 50%;
  background: #9aa7a1;
  animation: tg-typing 0.7s infinite linear;
}
.view[data-skin="tg"] .typing i:nth-child(2) { animation-delay: .14s; }
.view[data-skin="tg"] .typing i:nth-child(3) { animation-delay: .28s; }
@keyframes tg-typing {
  0%, 100% { transform: scale(.67); opacity: .75; }
  50% { transform: scale(1); opacity: 1; }
}

.view[data-skin="tg"] .composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
}
.view[data-skin="tg"] .inputbar {
  display: flex;
  align-items: flex-end;
  gap: var(--tg-input-gap);
  padding: 0 var(--tg-input-side) var(--tg-input-bottom);
  background: transparent;
}
.view[data-skin="tg"] .composer:has(.ib-menu) .inputbar {
  padding-left: 10px;
  padding-right: 10px;
}
.view[data-skin="tg"] .composer:has(.rkb:not(.is-hidden)) .inputbar {
  gap: 5.5px;
  padding: 0 var(--tg-input-side-kb) 9px;
}
.view[data-skin="tg"] .ib-menu {
  flex-shrink: 0;
  height: var(--tg-input-h);
  padding: 3px;
  border: 0;
  border-radius: 20px;
  background: none;
  cursor: default;
  font: inherit;
  display: block;
}
.view[data-skin="tg"] .ib-menu-pill {
  height: 100%;
  padding: 0 13px 0 10px;
  border-radius: 17px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.view[data-skin="tg"] .ib-menu-pill .ico { width: 18px; height: 18px; stroke-width: 2; }
.view[data-skin="tg"] .ib-round {
  width: var(--tg-input-h);
  height: var(--tg-input-h);
  border: 0;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tg-glass-light);
  backdrop-filter: var(--tg-glass-blur);
  box-shadow: inset 0 0 0 .5px var(--tg-glass-rim);
  color: #000;
  cursor: default;
  padding: 0;
  box-sizing: border-box;
}
.view[data-skin="tg"] .ib-round .ico { width: 24px; height: 24px; }
.view[data-skin="tg"] .ib-field {
  flex: 1;
  min-width: 0;
  min-height: var(--tg-input-h);
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 9px 0 16px;
  background: var(--tg-glass-light);
  backdrop-filter: var(--tg-glass-blur);
  box-shadow: inset 0 0 0 .5px var(--tg-glass-rim);
  font-size: 17px;
  color: var(--tg-hint);
}
.view[data-skin="tg"] .ib-field > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view[data-skin="tg"] .ib-field .ico-infield {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: #5f6670;
}

.view[data-skin="tg"] .rkb {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 17px 18px 38px;
  border-radius: 24px 24px 0 0;
  background: rgba(236, 245, 250, .45);
  backdrop-filter: var(--tg-glass-blur);
  box-shadow: inset 0 .5px 0 rgba(255, 255, 255, .8);
}
.view[data-skin="tg"] .rkb .row { display: flex; gap: 5px; }
.view[data-skin="tg"] .rkb span {
  flex: 1;
  min-width: 0;
  height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .78);
  color: #000;
  font-size: 17px;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
.view[data-skin="tg"] .rkb:empty { display: none; }

/* Базовые стили (fallback / legacy) */
.chat-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px 10px; }
.back { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(10px); font-size: 26px; color: #000; }
.title { flex: 1; text-align: center; background: rgba(255, 255, 255, .6); backdrop-filter: blur(10px); border-radius: 22px; padding: 6px 12px; }
.title b { display: block; font-size: 16px; font-weight: 600; }
.title small { font-size: 13px; color: #6d7a74; }
.ava { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font: 600 15px/1 var(--ios); color: #fff;
  background: linear-gradient(135deg, var(--ava, #2aa38a), #1f6f86); }
.ava[data-ava="2aa38a"] { --ava: #2aa38a; }
.ava[data-ava="e0773f"] { --ava: #e0773f; }
.ava[data-ava="2b8fd6"] { --ava: #2b8fd6; }
.ava[data-ava="d9a21b"] { --ava: #9a6b06; }
.ava[data-ava="7a5af5"] { --ava: #7a5af5; }
.ava[data-ava="007aff"] { --ava: #007aff; }
.ava[data-ava="d64545"] { --ava: #d64545; }

.chat { flex: 1; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; padding: 8px 10px 10px; }
.day { align-self: center; font: 600 13px/1 var(--ios); color: #fff; background: rgba(40, 80, 60, .38); padding: 6px 11px; border-radius: 12px; margin: 6px 0; }
.msg { max-width: 82%; padding: 8px 12px 7px; border-radius: 18px; font-size: 16.5px; line-height: 1.32; white-space: pre-line;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08); position: relative; }
.msg .t { float: right; margin: 8px 0 -4px 10px; font-size: 12px; color: rgba(0, 0, 0, .55); }
.msg--in { align-self: flex-start; background: #fff; border-bottom-left-radius: 6px; }
.msg--out { align-self: flex-end; background: #e2fdc6; border-bottom-right-radius: 6px; }
.msg--out .t { color: #3f9a4b; }
.msg--out .t::after { content: " ✓✓"; }
.msg b { font-weight: 600; }
.msg .sub { display: block; margin-top: 6px; font-size: 13px; color: #3f9a4b; }
.msg--photo { padding: 4px; background: #fff; }
.msg--photo img { display: block; width: 100%; max-width: 260px; border-radius: 14px; }

html.js [data-at].is-hidden { display: none !important; }

.ikb { display: flex; gap: 4px; margin-top: 4px; align-self: flex-start; max-width: 82%; }
.ikb .row { display: flex; gap: 4px; width: 100%; }
.ikb span { flex: 1; text-align: center; padding: 10px 6px; border-radius: 14px; font-size: 15px; font-weight: 500;
  background: rgba(20, 70, 50, .6); color: #fff; backdrop-filter: blur(8px); }
.typing { align-self: flex-start; background: #fff; border-radius: 18px; border-bottom-left-radius: 6px; padding: 13px 14px; display: flex; gap: 5px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: #9aa7a1; animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

@keyframes msg-fade { from { opacity: 0; } }
@keyframes msg-rise {
  from { transform: translateY(1.6em); }
  to { transform: none; }
}
@keyframes rkb-rise {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.pop { animation: msg-fade .2s ease-out, msg-rise .4s cubic-bezier(.38, .7, .125, 1) both; }
.view[data-skin="tg"] .rkb.pop { animation: rkb-rise .4s cubic-bezier(.38, .7, .125, 1) both; }

.inputbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px 30px; }
.inputbar .pill { height: 44px; border-radius: 22px; background: rgba(255, 255, 255, .7); backdrop-filter: blur(10px);
  display: flex; align-items: center; padding: 0 16px; color: #6b746f; font-size: 16px; }
.inputbar .grow { flex: 1; }
.inputbar .menu { background: #2a8f78; color: #fff; font-weight: 600; }
.rkb { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px 10px 0; }
.rkb span { background: rgba(255, 255, 255, .72); border-radius: 12px; padding: 10px 4px; text-align: center; font-size: 15px; line-height: 1.2; }
.rkb:empty { display: none; }

.view[data-skin="max"] .screen,
.view[data-skin="max"] { background: linear-gradient(160deg, #a2cfe0, #93c2f0 55%, #7db3f1); }
.view[data-skin="max"] .chat-head .back,
.view[data-skin="max"] .chat-head .title { background: transparent; backdrop-filter: none; }
.view[data-skin="max"] .title small { color: rgba(6, 7, 8, .52); }
.view[data-skin="max"] .msg--in { background: #ffffff; }
.view[data-skin="max"] .msg--out { background: #edfdff; }
.view[data-skin="max"] .ikb span { height: 40px; display: flex; align-items: center; justify-content: center; padding: 0 6px;
  background: rgba(25, 75, 115, .72); color: #fff; border-radius: 10px; margin: 0; gap: 2px; }
.view[data-skin="max"] .ikb { gap: 2px; max-width: 342px; width: 100%; }
.view[data-skin="max"] .ikb .row { gap: 2px; }
.view[data-skin="max"] .inputbar { background: transparent; }
.view[data-skin="max"] .inputbar .pill { background: #e8eff3; color: #060708; font-family: var(--mx-family, -apple-system, system-ui, 'Helvetica Neue', Roboto, sans-serif); }
.view[data-skin="max"] .inputbar .pill.app { width: 44px; height: 34px; padding: 0; justify-content: center; background: #3478f7; color: #fff; border-radius: 17px; flex: none; }
.view[data-skin="max"] .rkb span { height: 40px; display: flex; align-items: center; justify-content: center; background: rgba(25, 75, 115, .72); color: #fff; border-radius: 10px; }

.view[data-skin="tg"] .chat-head .back,
.view[data-skin="tg"] .chat-head .title {
  background: var(--tg-glass-light);
  backdrop-filter: var(--tg-glass-blur);
  box-shadow: inset 0 0 0 .5px var(--tg-glass-rim), 0 2px 10px rgba(0, 0, 0, .06);
}

@media (prefers-reduced-motion: reduce) {
  .pop, .typing i, .view[data-skin="tg"] .typing i { animation: none; }
  .view, .step { transition: none; }
}
