:root {
  color-scheme: light;
  --turgus-green: #2b843f;
  --turgus-green-dark: #246f37;
  --turgus-green-pressed: #246f37;
  --turgus-green-soft: #eaf5ea;
  --turgus-surface: var(--tg-theme-bg-color, #ffffff);
  --turgus-surface-muted: var(--tg-theme-secondary-bg-color, #f3f6f3);
  --turgus-page: var(--tg-theme-secondary-bg-color, #f4f7f4);
  --turgus-border: #dce5dc;
  --turgus-text: var(--tg-theme-text-color, #172019);
  --turgus-muted: var(--tg-theme-hint-color, #68746b);
  --turgus-link: var(--tg-theme-link-color, #2481cc);
  --turgus-button-text: var(--tg-theme-button-text-color, #ffffff);
  --turgus-telegram-blue: #2aabee;
  --turgus-danger: #c43d4b;
  --turgus-danger-soft: #fff0f1;
  --turgus-shadow: 0 6px 18px rgba(26, 56, 31, 0.06);
  --turgus-pattern-opacity: 0.50;
}

html[data-turgus-theme="dark"] {
  color-scheme: dark;
  --turgus-green-dark: #63c477;
  --turgus-surface: var(--tg-theme-bg-color, #18211b);
  --turgus-surface-muted: var(--tg-theme-secondary-bg-color, #202b23);
  --turgus-page: var(--tg-theme-secondary-bg-color, #111813);
  --turgus-border: #344338;
  --turgus-text: var(--tg-theme-text-color, #f2f6f3);
  --turgus-muted: var(--tg-theme-hint-color, #a8b4aa);
  --turgus-green-soft: #203b27;
  --turgus-danger-soft: #3b2327;
  --turgus-shadow: none;
  --turgus-pattern-opacity: 0.20;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--turgus-text);
  background: var(--turgus-page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  content: "";
  pointer-events: none;
  background: url("turgus-miniapp-background-optimized.png") center / cover no-repeat;
  opacity: var(--turgus-pattern-opacity);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--turgus-green) 28%, transparent);
  outline-offset: 2px;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.mini-card,
.listing-card,
.actions {
  margin: 0 0 12px;
  overflow: hidden;
  border: 1px solid var(--turgus-border);
  border-radius: 12px;
  background: var(--turgus-surface);
  box-shadow: var(--turgus-shadow);
}

.mini-card {
  padding: 16px;
}

.header-card {
  padding: 14px 16px 15px;
}

.header-card h1,
.mini-card h1 {
  margin: 3px 0 5px;
  font-size: 23px;
  line-height: 1.18;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--turgus-green-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.muted {
  margin: 0;
  color: var(--turgus-muted);
  font-size: 14px;
  line-height: 1.4;
}

.notice {
  display: none;
  margin: 0 0 12px;
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--turgus-link) 28%, var(--turgus-border));
  border-radius: 10px;
  color: var(--turgus-text);
  background: color-mix(in srgb, var(--turgus-link) 8%, var(--turgus-surface));
  font-size: 13px;
  line-height: 1.4;
}

.listing-media {
  position: relative;
  min-width: 0;
  border-bottom: 1px solid var(--turgus-border);
  background: var(--turgus-surface-muted);
}

.photo-gallery {
  display: flex;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-inline: contain;
}

.photo-gallery::-webkit-scrollbar {
  display: none;
}

.photo-slide {
  width: 100%;
  min-width: 100%;
  aspect-ratio: 4 / 3;
  margin: 0;
  display: grid;
  place-items: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: var(--turgus-surface-muted);
}

.photo-slide img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 360px;
  object-fit: contain;
}

.photo-meta {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.photo-counter {
  margin-left: auto;
  padding: 4px 7px;
  border-radius: 6px;
  color: #fff;
  background: rgba(18, 30, 21, 0.72);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.photo-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(18, 30, 21, 0.58);
}

.photo-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.52);
}

.photo-dot.is-active {
  width: 7px;
  height: 7px;
  background: #fff;
}

.photo-placeholder {
  min-height: 182px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: 22px;
  color: var(--turgus-muted);
  text-align: center;
  background: var(--turgus-surface-muted);
  font-size: 14px;
}

.photo-placeholder-icon {
  width: 36px;
  height: 30px;
  position: relative;
  display: block;
  border: 2px solid var(--turgus-border);
  border-radius: 7px;
}

.photo-placeholder-icon::before {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: 6px;
  height: 10px;
  border: solid var(--turgus-muted);
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg) skew(8deg, 8deg);
  opacity: 0.55;
}

.photo-placeholder-icon::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--turgus-muted);
  opacity: 0.55;
}

.card-body {
  padding: 16px;
}

.status-pill {
  display: inline-flex;
  margin: 0 0 8px;
  padding: 3px 6px;
  border: 1px solid var(--turgus-border);
  border-radius: 5px;
  color: var(--turgus-muted);
  background: var(--turgus-surface-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.listing-card h2 {
  margin: 0 0 5px;
  font-size: 22px;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.price {
  margin: 0 0 10px;
  color: var(--turgus-green-dark);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.pills span {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 7px;
  border: 1px solid var(--turgus-border);
  border-radius: 6px;
  color: var(--turgus-muted);
  background: var(--turgus-surface-muted);
  font-size: 12px;
  line-height: 1.2;
}

.description {
  margin: 0;
  color: var(--turgus-text);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.custom-fields {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--turgus-border);
  border-radius: 9px;
  background: var(--turgus-surface-muted);
}

.custom-fields h3 {
  margin: 0 0 5px;
  font-size: 15px;
  line-height: 1.3;
}

.custom-field-row {
  display: grid;
  grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--turgus-border);
}

.custom-field-row:first-child {
  border-top: 0;
}

.custom-field-label {
  color: var(--turgus-muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.custom-field-value {
  color: var(--turgus-text);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
  text-align: right;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.consent-note {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 13px 14px;
  background: var(--turgus-surface-muted);
}

.consent-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--turgus-green) 55%, var(--turgus-border));
  border-radius: 50%;
  color: var(--turgus-green-dark);
  font-size: 12px;
  font-weight: 800;
}

.consent-note p {
  margin: 0;
  color: var(--turgus-muted);
  font-size: 13px;
  line-height: 1.45;
}

.actions {
  padding: 12px;
}

.btn {
  width: 100%;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.btn:last-of-type {
  margin-bottom: 0;
}

.btn:focus-visible {
  outline-offset: 2px;
}

.btn.primary {
  color: var(--turgus-button-text);
  background: var(--turgus-green);
}

.btn.primary:hover,
.btn.primary:active {
  background: var(--turgus-green-pressed);
}

.btn.secondary {
  color: var(--turgus-green-dark);
  border-color: var(--turgus-border);
  background: var(--turgus-surface);
}

.btn.ghost {
  color: var(--turgus-text);
  border-color: transparent;
  background: var(--turgus-surface-muted);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.62;
}

.action-message {
  min-height: 0;
  margin: 5px 2px 0;
  color: var(--turgus-muted);
  font-size: 13px;
  line-height: 1.4;
}

.action-message:empty {
  display: none;
}

.state-card {
  text-align: center;
}

.state-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 800;
}

.error-card .state-icon {
  color: var(--turgus-danger);
  background: var(--turgus-danger-soft);
}

.success-card .state-icon {
  color: var(--turgus-green-dark);
  background: var(--turgus-green-soft);
}

.state-card h1,
.state-card h2 {
  margin: 0 0 7px;
  font-size: 22px;
  line-height: 1.25;
}

.state-card p {
  margin: 0 0 14px;
  color: var(--turgus-muted);
  font-size: 14px;
  line-height: 1.45;
}

.error-text {
  color: var(--turgus-danger);
}

.actions.is-success {
  padding: 22px 16px 14px;
}

.rules-header {
  margin-bottom: 10px;
}

.rules-shell {
  width: min(100%, 620px);
}

.rules-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
}

.rules-navigation .btn {
  width: auto;
  min-height: 40px;
  flex: 1 1 160px;
  margin: 0;
  padding: 8px 11px;
  font-size: 13px;
}

.rules-card {
  padding: 4px 16px;
}

.rules-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rules-section {
  padding: 16px 0;
  border-top: 1px solid var(--turgus-border);
}

.rules-section:first-child {
  border-top: 0;
}

.rules-section h2 {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  margin: 0 0 9px;
  color: var(--turgus-text);
  font-size: 17px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.rules-number {
  width: 25px;
  height: 25px;
  display: inline-grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--turgus-green) 36%, var(--turgus-border));
  border-radius: 7px;
  color: var(--turgus-green-dark);
  background: var(--turgus-green-soft);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.rules-section p {
  margin: 0 0 9px 35px;
  color: var(--turgus-text);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.rules-section p:last-child {
  margin-bottom: 0;
}

.rules-section a {
  color: var(--turgus-green-dark);
}

@media (prefers-color-scheme: dark) {
  html:not([data-turgus-theme]) {
    color-scheme: dark;
    --turgus-green-dark: #63c477;
    --turgus-surface: #18211b;
    --turgus-surface-muted: #202b23;
    --turgus-page: #111813;
    --turgus-border: #344338;
    --turgus-text: #f2f6f3;
    --turgus-muted: #a8b4aa;
    --turgus-green-soft: #203b27;
    --turgus-danger-soft: #3b2327;
    --turgus-shadow: none;
  }
}

@media (max-width: 359px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .header-card h1,
  .mini-card h1 {
    font-size: 21px;
  }

  .listing-card h2 {
    font-size: 20px;
  }

  .price {
    font-size: 22px;
  }

  .custom-field-row {
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
    gap: 8px;
  }

  .btn {
    padding-right: 10px;
    padding-left: 10px;
    font-size: 13px;
  }

  .rules-card {
    padding-right: 14px;
    padding-left: 14px;
  }

  .rules-section p {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
