:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-secondary-bg-color: #efeff3;
  --tg-theme-section-bg-color: #ffffff;
  --tg-theme-section-separator-color: rgba(60, 60, 67, 0.18);
  --tg-theme-section-header-text-color: #e87722;
  --tg-theme-text-color: #000000;
  --tg-theme-hint-color: #8e8e93;
  --tg-theme-subtitle-text-color: #8e8e93;
  --tg-theme-button-color: #e87722;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-link-color: #e87722;
  --tg-theme-accent-text-color: #e87722;
  --tg-theme-destructive-text-color: #ff3b30;
  --tg-theme-header-bg-color: #efeff3;
  --tg-theme-bottom-bar-bg-color: #f7f7f8;
  --brand: #e87722;
  --brand-soft: rgba(232, 119, 34, 0.16);
  --inset-top: 0px;
  --inset-bottom: 0px;
  --inset-left: 0px;
  --inset-right: 0px;
  --app-height: 100dvh;
  --tabbar-h: 56px;
  --composer-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tg-theme-bg-color: #1c1c1d;
    --tg-theme-secondary-bg-color: #000000;
    --tg-theme-section-bg-color: #1c1c1d;
    --tg-theme-section-separator-color: rgba(84, 84, 88, 0.65);
    --tg-theme-section-header-text-color: #e87722;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-subtitle-text-color: #8e8e93;
    --tg-theme-button-color: #e87722;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-link-color: #e87722;
    --tg-theme-accent-text-color: #e87722;
    --tg-theme-header-bg-color: #1c1c1d;
    --tg-theme-bottom-bar-bg-color: #1c1c1d;
  }
}

* { box-sizing: border-box; }
html {
  margin: 0;
  height: var(--app-height);
  background: var(--tg-theme-secondary-bg-color);
}
body {
  margin: 0 auto;
  width: 100%;
  max-width: 430px;
  height: var(--app-height);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-left: var(--inset-left);
  padding-right: var(--inset-right);
}
.hidden { display: none !important; }

#app {
  flex: 1;
  min-height: 0;
  margin-top: var(--inset-top);
  overflow: hidden;
}
.view {
  height: 100%;
  overflow: hidden;
}
#view-ask {
  display: flex;
  flex-direction: column;
  background: var(--tg-theme-bg-color);
}
#view-ask.hidden { display: none !important; }

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1rem;
}
.bubble.bot {
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}
.bubble.user {
  background: var(--brand);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.bubble.busy {
  color: var(--tg-theme-hint-color);
  font-style: italic;
  background: var(--tg-theme-secondary-bg-color);
}

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--tg-theme-bg-color);
  border-top: 0.5px solid var(--tg-theme-section-separator-color);
}
#view-ask.hidden .composer { display: none; }
.composer input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 20px;
  padding: 8px 14px;
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 1rem;
  outline: none;
}
.composer input::placeholder { color: var(--tg-theme-hint-color); }
.send {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send:disabled { opacity: 0.45; }

.page { padding: 12px 16px 24px; }
.section-label {
  margin: 8px 16px 8px;
  padding: 0;
  font-size: 0.81rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
}
.page .section-label { margin-left: 4px; }
.caption {
  margin: 0 4px 12px;
  font-size: 0.81rem;
  line-height: 1.35;
  color: var(--tg-theme-hint-color);
}
.caption.center { text-align: center; margin: 14px 8px 0; }

.group {
  background: var(--tg-theme-section-bg-color);
  border-radius: 12px;
  overflow: hidden;
}
[data-platform="android"] .group { border-radius: 8px; }

.cell {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--tg-theme-text-color);
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.cell + .cell::before {
  content: "";
  position: absolute;
  left: 52px;
  right: 0;
  top: 0;
  height: 0.5px;
  background: var(--tg-theme-section-separator-color);
}
.cell-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
}
.cell-title { flex: 1; font-weight: 400; }
.cell-chevron {
  color: var(--tg-theme-hint-color);
  font-size: 22px;
  line-height: 1;
  font-weight: 300;
}
.cell:active { background: var(--brand-soft); }
.skeleton .cell-title {
  height: 12px;
  width: 46%;
  border-radius: 6px;
  background: var(--tg-theme-section-separator-color);
}

.back-fallback {
  margin: 0 0 10px;
  padding: 8px 0;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.photo-card {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--tg-theme-section-bg-color);
  color: var(--tg-theme-text-color);
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
}
.photo-card img,
.photo-card .photo-fallback {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--tg-theme-section-bg-color);
}
.photo-card .photo-fallback {
  display: grid;
  place-items: center;
  font-size: 2rem;
  background: var(--brand-soft);
}
.photo-card span {
  display: block;
  padding: 8px 10px 10px;
  font-size: 0.94rem;
  font-weight: 600;
}
.photo-grid.skeleton .photo-card {
  aspect-ratio: 1 / 1;
  background: var(--tg-theme-section-bg-color);
}
.tool-image {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--tg-theme-section-bg-color);
}
.detail-title {
  margin: 0;
  padding: 14px 16px 6px;
  font-size: 1.25rem;
  font-weight: 700;
}
.seg {
  display: flex;
  margin: 8px 12px 12px;
  padding: 3px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 9px;
}
.seg-btn {
  flex: 1;
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--tg-theme-hint-color);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--tg-theme-section-bg-color);
  color: var(--brand);
  box-shadow: 0 0.5px 2px rgba(0, 0, 0, 0.12);
}
html.lite .seg-btn.active { box-shadow: none; }
.article {
  padding: 4px 16px 18px;
  font-size: 1rem;
  color: var(--tg-theme-text-color);
}

.plastic {
  position: relative;
  margin-top: 4px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--tg-theme-section-bg-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
html.lite .plastic { box-shadow: none; }
.plastic-stripe {
  height: 6px;
  background: linear-gradient(90deg, #c45e12, var(--brand) 45%, #f0a35c);
}
.plastic-top {
  padding: 16px 16px 10px;
}
.plastic-top span {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 600;
}
.plastic-top strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}
.barcode-wrap {
  margin: 8px 12px 16px;
  padding: 14px 10px 8px;
  background: #fff;
  border-radius: 10px;
  display: flex;
  justify-content: center;
}
.barcode-wrap img {
  width: min(100%, 340px);
  height: auto;
  display: block;
  background: #fff;
  image-rendering: -webkit-optimize-contrast;
}

.tabbar {
  flex-shrink: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  height: calc(var(--tabbar-h) + var(--inset-bottom));
  padding-bottom: var(--inset-bottom);
  background: var(--tg-theme-bottom-bar-bg-color);
  border-top: 0.5px solid var(--tg-theme-section-separator-color);
}
.tab {
  border: 0;
  background: transparent;
  color: var(--tg-theme-hint-color);
  font: inherit;
  font-size: 0.63rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  min-height: 44px;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { color: var(--brand); }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.page-head .section-label { margin-right: 0; }
.admin-tools { display: flex; gap: 12px; flex-shrink: 0; }
.admin-tools.hidden { display: none !important; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
}
.blog-card {
  width: 100%;
  display: block;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--tg-theme-section-bg-color);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.blog-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--tg-theme-section-bg-color);
}
.blog-card .blog-meta { padding: 10px 12px 12px; }
.blog-card .blog-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--brand);
}
.blog-card h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.blog-empty { color: var(--tg-theme-hint-color); font-size: 0.94rem; padding: 8px 4px; }
.article-source {
  margin: 0;
  padding: 14px 16px 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
}
.article-card .tool-image {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
.admin-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.admin-row + .admin-row::before {
  content: "";
  position: absolute;
  left: 14px;
  right: 0;
  top: 0;
  height: 0.5px;
  background: var(--tg-theme-section-separator-color);
}
.admin-row strong { display: block; font-size: 1rem; }
.admin-row small { color: var(--tg-theme-hint-color); font-size: 0.81rem; }
.badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--brand);
}
.badge.off { color: var(--tg-theme-hint-color); }
.form-card { padding: 12px 14px 16px; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 12px;
  font-size: 0.81rem;
  font-weight: 600;
  color: var(--tg-theme-hint-color);
}
.field input, .field textarea {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font: inherit;
  font-weight: 400;
  font-size: 1rem;
  outline: none;
}
.field textarea { resize: vertical; min-height: 160px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 14px;
  min-height: 44px;
  font-size: 0.94rem;
}
.form-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 10px;
  margin: 0 0 12px;
  background: var(--tg-theme-secondary-bg-color);
}
.admin-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.admin-actions .btn { flex: 1; }
.btn-danger {
  background: var(--tg-theme-destructive-text-color, #ff3b30);
  color: #fff;
}

#view-blog, #view-manual, #view-card {
  background: var(--tg-theme-secondary-bg-color);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.45);
}
.overlay-card {
  width: min(100%, 340px);
  padding: 22px 18px;
  border-radius: 14px;
  background: var(--tg-theme-section-bg-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.overlay-card h2 { margin: 0; font-size: 1.2rem; }
.overlay-card p { margin: 0; color: var(--tg-theme-hint-color); font-size: 0.94rem; }
.btn, .seg-btn, .tab, .cell, .send, .back-fallback { -webkit-tap-highlight-color: transparent; }
.btn {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-ghost {
  background: transparent;
  color: var(--brand);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
