/*
 * Калькулятор ваги й модалка з ним — assets/js/weight-calculator.js.
 * Спільне для обох тем; акцент — колір магазину (--primary-color).
 */

.wcalc {
  --wcalc-accent: var(--primary-color, #2f9e55);
  --wcalc-border: #d9dde3;
  --wcalc-error: #d93025;
  --wcalc-error-bg: #fdf1f0;
  --wcalc-muted: #6b7280;
  color: #111827;
}

.wcalc [hidden] {
  display: none !important;
}

.wcalc__fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
}

/* Два поля в рядок; на вузькому екрані Сума переноситься під Вагу. */
.wcalc__field {
  flex: 1 1 220px;
  min-width: 0;
}

/* Підпис поля; праворуч у ньому — перемикач г / кг (лише в полі Вага).
   Висота однакова з перемикачем і без, щоб поля Вага й Сума стояли рівно. */
.wcalc__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
  margin: 0 0 6px;
}

.wcalc__label {
  display: block;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/*
 * Поле з кнопками − / + — один контрол: біле, з нейтральною рамкою, кнопки —
 * заокруглені квадрати всередині. Акцент магазину — точково: іконка «+»,
 * рамка на фокусі, вибрані г / кг. Відтінки рахуються з --primary-color.
 */
.wcalc {
  --wcalc-tint: color-mix(in srgb, var(--wcalc-accent) 7%, #fff);
  --wcalc-surface: #f4f5f7;
}

.wcalc__row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: 6px;
  border: 1.5px solid var(--wcalc-border);
  border-radius: 16px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.wcalc__row:hover {
  border-color: #c4c9d1;
}

.wcalc__row:focus-within {
  border-color: var(--wcalc-accent);
  box-shadow: 0 1px 0 0 var(--wcalc-accent), 0 6px 16px -10px var(--wcalc-accent);
}

.wcalc__row.is-error {
  border-color: var(--wcalc-error);
  background: var(--wcalc-error-bg);
  box-shadow: none;
}

.wcalc__step {
  flex: none;
  width: 42px;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: var(--wcalc-surface);
  color: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

/* «+» — головна дія: лише іконка в кольорі магазину. */
.wcalc__step[data-step="1"] {
  color: var(--wcalc-accent);
}

.wcalc__step svg {
  display: block;
}

.wcalc__step:hover:not(:disabled) {
  background: var(--wcalc-tint);
  color: var(--wcalc-accent);
}

.wcalc__step:active:not(:disabled) {
  transform: scale(0.92);
}

.wcalc__step:focus-visible {
  outline: 2px solid var(--wcalc-accent);
  outline-offset: 1px;
}

.wcalc__row.is-error .wcalc__step {
  background: rgba(255, 255, 255, 0.75);
}

/* Саме поле — без власної рамки: її малює ряд. */
.wcalc__box {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 0 10px;
  border: 0;
  background: transparent;
}

.wcalc__input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: inherit;
  text-overflow: ellipsis;
}

.wcalc__input::placeholder {
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: #9ca3af;
}

.wcalc__currency {
  flex: none;
  padding-right: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--wcalc-muted);
}

/* г / кг — сегментований перемикач: сіра доріжка, активний — білий з
   акцентним текстом. */
.wcalc__units {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--wcalc-surface);
}

.wcalc__unit {
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--wcalc-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.wcalc__unit.is-active {
  background: #fff;
  color: var(--wcalc-accent);
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.12);
}

.wcalc__msg {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--wcalc-accent);
}

.wcalc__msg.is-error {
  color: var(--wcalc-error);
}

.wcalc__take {
  margin-left: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.wcalc__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.wcalc__chip {
  padding: 7px 15px;
  border: 1.5px solid var(--wcalc-border);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.wcalc__chip:hover {
  border-color: #c4c9d1;
  color: #111827;
}

.wcalc__chip.is-active {
  border-color: var(--wcalc-accent);
  background: var(--wcalc-tint);
  color: var(--wcalc-accent);
}

/* Фіксовані тари: картки вибору замість полів ваги й суми. */
.wcalc--tares .wcalc__field {
  flex: none;
}

.wcalc--tares .wcalc__field--count {
  margin-top: 14px;
  max-width: 260px;
}

.wcalc--tares .wcalc__field--count .wcalc__label {
  margin-bottom: 6px;
}

.wcalc__tares {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.wcalc__tare {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 9px 6px;
  border: 1.5px solid var(--wcalc-border);
  border-radius: 14px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  color: #111827;
  font: inherit;
  text-align: center;
  cursor: pointer;
}

.wcalc__tare:hover:not(:disabled) {
  border-color: #c4c9d1;
}

.wcalc__tare.is-active {
  border-color: var(--wcalc-accent);
}

.wcalc__tare.is-active {
  background: var(--wcalc-tint);
  box-shadow: inset 0 0 0 1px var(--wcalc-accent);
}

.wcalc__tare.is-active .wcalc__tare-amount {
  color: var(--wcalc-accent);
}

/* Тари, якої не вистачає залишку, не ховаємо — приглушуємо. */
.wcalc__tare:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wcalc__tare-amount {
  font-size: 15px;
  font-weight: 700;
}

.wcalc__tare-price {
  font-size: 13px;
  color: var(--wcalc-muted);
}

.wcalc__step:disabled {
  opacity: 0.4;
  cursor: default;
}

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

.wcalc__total:empty {
  display: none;
}

.wcalc__total-weight {
  color: var(--wcalc-muted);
  font-size: 14px;
}

/* Позначка акції (FE_Client_7.2.12): та сама зелена, що й акційні рядки кошика. */
.wcalc__promo {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.08);
  color: #15803d;
  font-size: 14px;
  line-height: 1.4;
}

.wcalc__promo-title {
  font-weight: 600;
}

.wcalc__promo-old {
  color: var(--wcalc-muted);
}

.wcalc__promo-new {
  font-size: 15px;
}

.wcalc__hint {
  margin-top: 10px;
  font-size: 13px;
  color: var(--wcalc-muted);
}

.wcalc__actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

/* Кнопки модалки — однакової ширини, незалежно від довжини підпису. */
.wcalc__btn {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

/* Вузький телефон: половина ширини замала для «Додати до кошику» в рядок —
   переносимо підпис, а не обрізаємо. */
@media (max-width: 420px) {
  .wcalc__btn {
    padding: 0 10px;
    font-size: 15px;
    line-height: 1.15;
    white-space: normal;
  }
}

.wcalc__btn--secondary {
  background: #eef0f2;
  color: #1f2937;
}

.wcalc__btn--primary {
  background: var(--wcalc-accent);
  color: #fff;
}

.wcalc__btn--primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Модалка ─────────────────────────────────────────────────────────── */

.wcalc-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px;
  overflow-y: auto;
  background: rgba(15, 20, 32, 0.5);
  -webkit-overflow-scrolling: touch;
}

.wcalc-modal__dialog {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: auto;
  padding: 22px 20px 20px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: wcalcModalIn 0.2s ease;
}

@keyframes wcalcModalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.wcalc-modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: #6b7280;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.wcalc-modal__close:hover {
  background: #f3f4f6;
  color: #374151;
}

.wcalc-modal__title {
  margin: 0;
  padding-right: 36px;
  font-size: 20px;
  font-weight: 700;
  color: #111827;
}

.wcalc-modal__price {
  margin: 4px 0 16px;
  font-size: 16px;
  color: #4b5563;
}
