:root {
  --fp-bg: var(--tg-theme-bg-color, #ffffff);
  --fp-text: var(--tg-theme-text-color, #1a1a1a);
  --fp-hint: var(--tg-theme-hint-color, #8a8a8a);
  --fp-link: var(--tg-theme-link-color, #2481cc);
  --fp-button: var(--tg-theme-button-color, #2ea043);
  --fp-button-text: var(--tg-theme-button-text-color, #ffffff);
  --fp-secondary-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --fp-card-bg: var(--tg-theme-section-bg-color, #ffffff);
  --fp-border: rgba(0, 0, 0, 0.08);
  --fp-radius: 14px;
}

* { box-sizing: border-box; }

/* Several components below (.fp-sheet-overlay, .fp-cart-bar, ...) set their
   own `display` unconditionally. A class selector and the `[hidden]`
   attribute selector have equal CSS specificity, so without this rule the
   browser's built-in `[hidden] { display: none }` loses to those classes
   and toggling `el.hidden` in JS has no visual effect - the product sheet
   overlay and cart bar end up permanently rendered full-screen/fixed,
   dimming the page and swallowing every tap regardless of what's
   underneath. This override always wins. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fp-bg);
  color: var(--fp-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.fp-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--fp-bg);
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--fp-border);
}

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

.fp-header__fridge {
  font-size: 13px;
  color: var(--fp-hint);
  margin-top: 2px;
  min-height: 16px;
}

.fp-screen { padding: 12px 12px 12px; }

.fp-empty {
  color: var(--fp-hint);
  text-align: center;
  padding: 40px 20px;
  font-size: 15px;
}

.fp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fp-card {
  background: var(--fp-card-bg);
  border-radius: var(--fp-radius);
  border: 1px solid var(--fp-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.fp-card__image-wrap {
  aspect-ratio: 1 / 1;
  background: var(--fp-secondary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.fp-card__placeholder {
  font-size: 34px;
  opacity: 0.5;
}

.fp-card__body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.fp-card__name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  min-height: 34px;
}

.fp-card__price {
  font-size: 15px;
  font-weight: 700;
}

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

.fp-card__stock--out {
  color: #d0463c;
}

.fp-card__controls { margin-top: 4px; }

.fp-btn {
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
}

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

.fp-btn--primary:active {
  filter: brightness(0.9);
}

.fp-btn--disabled {
  background: var(--fp-secondary-bg);
  color: var(--fp-hint);
}

.fp-qty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--fp-secondary-bg);
  border-radius: 10px;
  padding: 4px;
}

.fp-qty__btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--fp-card-bg);
  font-size: 18px;
  font-weight: 700;
  color: var(--fp-text);
  cursor: pointer;
  touch-action: manipulation;
}

.fp-qty__btn:active {
  background: var(--fp-secondary-bg);
}

.fp-qty__value {
  font-weight: 700;
  font-size: 15px;
  min-width: 24px;
  text-align: center;
}

.fp-cart-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  background: var(--fp-button);
  color: var(--fp-button-text);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.fp-cart-bar #cart-bar-text { font-weight: 600; font-size: 14px; }

.fp-cart-bar .fp-btn {
  width: auto;
  background: rgba(255, 255, 255, 0.18);
  color: var(--fp-button-text);
}

.fp-cart-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.fp-cart-header h2 { margin: 0; font-size: 18px; }

.fp-link-btn {
  background: none;
  border: none;
  color: var(--fp-link);
  font-size: 14px;
  padding: 4px 0;
  cursor: pointer;
}

.fp-cart-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.fp-cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--fp-card-bg);
  border: 1px solid var(--fp-border);
  border-radius: 12px;
  padding: 10px 12px;
}

.fp-cart-item__name { font-weight: 600; font-size: 14px; }
.fp-cart-item__price { font-size: 13px; color: var(--fp-hint); }
.fp-cart-item__qty { width: 112px; }

.fp-cart-summary {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fp-secondary-bg);
}

.fp-cart-summary__row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 3px 0;
}

.fp-cart-summary__row--total {
  font-weight: 700;
  font-size: 16px;
}

.fp-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: flex;
  align-items: flex-end;
}

.fp-sheet {
  background: var(--fp-bg);
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px 24px;
  max-height: 82vh;
  overflow-y: auto;
  position: relative;
}

.fp-sheet__close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--fp-secondary-bg);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
}

.fp-sheet__image {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: var(--fp-secondary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

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

.fp-sheet__name { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.fp-sheet__price { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.fp-sheet__stock { font-size: 13px; color: var(--fp-hint); margin-bottom: 14px; }

.fp-sheet__qty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 16px;
}

.fp-sheet__qty .fp-qty__btn { width: 42px; height: 42px; font-size: 20px; }
.fp-sheet__qty .fp-qty__value { font-size: 18px; min-width: 30px; }

.fp-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 96px;
  z-index: 30;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
  opacity: 0.95;
}

.fp-order-success { text-align: center; padding: 24px 8px; }
.fp-order-success__icon { font-size: 42px; margin-bottom: 8px; }
.fp-order-success__title { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

.fp-order-summary {
  text-align: left;
  background: var(--fp-secondary-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0;
}

.fp-order-summary__row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 2px 0;
}

.fp-note {
  font-size: 13px;
  color: var(--fp-hint);
  margin-top: 10px;
  line-height: 1.4;
}

.fp-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  background: #fff4cc;
  color: #8a6d00;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 10px;
}
