/* Telegram Mini App — максимально плотный, читаемый UI */

html.is-telegram-webapp {
  --tg-safe-top: env(safe-area-inset-top, 0px);
  --tg-safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.is-telegram-webapp {
  font-size: 12.5px;
  line-height: 1.25;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  background: var(--tg-bg, var(--bg, #f4f7f6));
}

/* убираем старые минимальные правила из style.css — полный набор ниже */
body.is-telegram-webapp .topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: max(0.2rem, var(--tg-safe-top));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

body.is-telegram-webapp .topbar__inner {
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  min-height: 0;
  flex-wrap: wrap;
}

body.is-telegram-webapp .page {
  padding: 0.45rem 0.5rem calc(0.75rem + var(--tg-safe-bottom));
  max-width: none;
}

body.is-telegram-webapp .brand__mark {
  width: 1.35rem;
  height: 1.35rem;
  font-size: 0.7rem;
}

body.is-telegram-webapp .brand__name {
  font-size: 0.88rem;
}

body.is-telegram-webapp .nav {
  gap: 0.15rem;
  order: 3;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

body.is-telegram-webapp .nav::-webkit-scrollbar {
  display: none;
}

body.is-telegram-webapp .nav__link {
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
  white-space: nowrap;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 6%, #fff);
}

body.is-telegram-webapp .nav__link.is-active {
  background: var(--brand);
  color: #fff;
}

body.is-telegram-webapp .role-chip,
body.is-telegram-webapp .topbar__actions .btn--ghost {
  display: none;
}

body.is-telegram-webapp .icon-btn {
  width: 1.85rem;
  height: 1.85rem;
}

body.is-telegram-webapp .panel {
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  box-shadow: none;
}

body.is-telegram-webapp .btn {
  min-height: 2rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

body.is-telegram-webapp .btn--sm {
  min-height: 1.75rem;
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
}

body.is-telegram-webapp .input,
body.is-telegram-webapp .select,
body.is-telegram-webapp textarea.input {
  font-size: 0.8rem;
  padding: 0.32rem 0.45rem;
  border-radius: 7px;
  min-height: 1.9rem;
}

body.is-telegram-webapp .input--sm,
body.is-telegram-webapp .select.input--sm {
  font-size: 0.76rem;
  padding: 0.26rem 0.4rem;
  min-height: 1.7rem;
}

body.is-telegram-webapp .field__label {
  font-size: 0.68rem;
  margin-bottom: 0.15rem;
}

body.is-telegram-webapp .field__hint,
body.is-telegram-webapp .req-list__hint {
  display: none;
}

body.is-telegram-webapp .flash-stack {
  margin-bottom: 0.4rem;
}

body.is-telegram-webapp .flash {
  padding: 0.4rem 0.55rem;
  font-size: 0.72rem;
}

/* ========== Создание заявки / перевозки ========== */

body.is-telegram-webapp.page--req,
body.is-telegram-webapp .page--req {
  padding-top: 0.35rem;
}

body.is-telegram-webapp .req-app {
  grid-template-columns: 1fr;
  gap: 0.45rem;
  font-size: 0.82rem;
}

body.is-telegram-webapp .req-mode-tabs {
  position: sticky;
  top: calc(2.6rem + var(--tg-safe-top));
  z-index: 30;
  gap: 0.3rem;
  margin: 0 0 0.35rem;
  padding: 0.2rem 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}

body.is-telegram-webapp .req-mode-tab {
  flex: 1;
  padding: 0.38rem 0.4rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

body.is-telegram-webapp .req-create,
body.is-telegram-webapp .req-list {
  padding: 0.55rem 0.55rem 0.65rem;
}

body.is-telegram-webapp .req-create__head {
  margin-bottom: 0.45rem;
  gap: 0.35rem;
}

body.is-telegram-webapp .req-title {
  font-size: 1.05rem;
}

body.is-telegram-webapp .req-lead,
body.is-telegram-webapp .catalog-meta {
  display: none;
}

body.is-telegram-webapp .req-fields,
body.is-telegram-webapp .req-fields--transfer {
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

body.is-telegram-webapp .req-fields > .field:last-child,
body.is-telegram-webapp #trFromLabelWrap:not([hidden]),
body.is-telegram-webapp .req-fields--transfer > .field:nth-child(n + 3) {
  grid-column: 1 / -1;
}

body.is-telegram-webapp .req-day-tabs {
  gap: 0.25rem;
}

body.is-telegram-webapp .req-day-tab {
  flex: 1;
  padding: 0.32rem 0.35rem;
  font-size: 0.7rem;
  border-radius: 7px;
  text-align: center;
}

body.is-telegram-webapp .req-day-tab__full {
  display: none;
}

body.is-telegram-webapp .req-day-tab__short {
  display: inline;
}

.req-day-tab__short {
  display: none;
}

body.is-telegram-webapp .req-edit-banner {
  padding: 0.35rem 0.45rem;
  margin-bottom: 0.4rem;
  font-size: 0.7rem;
  border-radius: 7px;
}

body.is-telegram-webapp .field--extra-note {
  margin-bottom: 0.4rem;
}

body.is-telegram-webapp .req-extra-note {
  rows: 2;
  min-height: 2.6rem;
  font-size: 0.76rem;
}

body.is-telegram-webapp textarea.req-extra-note {
  min-height: 2.6rem;
}

/* Таблица позиций: горизонтальный скролл, широкое имя продукта */
body.is-telegram-webapp .lines-scroll {
  margin: 0 -0.15rem 0.35rem;
  padding-bottom: 0.15rem;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

body.is-telegram-webapp .lines-scroll .lines-head,
body.is-telegram-webapp .lines-scroll .lines {
  min-width: 32rem;
}

body.is-telegram-webapp .lines-head--edit > span:nth-child(4),
body.is-telegram-webapp .lines-head--edit > span:nth-child(6),
body.is-telegram-webapp .line-row--edit > .line-row__purchased.is-rolled,
body.is-telegram-webapp .line-row--edit > .line-row__purchased:nth-of-type(2),
body.is-telegram-webapp .line-row--edit > .line-row__target {
  display: none;
}

body.is-telegram-webapp .line-row--edit > .line-row__purchased + .line-row__purchased {
  display: none;
}

body.is-telegram-webapp .lines-head--edit,
body.is-telegram-webapp .line-row--edit {
  grid-template-columns: minmax(14rem, 1.6fr) 4rem 3.6rem 3.2rem 1.5rem;
  gap: 0.35rem;
  align-items: center;
}

body.is-telegram-webapp .lines-head--edit {
  font-size: 0.62rem;
  color: var(--ink-soft);
  padding: 0.15rem 0.2rem;
  margin-bottom: 0.15rem;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
}

body.is-telegram-webapp .lines-head--edit > span:nth-child(4),
body.is-telegram-webapp .lines-head--edit > span:nth-child(6) {
  display: none;
}

body.is-telegram-webapp .line-row {
  padding: 0.32rem 0.2rem;
  border-radius: 7px;
  margin-bottom: 0.2rem;
  border: 1px solid var(--line);
  background: #fff;
}

body.is-telegram-webapp .line-row.is-empty {
  opacity: 0.85;
}

body.is-telegram-webapp .line-row__product {
  min-width: 14rem;
}

body.is-telegram-webapp .line-row__search {
  font-size: 0.8rem;
  padding: 0.32rem 0.4rem;
  min-height: 1.85rem;
  width: 100%;
}

body.is-telegram-webapp .line-row__qty {
  font-size: 0.78rem;
  padding: 0.28rem 0.25rem;
  text-align: center;
  min-width: 3.6rem;
}

body.is-telegram-webapp .line-row__purchased {
  font-size: 0.7rem;
  text-align: center;
}

body.is-telegram-webapp .line-row__unit-select {
  font-size: 0.68rem;
  padding: 0.2rem 0.15rem;
  min-width: 2.8rem;
}

body.is-telegram-webapp .line-row__remove {
  width: 1.45rem;
  height: 1.45rem;
  font-size: 0.85rem;
  border-radius: 6px;
}

/* Перевозка: тот же горизонтальный скролл */
body.is-telegram-webapp .lines-head--transfer > span:nth-child(4),
body.is-telegram-webapp .line-row--transfer > .line-row__purchased + .line-row__purchased {
  display: none;
}

body.is-telegram-webapp .lines-head--transfer,
body.is-telegram-webapp .line-row--transfer {
  grid-template-columns: minmax(14rem, 1.6fr) 4rem 3.8rem 3.4rem 1.5rem;
  gap: 0.35rem;
}

body.is-telegram-webapp .req-actions {
  position: sticky;
  bottom: calc(0.25rem + var(--tg-safe-bottom));
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.55rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
}

body.is-telegram-webapp .req-actions .form-hint {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.68rem;
}

body.is-telegram-webapp .req-actions .btn {
  flex: 1;
}

body.is-telegram-webapp .req-list__title {
  font-size: 0.92rem;
  margin: 0 0 0.35rem;
}

body.is-telegram-webapp .req-card {
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  margin-bottom: 0.35rem;
}

body.is-telegram-webapp .req-card__top {
  gap: 0.3rem;
  font-size: 0.78rem;
}

body.is-telegram-webapp .req-card__meta {
  font-size: 0.66rem;
  margin-top: 0.15rem;
}

body.is-telegram-webapp .status-badge {
  font-size: 0.62rem;
  padding: 0.12rem 0.35rem;
}

body.is-telegram-webapp .suggest {
  font-size: 0.76rem;
  max-height: 40vh;
}

body.is-telegram-webapp .suggest__item {
  padding: 0.4rem 0.5rem;
}

/* ========== Заявки (purchaser / сводка дня) ========== */

body.is-telegram-webapp .page--purchaser {
  padding-top: 0.35rem;
}

body.is-telegram-webapp .pc-app__head {
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

body.is-telegram-webapp .pc-title {
  font-size: 1.05rem;
}

body.is-telegram-webapp .pc-lead {
  display: none;
}

body.is-telegram-webapp .pc-date-row {
  gap: 0.4rem;
  align-items: end;
}

body.is-telegram-webapp .pc-date-row .muted {
  font-size: 0.66rem;
  line-height: 1.2;
}

body.is-telegram-webapp .pc-tabs {
  position: sticky;
  top: calc(2.6rem + var(--tg-safe-top));
  z-index: 30;
  gap: 0.25rem;
  margin-bottom: 0.45rem;
  padding: 0.2rem 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}

body.is-telegram-webapp .pc-tab {
  flex: 1;
  text-align: center;
  padding: 0.38rem 0.3rem;
  font-size: 0.74rem;
  border-radius: 8px;
}

body.is-telegram-webapp .pc-progress-head {
  position: sticky;
  top: calc(5rem + var(--tg-safe-top));
  z-index: 28;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
}

body.is-telegram-webapp .pc-progress-head .muted,
body.is-telegram-webapp .pc-buy-hint {
  font-size: 0.64rem;
  margin: 0 0 0.3rem;
}

body.is-telegram-webapp .pc-actions-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.28rem;
}

body.is-telegram-webapp .pc-actions-row #btnMarkAllPurchases {
  grid-column: 1 / -1;
}

body.is-telegram-webapp .pc-actions-row .btn--primary {
  grid-column: 1 / -1;
}

body.is-telegram-webapp .table-wrap {
  margin: 0 -0.15rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-height: min(62vh, 28rem);
}

body.is-telegram-webapp .pc-summary,
body.is-telegram-webapp .table {
  font-size: 0.7rem;
  min-width: 38rem;
}

body.is-telegram-webapp .pc-summary th,
body.is-telegram-webapp .pc-summary td,
body.is-telegram-webapp .table th,
body.is-telegram-webapp .table td {
  padding: 0.22rem 0.28rem;
  white-space: nowrap;
  vertical-align: middle;
}

/* sticky: галочка строки + наименование */
body.is-telegram-webapp .pc-summary th.pc-col-check,
body.is-telegram-webapp .pc-summary td.pc-col-check {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 1.5rem;
  width: 1.5rem;
  background: #fff;
  box-shadow: none;
}

body.is-telegram-webapp .pc-summary th.pc-col-name,
body.is-telegram-webapp .pc-summary td.pc-col-name {
  position: sticky;
  left: 1.5rem;
  z-index: 2;
  min-width: 11rem;
  max-width: 16rem;
  white-space: normal;
  word-break: break-word;
  line-height: 1.2;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
}

body.is-telegram-webapp .pc-summary thead th.pc-col-check,
body.is-telegram-webapp .pc-summary thead th.pc-col-name {
  z-index: 4;
  background: #f3f6f5;
}

body.is-telegram-webapp .pc-summary thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f3f6f5;
  font-size: 0.6rem;
}

body.is-telegram-webapp .pc-summary th:last-child,
body.is-telegram-webapp .pc-summary td:last-child {
  /* Цель — узко */
  max-width: 3.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.is-telegram-webapp .pc-cell__meta {
  font-size: 0.58rem;
  margin-bottom: 0.12rem;
  line-height: 1.15;
}

body.is-telegram-webapp .pc-cell__buy {
  gap: 0.2rem;
}

body.is-telegram-webapp .pc-check input {
  width: 1rem;
  height: 1rem;
}

body.is-telegram-webapp .pc-summary .input,
body.is-telegram-webapp .pc-buy-input {
  min-width: 2.8rem;
  width: 3.1rem;
  max-width: 3.4rem;
  font-size: 0.7rem;
  padding: 0.18rem 0.2rem;
  min-height: 1.45rem;
}

body.is-telegram-webapp .pc-transfer-card .table th:first-child,
body.is-telegram-webapp .pc-transfer-card .table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 10rem;
  max-width: 14rem;
  white-space: normal;
  word-break: break-word;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
}

body.is-telegram-webapp .pc-move-input {
  min-width: 2.8rem;
  width: 3.1rem;
  font-size: 0.7rem;
  padding: 0.18rem 0.2rem;
  min-height: 1.45rem;
}

body.is-telegram-webapp .pc-day-receipts {
  margin-top: 0.55rem;
  padding-top: 0.4rem;
}

body.is-telegram-webapp .pc-receipt-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: center;
}

body.is-telegram-webapp .pc-receipt-list {
  font-size: 0.72rem;
  gap: 0.25rem;
}

body.is-telegram-webapp .pc-transfer-card {
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
}

body.is-telegram-webapp .pc-transfer-card__head {
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  font-size: 0.76rem;
}

body.is-telegram-webapp .pc-extra-notes,
body.is-telegram-webapp .pc-extra-note-card {
  font-size: 0.72rem;
  padding: 0.4rem 0.5rem;
}

body.is-telegram-webapp .pc-dialog {
  width: min(100vw - 0.6rem, 28rem);
  border-radius: 10px;
  padding: 0;
}

body.is-telegram-webapp .pc-dialog__inner {
  padding: 0.55rem;
}

body.is-telegram-webapp .pc-dialog__title {
  font-size: 0.95rem;
}

body.is-telegram-webapp .pc-card {
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
}

body.is-telegram-webapp .pc-card__title {
  font-size: 0.82rem;
}

body.is-telegram-webapp .pc-card__meta {
  font-size: 0.66rem;
}
