/* Тема: значения берём из Telegram, вне Telegram — светлая/тёмная по системе. */
:root {
  --bg: #ffffff;
  --section: #ffffff;
  --secondary: #f2f3f5;
  --text: #1f2328;
  --hint: #707579;
  --link: #2f6fed;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --border: rgba(16, 24, 40, 0.08);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 28px rgba(16, 24, 40, 0.05);
}

html[data-theme="dark"] {
  --bg: #17212b;
  --section: #1e2a36;
  --secondary: #232f3b;
  --text: #f1f4f7;
  --hint: #8d9aa8;
  --link: #6ea8ff;
  --accent: #4c8dff;
  --accent-text: #ffffff;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

a {
  color: var(--link);
  text-decoration: none;
}

/* Верхняя панель */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top) * 0);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
}

.brand__name {
  letter-spacing: 0.2px;
}

.brand__note {
  color: var(--hint);
  font-size: 12px;
}

/* Страницы */
.pages {
  padding: 16px 16px 8px;
}

.page {
  display: none;
}

.page.is-active {
  display: block;
  animation: fade 0.18s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.page__title {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.2;
}

.page__hint {
  margin: 0 0 16px;
  color: var(--hint);
  font-size: 13.5px;
}

/* Поиск */
.search__input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
  outline: none;
}

.search__input::placeholder {
  color: var(--hint);
}

.search__input:focus {
  border-color: var(--accent);
}

/* Фильтры */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

/* Карточки */
.cards {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.card {
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--section);
  box-shadow: var(--shadow);
}

.card__top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card__meta {
  margin: 3px 0 0;
  color: var(--hint);
  font-size: 13px;
}

.card__price {
  flex: 0 0 auto;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.card__price--muted {
  color: var(--hint);
  font-weight: 500;
}

.empty {
  padding: 28px 8px;
  color: var(--hint);
  text-align: center;
  font-size: 14px;
}

.note {
  margin: 14px 0 0;
  color: var(--hint);
  font-size: 12.5px;
}

/* Кнопки */
.button {
  display: block;
  width: 100%;
  margin: 18px 0 0;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button:active {
  opacity: 0.85;
}

.button--ghost {
  margin-top: 18px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
}

.button--compact {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 11px 18px;
}

/* Форма поиска по артикулу */
.search {
  display: flex;
  gap: 8px;
}

.search__input {
  flex: 1 1 auto;
}

/* Результат поиска */
.status {
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--hint);
  font-size: 13.5px;
  text-align: center;
}

/* Список запчастей */
.basket {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 15;
  max-height: 46vh;
  overflow-y: auto;
  padding: 12px 16px 14px;
  background: color-mix(in srgb, var(--section) 96%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 30px rgba(16, 24, 40, 0.12);
}

.basket[hidden] {
  display: none;
}

.basket__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.basket__handle {
  width: 44px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: var(--hint);
  opacity: 0.35;
}

.basket.is-collapsed {
  max-height: none;
  overflow: hidden;
}

.basket.is-collapsed .basket__items,
.basket.is-collapsed .basket__footer {
  display: none;
}

.basket__footer {
  margin-top: 10px;
}

.basket__title {
  font-weight: 600;
  font-size: 14.5px;
}

.basket__total {
  color: var(--hint);
  font-size: 12.5px;
}

.basket__row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.basket__row:last-child {
  border-bottom: 0;
}

.basket__name {
  font-size: 13.5px;
  line-height: 1.3;
}

.basket__meta {
  margin-top: 2px;
  color: var(--hint);
  font-size: 11.5px;
}

.basket__qty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.qty-btn:active {
  opacity: 0.7;
}

.basket__count {
  min-width: 18px;
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.basket__sum {
  min-width: 72px;
  text-align: right;
  font-size: 13.5px;
  font-weight: 600;
}

/* Маленькая кнопка в карточке */
.button--small {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 13.5px;
}

.button--in-basket {
  background: var(--secondary);
  border: 1px solid var(--accent);
  color: var(--accent);
}

/* Вступительный текст на экране услуг */
.page__text {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
}

/* Плитки прайсов */
.price-tiles {
  display: grid;
  gap: 10px;
}

.price-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--section);
  box-shadow: var(--shadow);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.price-tile:active {
  opacity: 0.9;
}

.price-tile__hint {
  display: block;
  margin-top: 4px;
  color: var(--hint);
  font-size: 12px;
  font-weight: 400;
}

.price-tile__arrow {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

/* Модальное окно с прайсом */
.modal__card--wide {
  max-width: 460px;
  padding: 16px 14px 14px;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.modal__title {
  margin: 0;
  font-size: 16px;
}

.modal__close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: var(--secondary);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.price-table-wrap {
  max-height: 58vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.price-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.price-table th,
.price-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.price-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--section);
  color: var(--hint);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.price-table thead th:first-child {
  text-align: left;
}

.price-table tbody th {
  text-align: left;
  font-weight: 400;
  white-space: normal;
}

.price-table tbody td {
  text-align: right;
  white-space: nowrap;
}

.price-table tbody tr:last-child th,
.price-table tbody tr:last-child td {
  border-bottom: 0;
}

/* Модальное окно подтверждения */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 12, 17, 0.55);
}

.modal[hidden] {
  display: none;
}

.modal__card {
  width: 100%;
  max-width: 340px;
  padding: 18px 16px 14px;
  border-radius: 16px;
  background: var(--section);
  box-shadow: var(--shadow);
}

.modal__text {
  margin: 0 0 14px;
  font-size: 14.5px;
  line-height: 1.4;
}

.modal__actions {
  display: flex;
  gap: 8px;
}

.modal__actions .button {
  flex: 1 1 0;
  margin: 0;
  padding: 12px;
  font-size: 14px;
}

.part__facts {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  font-size: 13.5px;
}

.part__fact {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.part__fact span:first-child {
  color: var(--hint);
}

/* Форма */
.form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  color: var(--hint);
  font-size: 12.5px;
}

.field__input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
  outline: none;
  resize: vertical;
}

.field__input:focus {
  border-color: var(--accent);
}

.field__input.is-invalid {
  border-color: #e5484d;
}

.field__file {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--secondary);
  color: var(--hint);
  font: inherit;
  font-size: 12.5px;
}

.field__file::file-selector-button {
  margin-right: 10px;
  padding: 8px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.field__hint {
  color: var(--hint);
  font-size: 12px;
}

/* Контакты */
.contacts {
  margin-top: 22px;
}

.contacts__title {
  margin: 0 0 8px;
  font-size: 15px;
}

.contact {
  display: grid;
  gap: 2px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.contact:last-child {
  border-bottom: 0;
}

.contact__label {
  color: var(--hint);
  font-size: 12px;
}

.contact__value {
  font-size: 14px;
}

/* Нижняя навигация */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.tab {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 6px 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 10.5px;
  cursor: pointer;
}

.tab__label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab__icon {
  font-size: 17px;
  line-height: 1;
}

.tab.is-active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Уведомление */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  text-align: center;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 520px) {
  .pages {
    max-width: 520px;
    margin: 0 auto;
  }

  .tabbar {
    max-width: 520px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
