:root { --bg: #0f1216; --card: #171c22; --line: #2a313a; --text: #e7ecf2; --muted: #8b97a6; --accent: #ff6a3d; --ok: #3ccf91; --bad: #ff5c6c; --tap: 44px; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--text); }
img { max-width: 100%; height: auto; }

/* шапка */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 14px; align-items: center; }
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.spent { color: var(--muted); font-size: 13px; white-space: nowrap; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.head--chat { flex-wrap: nowrap; align-items: flex-start; }
.head--chat h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.back { display: none; text-decoration: none; font-size: 22px; line-height: 1; padding: 6px 4px; }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 15px; margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* общие элементы */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 10px 0; }
.card--report { border-color: #3b4552; }
.narrow { max-width: 420px; margin: 40px auto; }
label { display: block; margin: 10px 0; color: var(--muted); }
input, textarea, select { width: 100%; padding: 10px; background: #0b0e12; color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 16px; /* iOS не увеличивает страницу при вводе */ }
button { min-height: var(--tap); padding: 10px 16px; background: var(--accent); color: #111; border: 0; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation; }
button.link { min-height: 0; background: none; color: var(--muted); padding: 0; font-weight: 400; }
button.copy { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.error { color: var(--bad); }
.muted { color: var(--muted); }
.flash { padding: 10px 12px; border-radius: 8px; background: #2a1d20; border: 1px solid var(--bad); }

/* список расчётов */
.list { list-style: none; padding: 0; margin: 0; }
.list a { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 14px 12px; border-bottom: 1px solid var(--line); text-decoration: none; }
.list time { color: var(--muted); font-size: 13px; }
.tag { font-style: normal; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #26303a; white-space: nowrap; }
.tag--agreed { background: #173a2b; color: var(--ok); }
.tag--expensive { background: #3a1a1f; color: var(--bad); }

/* итог разговора */
.outcome-box summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 10px 0; list-style: none; white-space: nowrap; }
.outcome-box summary::-webkit-details-marker { display: none; }
.outcome-box b { color: var(--text); font-weight: 600; }
.outcome { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.outcome select, .outcome input { width: auto; flex: 1 1 140px; }

/* разговор */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.msg { padding: 10px 14px; border-radius: 14px; max-width: 88%; overflow-wrap: anywhere; }
.msg--user { align-self: flex-end; background: #233142; border-bottom-right-radius: 4px; }
.msg--bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.shots { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.shots img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; display: block; background: #0b0e12; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* поле ввода: прилипает к низу экрана, над клавиатурой телефона */
.ask { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.ask__row { display: flex; align-items: flex-end; gap: 8px; }
.ask__add { flex: none; display: grid; place-items: center; width: var(--tap); height: var(--tap); margin: 0; border-radius: 50%; background: #233142; color: var(--text); font-size: 26px; line-height: 1; cursor: pointer; user-select: none; }
.ask__add:active { transform: scale(.94); }
.ask textarea { flex: 1; min-width: 0; min-height: var(--tap); max-height: 40vh; resize: none; overflow-y: hidden; line-height: 1.4; padding: 10px 14px; border-radius: 22px; }
.ask textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ask__send { flex: none; border-radius: 22px; }
.ask__send-icon { display: none; }
.ask__previews { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; -webkit-overflow-scrolling: touch; }
.ask__preview { position: relative; flex: none; }
.ask__preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.ask__preview button { position: absolute; top: -6px; right: -6px; min-height: 0; width: 24px; height: 24px; padding: 0; border-radius: 50%; background: #000c; color: #fff; font-size: 14px; line-height: 24px; }
.ask__error { margin: 0 0 6px; font-size: 14px; }
.ask.is-busy .ask__send, .ask.is-busy .ask__add { opacity: .5; pointer-events: none; }
.ask.is-drop { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* таблица расчёта */
.quote { background: #12161b; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.quote summary { cursor: pointer; }
.quote table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.quote th, .quote td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sums { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; margin: 8px 0; }
.sums div { min-width: 0; }
.sums dt { color: var(--muted); font-size: 12px; }
.sums dd { margin: 0; font-weight: 600; }
.note { font-size: 13px; color: var(--muted); margin: 4px 0; }
.qr svg { max-width: 220px; height: auto; background: #fff; border-radius: 8px; }

/* телефон */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .top { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .brand { font-size: 15px; }
  .brand__sub { display: none; }
  .top nav { gap: 12px; font-size: 14px; }
  .spent { font-size: 12px; }
  .wrap { padding: 12px; }
  h1 { font-size: 18px; margin: 4px 0 10px; }
  .back { display: block; }
  .head--chat { gap: 4px 8px; flex-wrap: wrap; }
  .outcome-box { flex-basis: 100%; order: 3; }
  .outcome-box summary { padding: 0 0 8px; }
  /* таблица расчёта на телефоне — карточками: название и сумма, ниже «кол-во × цена», ещё ниже пояснение */
  .quote table, .quote tbody { display: block; overflow: visible; }
  .quote thead { display: none; }
  .quote tr { display: grid; grid-template-columns: max-content max-content 1fr max-content; gap: 0 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .quote td { border: 0; padding: 0; }
  .quote td:nth-child(1) { grid-column: 1 / 4; }
  .quote td:nth-child(4) { grid-column: 4; grid-row: 1 / 3; align-self: center; font-weight: 600; white-space: nowrap; }
  .quote td:nth-child(4)::after { content: " ₽"; }
  .quote td:nth-child(2), .quote td:nth-child(3) { grid-row: 2; color: var(--muted); }
  .quote td:nth-child(2)::after { content: " ×"; }
  .quote td:nth-child(3)::after { content: " ₽"; }
  .quote td:nth-child(5) { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
  .quote td:nth-child(5):empty { display: none; }
  .list a { grid-template-columns: 1fr auto; }
  .list time { grid-column: 1 / -1; }
  .msg { max-width: 94%; }
  .card { padding: 12px; }
  .sums { grid-template-columns: 1fr 1fr; }
  .ask { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .ask__send { width: var(--tap); padding: 0; border-radius: 50%; }
  .ask__send-text { display: none; }
  .ask__send-icon { display: inline; font-size: 18px; }
}
@media (max-width: 360px) { .spent { display: none; } }
