:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --radius: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--secondary-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--hint);
}

.center {
  text-align: center;
  padding: 48px 16px;
}

/* --- Topbar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
}

.cart-btn {
  position: relative;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
}

.cart-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  background: var(--destructive);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  text-align: center;
  padding: 0 4px;
}

/* --- Content --- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 88px;
}

/* --- Cards / list --- */
.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row-between {
  justify-content: space-between;
}

.grow {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 16px;
  word-break: break-word;
}

.item-sub {
  color: var(--hint);
  font-size: 13px;
  margin-top: 2px;
}

.price {
  font-weight: 600;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--secondary-bg);
  color: var(--hint);
}

.badge.ok {
  background: rgba(52, 199, 89, 0.15);
  color: #2e9e4f;
}

.badge.low {
  background: rgba(255, 149, 0, 0.18);
  color: #c77700;
}

.badge.out {
  background: rgba(229, 57, 53, 0.15);
  color: var(--destructive);
}

.badge.new {
  background: rgba(36, 129, 204, 0.15);
  color: var(--link);
}

.badge.completed {
  background: rgba(52, 199, 89, 0.15);
  color: #2e9e4f;
}

.badge.cancelled {
  background: rgba(229, 57, 53, 0.15);
  color: var(--destructive);
}

/* --- Buttons --- */
button {
  font-family: inherit;
  font-size: 15px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
}

.btn-block {
  width: 100%;
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

.btn-danger {
  background: rgba(229, 57, 53, 0.12);
  color: var(--destructive);
}

.btn-success {
  background: rgba(52, 199, 89, 0.15);
  color: #2e9e4f;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 14px;
  border-radius: 9px;
}

/* --- Stepper --- */
.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper .qty {
  min-width: 24px;
  text-align: center;
  font-weight: 600;
}

/* --- Tabbar --- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 4px 6px;
  color: var(--hint);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
}

.tab .tab-icon {
  font-size: 20px;
}

.tab.active {
  color: var(--link);
}

/* --- Forms --- */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 5px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
}

.section-title {
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 18px 4px 8px;
}

/* --- Overlay / sheet --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(40px);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 600;
}

.sheet-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--hint);
  cursor: pointer;
  line-height: 1;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 40;
  max-width: 90%;
  text-align: center;
}

.toast.error {
  background: var(--destructive);
}

.empty {
  text-align: center;
  color: var(--hint);
  padding: 56px 16px;
}

.empty .emoji {
  font-size: 40px;
  display: block;
  margin-bottom: 10px;
}

hr.sep {
  border: none;
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  margin: 10px 0;
}

.total-line {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  margin: 12px 4px;
}

.order-meta {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
}

.li {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}

/* --- Фильтр-панель --- */
.filterbar {
  margin-bottom: 10px;
}

.filterbar .search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 8px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.chip {
  flex: 0 0 auto;
  border: none;
  padding: 7px 14px;
  border-radius: 18px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--button);
  color: var(--button-text);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar .sort {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--hint);
  white-space: nowrap;
  cursor: pointer;
}

.toggle input {
  width: 16px;
  height: 16px;
}

.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

/* --- Миниатюра в карточке --- */
.thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background: var(--secondary-bg);
  cursor: pointer;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  opacity: 0.5;
  cursor: default;
}

.thumb-more {
  position: absolute;
  right: 2px;
  bottom: 2px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
}

/* --- Артикулы в карточке --- */
.arts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 2px;
}

.art {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--secondary-bg);
  color: var(--hint);
  padding: 1px 6px;
  border-radius: 6px;
}

/* --- Чипсы-инпут (артикулы в форме) --- */
.chips-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: 10px;
  background: var(--bg);
}

.chips-input input {
  flex: 1;
  min-width: 120px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 4px;
}

.chip-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 4px 8px;
  border-radius: 8px;
}

.chip-tag button {
  border: none;
  background: none;
  color: var(--hint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

/* --- Сетка фото в форме --- */
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

.img-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--secondary-bg);
}

.img-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.img-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.img-setmain,
.img-main,
.img-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  padding: 2px 6px;
  cursor: pointer;
}

.img-setmain {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.img-main {
  background: var(--button);
  color: var(--button-text);
}

.img-badge {
  background: rgba(52, 199, 89, 0.9);
  color: #fff;
  cursor: default;
}

/* --- Галерея --- */
.gallery-main {
  width: 100%;
  background: var(--secondary-bg);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 70vh;
}

.gallery-main img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.gallery-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
}

.gallery-count {
  font-size: 14px;
  color: var(--hint);
  min-width: 56px;
  text-align: center;
}
