:root {
  /* Light scheme (Material 3 из приложения) */
  --primary: #1976D2;
  --on-primary: #FFFFFF;
  --secondary: #388E3C;
  --on-secondary: #FFFFFF;
  --background: #FFFFFF;
  --surface: #FFFFFF;
  --surface-variant: #EEEEEE;
  --primary-container: #D6E4FF;
  --on-primary-container: #1A3A5C;
  --secondary-container: #DCEEDC;
  --on-secondary-container: #1E3A1E;
  --on-surface: #1C1B1F;
  --on-surface-muted: rgba(28, 27, 31, 0.6);
  --on-surface-faint: rgba(28, 27, 31, 0.4);
  --error: #B3261E;
  --gray: #9E9E9E;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #90CAF9;
    --on-primary: #000000;
    --secondary: #81C784;
    --on-secondary: #000000;
    --background: #121212;
    --surface: #1E1E1E;
    --surface-variant: #2C2C2C;
    --primary-container: #1E3A5C;
    --on-primary-container: #D6E4FF;
    --secondary-container: #1E3A1E;
    --on-secondary-container: #DCEEDC;
    --on-surface: #FFFFFF;
    --on-surface-muted: rgba(255, 255, 255, 0.65);
    --on-surface-faint: rgba(255, 255, 255, 0.45);
    --error: #F2B8B5;
    --gray: #757575;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--background);
  color: var(--on-surface);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

img {
  display: block;
}

/* ---------- Layout ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 64px;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.topbar__brand {
  font-size: 20px;
  font-weight: 700;
}

.topbar__subtitle {
  font-size: 13px;
  opacity: 0.9;
}

.topbar__spacer {
  flex: 1;
}

.topbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--on-primary);
  flex-shrink: 0;
}

.topbar__back:hover {
  background: rgba(255, 255, 255, 0.15);
}

.topbar__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  color: var(--on-primary);
  flex-shrink: 0;
  text-decoration: none;
}

.topbar__icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.topbar__icon svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 480px) {
  .topbar__icon {
    width: 36px;
    height: 36px;
  }

  .topbar__icon svg {
    width: 20px;
    height: 20px;
  }
}

.page {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- Cart button ---------- */
.cart-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: 20px;
  background: var(--secondary);
  color: var(--on-secondary);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.cart-btn:hover {
  filter: brightness(1.05);
}

.cart-btn__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--on-secondary);
  color: var(--secondary);
  font-size: 13px;
  font-weight: 700;
}

.cart-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------- Category chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}

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

.chip {
  flex-shrink: 0;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--surface-variant);
  border-radius: 18px;
  background: transparent;
  color: var(--on-surface);
  font-size: 14px;
}

.chip:hover {
  background: var(--surface-variant);
}

.chip--active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

/* ---------- Product grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card--disabled {
  background: var(--surface-variant);
  cursor: default;
}

.card__media {
  position: relative;
  height: 150px;
  background: var(--surface-variant);
  overflow: hidden;
}

.card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__media--disabled img {
  opacity: 0.5;
}

.badge-out {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
}

.card__body {
  padding: 12px;
}

.card__name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__category {
  font-size: 13px;
  color: var(--secondary);
  margin-top: 2px;
}

.card__price-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 10px;
}

.card__price {
  font-size: 19px;
  font-weight: 700;
  color: var(--secondary);
}

.card__price--disabled {
  color: var(--gray);
}

.card__unit {
  font-size: 13px;
  color: var(--on-surface-muted);
}

/* ---------- Detail ---------- */
.detail__media {
  position: relative;
  height: 250px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-variant);
}

.detail__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail__media--disabled img {
  opacity: 0.5;
}

.detail__name {
  font-size: 24px;
  font-weight: 700;
  margin-top: 16px;
}

.info-card {
  margin-top: 12px;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.info-card__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.info-card__category {
  font-size: 16px;
}

.info-card__price {
  font-size: 20px;
  font-weight: 700;
  color: var(--secondary);
}

.info-card__price--disabled {
  color: var(--gray);
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-top: 20px;
}

.section-text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--on-surface-muted);
  margin-top: 8px;
  white-space: pre-line;
}

.specs {
  margin-top: 20px;
  border-radius: 10px;
  padding: 16px;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.specs__title {
  font-size: 16px;
  font-weight: 600;
}

.specs__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
}

.specs__row:not(:last-child) {
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.specs__label {
  color: var(--on-primary-container);
  opacity: 0.72;
}

.specs__value {
  font-weight: 500;
  text-align: right;
}

.specs__value--unavailable {
  color: var(--gray);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--secondary);
  color: var(--on-secondary);
  font-size: 16px;
  font-weight: 600;
  margin-top: 24px;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:disabled {
  background: var(--gray);
  cursor: not-allowed;
}

.btn svg {
  width: 20px;
  height: 20px;
}

.btn--outline {
  background: transparent;
  color: var(--secondary);
  border: 1px solid var(--secondary);
}

/* ---------- States ---------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 16px;
  color: var(--on-surface-muted);
}

.state__icon {
  font-size: 56px;
  line-height: 1;
}

.state__title {
  font-size: 20px;
  font-weight: 700;
  margin-top: 16px;
  color: var(--on-surface);
}

.state__text {
  font-size: 15px;
  margin-top: 8px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-variant);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* ---------- Cart ---------- */
.cart-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.cart-item__thumb {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-variant);
}

.cart-item__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cart-item__info {
  flex: 1;
  min-width: 0;
}

.cart-item__name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item__category {
  font-size: 13px;
  color: var(--secondary);
}

.cart-item__price {
  font-size: 13px;
  color: var(--on-surface-muted);
}

.cart-item__controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper__btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--surface-variant);
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface);
  font-size: 20px;
  line-height: 1;
}

.stepper__btn:hover {
  background: var(--surface-variant);
}

.stepper__value {
  width: 30px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
}

.cart-item__total {
  font-size: 14px;
  font-weight: 700;
  color: var(--secondary);
}

.summary {
  margin-top: 16px;
  border-radius: var(--radius);
  padding: 16px;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.summary__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary__label {
  font-size: 18px;
}

.summary__value {
  font-size: 24px;
  font-weight: 700;
  color: var(--secondary);
}

/* ---------- Checkout ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 14px;
  font-weight: 500;
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--surface-variant);
  border-radius: 8px;
  background: var(--surface);
  color: var(--on-surface);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

.field--error input,
.field--error textarea {
  border-color: var(--error);
}

.field__error {
  font-size: 12px;
  color: var(--error);
}

.checkout-items {
  border-radius: 10px;
  padding: 16px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  margin-top: 8px;
}

.checkout-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
}

.checkout-total {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(128, 128, 128, 0.25);
}

.checkout-total .value {
  color: var(--secondary);
}

/* ---------- Success ---------- */
.success {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 0;
}

.success__check {
  width: 110px;
  height: 110px;
  color: var(--secondary);
}

.success__title {
  font-size: 26px;
  font-weight: 700;
  margin-top: 24px;
}

.success__text {
  font-size: 16px;
  color: var(--on-surface-muted);
  margin-top: 14px;
  line-height: 1.5;
}

.contacts {
  width: 100%;
  margin-top: 28px;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  text-align: left;
}

.contacts__title {
  font-size: 16px;
  font-weight: 700;
}

.contacts__line {
  font-size: 16px;
  margin-top: 12px;
}

/* ---------- Dialog ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.dialog {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.dialog__icon {
  width: 48px;
  height: 48px;
  color: var(--error);
  margin: 0 auto;
}

.dialog__title {
  font-size: 20px;
  font-weight: 700;
  margin-top: 12px;
}

.dialog__text {
  font-size: 15px;
  color: var(--on-surface-muted);
  margin-top: 8px;
  line-height: 1.5;
}

.dialog__phone {
  font-size: 15px;
  margin-top: 8px;
}

.dialog__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #323232;
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

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

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .page {
    padding: 24px;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
  }
  .detail__media {
    height: 340px;
  }
}
