html, body { height: 100%; }
body { background: var(--white); font-size: 17px; line-height: 1.55; overflow: hidden; }
html.big body { font-size: 20px; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 48px; height: 48px; border: 0; border-radius: 14px; background: none; cursor: pointer;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:hover { background: var(--sun-soft); }
.icon-btn[aria-pressed="true"] { background: var(--sun); }

.link-btn { border: 0; background: none; padding: 0; font-weight: 700; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

/* ---------- каркас */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }

.side {
  display: flex; flex-direction: column; gap: 18px; min-height: 0;
  padding: 18px 16px 16px; background: var(--paper); border-right: 1px solid var(--hair);
}
.side__head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 0; }
.side__close { display: none; }
.side__new { width: 100%; min-height: 52px; font-size: 17px; }

.history { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.history__day { margin: 16px 10px 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.history a {
  display: block; padding: 10px 12px; border-radius: 12px; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history a:hover { background: var(--sun-soft); }
.history a.is-active { background: var(--white); box-shadow: 0 1px 3px rgba(30, 26, 20, .12); font-weight: 600; }

.plan-box { padding: 16px; background: var(--white); border: 1px solid var(--hair); border-radius: var(--r-md); display: grid; gap: 12px; font-size: 15px; }
.plan-box__head { display: flex; justify-content: space-between; align-items: baseline; }
.plan-box__head b { font-family: var(--display); font-size: 16px; }
.plan-box__head span { color: var(--muted); font-size: 14px; }
.meter__row { display: flex; justify-content: space-between; margin-bottom: 5px; }
.meter__bar { height: 8px; border-radius: 999px; overflow: hidden; background: #efe9dc; }
.meter__bar i { display: block; height: 100%; background: var(--sun-deep); border-radius: 999px; }
.plan-box__note { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.plan-box .link-btn { justify-self: start; font-size: 15px; }

.scrim { display: none; }

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

.bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 68px; }
.bar__menu, .bar__logo { display: none; }
.bar__right { margin-left: auto; display: flex; gap: 4px; }

/* ---------- лента */
.thread { flex: 1; overflow-y: auto; padding: 8px 20px 24px; scroll-behavior: smooth; }
.thread > * { max-width: 760px; margin-inline: auto; }

.hello { display: none; text-align: center; padding: 6vh 0 12px; }
.app.is-empty .hello { display: block; }
.app.is-empty .messages { display: none; }
.hello__mark { width: 132px; height: auto; margin: 0 auto 12px; }
.hello h1 { font-family: var(--display); font-weight: 700; font-size: clamp(26px, 4vw, 36px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 10px; }
.hello > p { margin: 0 0 30px; color: var(--muted); font-size: 1.05em; }
.starts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; }
.starts button {
  display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 18px;
  background: var(--white); border: 1.5px solid var(--hair); border-radius: var(--r-md);
  font-weight: 600; font-size: 1em; line-height: 1.3; text-align: left; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.starts button:hover { border-color: var(--ink); }
.starts button:active { transform: translateY(1px); }
.starts svg { width: 44px; height: 44px; flex: none; padding: 10px; border-radius: 12px; background: var(--sun-soft); }
.starts__img { grid-column: 1 / -1; background: var(--night) !important; color: var(--white); border-color: var(--night) !important; }
.starts__img svg { background: var(--sun); color: var(--ink); }

.messages { display: flex; flex-direction: column; gap: 28px; padding-top: 12px; }
.m p { margin: 0 0 12px; }
.m p:last-child { margin-bottom: 0; }
.m--me { align-self: flex-end; max-width: 82%; }
.m--me p {
  background: var(--sun-soft); border-radius: 22px 22px 6px 22px;
  padding: 12px 18px; font-weight: 500;
}
.m--ai { display: grid; grid-template-columns: 40px 1fr; gap: 14px; }
.m__av { width: 40px; height: auto; margin-top: -4px; }
.m__body { min-width: 0; }
.m__body ul { margin: 0 0 12px; padding-left: 1.2em; }
.m__body li { margin-bottom: 6px; }
.m__body li::marker { color: var(--flame); }
.doc {
  margin: 4px 0 18px; padding: 18px 20px; background: var(--paper);
  border: 1px solid var(--hair); border-left: 4px solid var(--sun-deep); border-radius: var(--r-sm); font-size: .95em;
}
.doc__title { text-align: center; font-weight: 700; }
.m__tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.m__tools button {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  background: var(--white); border: 1.5px solid var(--hair); border-radius: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.m__tools button:hover { border-color: var(--line); }
.m__tools svg { width: 20px; height: 20px; }
.typing .cursor { display: inline-block; width: 9px; height: 1.05em; background: var(--flame); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- поле ввода */
.composer { padding: 6px 20px max(14px, env(safe-area-inset-bottom)); }
.composer > * { max-width: 760px; margin-inline: auto; }

.mode { display: flex; gap: 8px; margin-bottom: 10px; }
.mode button {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 16px 0 12px;
  border: 1.5px solid var(--hair); border-radius: 12px; background: var(--white);
  font-weight: 700; font-size: 15px; cursor: pointer;
}
.mode button svg { width: 20px; height: 20px; flex: none; }
.mode button small { font-weight: 500; color: var(--muted); font-size: 14px; white-space: nowrap; }
.mode button[aria-checked="true"] { background: var(--sun); border-color: var(--sun); }
.mode button[aria-checked="true"] small { color: var(--ink); }

.box {
  display: flex; align-items: flex-end; gap: 4px; padding: 6px;
  background: var(--white); border: 1.5px solid #cfc8b8; border-radius: 22px; box-shadow: var(--pop);
}
.box:focus-within { border-color: var(--ink); }
.box textarea {
  flex: 1; min-height: 48px; max-height: 40vh; resize: none; border: 0; outline: 0; background: none;
  padding: 11px 6px; font-size: 1.05em; line-height: 1.4;
}
.box textarea::placeholder { color: #8d8472; }
.box__send {
  display: grid; place-items: center; flex: none; width: 48px; height: 48px;
  border: 0; border-radius: 14px; background: var(--sun); cursor: pointer;
}
.box__send svg { width: 24px; height: 24px; }
.box__send:disabled { background: #f1ede4; color: #a59a80; cursor: default; }
.composer__hint { margin-top: 8px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- оплата */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.sheet[hidden] { display: none; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(30, 26, 20, .55); }
.sheet__panel {
  position: relative; width: min(520px, 100% - 32px); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--white); border-radius: var(--r-lg); box-shadow: 0 30px 80px rgba(0, 0, 0, .3);
  padding: 30px 28px 24px; animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet__close { position: absolute; right: 12px; top: 12px; }
.sheet__mark { width: 84px; height: auto; margin-bottom: 10px; }
.sheet h2 { font-family: var(--display); font-weight: 700; font-size: 28px; letter-spacing: -.02em; margin: 0 0 6px; }
.sheet__lead { margin: 0 0 22px; color: var(--muted); }
.sheet__label { margin: 22px 0 10px; font-weight: 700; }

.tariffs { display: grid; gap: 12px; }
.tariff {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 16px 18px; border: 1.5px solid var(--hair); border-radius: var(--r-md); cursor: pointer;
}
.tariff:has(input:checked) { border-color: var(--ink); background: var(--sun-soft); }
.tariff input, .method input {
  appearance: none; margin: 0; width: 24px; height: 24px; border: 1.5px solid #a59a80; border-radius: 50%; background: var(--white);
}
.tariff input:checked, .method input:checked { border: 7px solid var(--ink); }
.tariff__main b { display: block; font-family: var(--display); font-size: 19px; }
.tariff__main span { display: block; font-size: 15px; line-height: 1.35; margin-top: 2px; }
.tariff__price { text-align: right; font-family: var(--display); font-weight: 800; font-size: 21px; white-space: nowrap; }
.tariff__price small { display: block; font-family: var(--text); font-weight: 500; font-size: 13px; }

.methods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.method {
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  padding: 14px; border: 1.5px solid var(--hair); border-radius: var(--r-md); cursor: pointer;
}
.method input { grid-row: span 2; }
.method svg { display: none; }
.method span { font-weight: 700; }
.method small { grid-column: 2; color: var(--muted); font-size: 13px; line-height: 1.3; }
.method:has(input:checked) { border-color: var(--ink); }
.sheet__pay { width: 100%; margin-top: 24px; min-height: 62px; font-size: 20px; }
.sheet__fine { margin: 12px 0 0; text-align: center; font-size: 14px; color: var(--muted); }

/* ---------- планшет: панель прячется в меню */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(340px, 86vw);
    transform: translateX(-105%); transition: transform .25s ease; box-shadow: 0 0 60px rgba(0, 0, 0, .25);
  }
  .app.side-open .side { transform: none; }
  .side__close { display: inline-grid; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(30, 26, 20, .5); }
  .app.side-open .scrim { display: block; }
  .bar { border-bottom: 1px solid var(--hair); }
  .bar__menu { display: inline-grid; }
  .bar__logo { display: inline-flex; font-size: 18px; }
  .bar__logo svg { width: 30px; }
}

/* ---------- телефон */
@media (max-width: 600px) {
  .bar { padding: 8px 8px; min-height: 60px; }
  .thread { padding: 4px 14px 16px; }
  .hello { padding-top: 3vh; }
  .hello__mark { width: 96px; }
  .starts { grid-template-columns: 1fr; gap: 10px; }
  .starts button { min-height: 64px; }
  .starts__img { grid-column: auto; }
  .m--me { max-width: 90%; }
  .m--ai { grid-template-columns: 1fr; gap: 8px; }
  .m__av { width: 34px; }
  .doc { padding: 14px; }
  .composer { padding-inline: 10px; }
  .mode button { flex: 1; justify-content: center; padding: 0 8px; min-height: 48px; font-size: 16px; }
  .mode button[data-mode="fast"] small { display: none; }
  .box { border-radius: 20px; box-shadow: var(--pop-sm); }
  .box__photo { width: 42px; }
  .composer__hint { display: none; }
  .sheet { place-items: end stretch; }
  .sheet__panel {
    width: 100%; max-height: 92dvh; border-radius: 26px 26px 0 0; box-shadow: none;
    padding: 26px 18px max(18px, env(safe-area-inset-bottom));
  }
  .tariff { padding: 14px; gap: 12px; }
}

/* ---------- состояния живого чата */
.history__empty { margin: 16px 10px; color: var(--muted); font-size: 15px; }
.m__body .h { font-weight: 700; font-size: 1.05em; margin-top: 4px; }
.m__body pre { white-space: pre-wrap; background: var(--paper); border: 1px solid var(--hair); border-radius: var(--r-sm); padding: 12px 14px; font-size: .9em; overflow-x: auto; }
.m__body code { background: var(--paper); border-radius: 6px; padding: 1px 5px; font-size: .92em; }
.m__body .cursor { display: inline-block; width: 9px; height: 1.05em; background: var(--sun-deep); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2) infinite; }
.m__body .err { color: var(--danger); font-weight: 600; }
.dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--sun-deep); animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.toast {
  position: fixed; z-index: 80; left: 50%; bottom: 120px; translate: -50% 12px; opacity: 0;
  max-width: min(460px, calc(100% - 32px)); padding: 14px 18px; border-radius: 14px;
  background: var(--night); color: var(--white); font-size: 16px; line-height: 1.4; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25); transition: opacity .2s, translate .2s;
}
.toast.is-on { opacity: 1; translate: -50% 0; }

.gate { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; background: var(--night); }
.gate[hidden] { display: none; }
.gate__card { max-width: 420px; text-align: center; color: var(--white); }
.gate__card img { width: 160px; height: auto; margin: 0 auto 10px; }
.gate__card h2 { font-family: var(--display); font-size: 28px; line-height: 1.15; margin: 0 0 12px; }
.gate__card p { color: rgba(255, 255, 255, .72); margin: 0 0 24px; }
.gate__card .btn { background: var(--sun); color: var(--ink); width: 100%; }
