/**
 * SHOPPING CALCULATOR STYLES - SuperPrecio
 * Mobile-first design for in-store shopping experience.
 * Brand: Green (#136213) primary, Yellow/Amber best price, Red for expensive alerts.
 */

/* =============================================
   PAGE LAYOUT
   ============================================= */

.calc-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(135deg, #f0faf0 0%, #f8f9fa 40%, #f0f7f0 100%);
  padding-bottom: 120px; /* Space for sticky total bar */
}

.calc-page__back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.625rem 1.125rem;
  margin: 0.5rem 0.75rem;
  background: #136213;
  border-radius: 2rem;
  transition: background-color 0.2s, transform 0.15s;
  box-shadow: 0 2px 6px rgba(19, 98, 19, 0.25);
}

.calc-page__back:hover {
  background: #0a4a0a;
  color: white;
  transform: translateY(-1px);
}

.calc-page__back:active {
  transform: translateY(0);
}

/* =============================================
   MARKET SELECTION SCREEN
   ============================================= */

.calc-market-selection {
  max-width: 500px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  text-align: center;
}

.calc-market-selection__icon {
  font-size: 3rem;
  color: #136213;
  margin-bottom: 0.75rem;
  display: block;
}

.calc-market-selection__title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #212529;
  margin: 0 0 0.375rem;
}

.calc-market-selection__subtitle {
  font-size: 0.9rem;
  color: #6c757d;
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

.calc-market-select-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.calc-market-select-group select {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 2px solid #dee2e6;
  border-radius: 12px;
  font-size: 1rem;
  background: white;
  color: #212529;
  appearance: auto;
  min-height: 52px;
}

.calc-market-select-group select:focus {
  border-color: #136213;
  outline: none;
  box-shadow: 0 0 0 3px rgba(19, 98, 19, 0.15);
}

#calc-market-select-btn {
  padding: 0.875rem 1.5rem;
  background: linear-gradient(135deg, #136213, #0d4a0a);
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  min-height: 52px;
  min-width: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(19, 98, 19, 0.25);
}

#calc-market-select-btn:hover {
  background: linear-gradient(135deg, #0d4a0d, #094209);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(19, 98, 19, 0.35);
}

/* Geo hint */
.calc-geo-hint {
  display: none;
  flex-direction: column;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 2px solid #136213;
  border-radius: 12px;
  font-size: 0.9rem;
  color: #0a4a0a;
  text-align: left;
  margin-top: 1rem;
  animation: calc-slide-in 0.3s ease;
}

.calc-geo-hint__body {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  line-height: 1.4;
}

.calc-geo-hint i {
  font-size: 1.1rem;
  color: #136213;
  flex-shrink: 0;
  margin-top: 0.1rem; /* optical alignment with first line of text */
}

.calc-geo-hint__text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.calc-geo-hint__footer {
  display: flex;
  justify-content: flex-end;
}

.calc-geo-hint__btn {
  padding: 0.5rem 1.25rem;
  background: #136213;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

.calc-geo-hint__btn:hover {
  background: #0a4a0a;
}

/* =============================================
   MAIN CALCULATOR AREA
   ============================================= */

.calc-main {
  display: none;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 0.75rem;
}

/* Active market header */
.calc-market-active {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #136213, #0d4a0a);
  color: white;
  border-radius: 12px;
  margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(19, 98, 19, 0.25);
}

.calc-market-active__logo {
  height: 32px;
  max-width: 80px;
  object-fit: contain;
  background: white;
  border-radius: 6px;
  padding: 2px 6px;
}

.calc-market-active__name {
  flex: 1;
  font-size: 0.95rem;
}

.calc-market-active__name strong {
  font-weight: 800;
}

.calc-market-active__change {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.calc-market-active__change:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* =============================================
   SEARCH BAR
   ============================================= */

.calc-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.calc-search__input-wrap {
  flex: 1;
  position: relative;
}

.calc-search__input {
  width: 100%;
  padding: 0.875rem 1rem 0.875rem 2.75rem;
  border: 2px solid #dee2e6;
  border-radius: 12px;
  font-size: 1rem;
  background: white;
  color: #212529;
  min-height: 52px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.calc-search__input:focus {
  border-color: #136213;
  outline: none;
  box-shadow: 0 0 0 3px rgba(19, 98, 19, 0.15);
}

.calc-search__input-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: #6c757d;
  font-size: 1.1rem;
  pointer-events: none;
}

.calc-search__submit {
  padding: 0 1rem;
  background: linear-gradient(135deg, #136213, #0d4a0a);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  min-height: 52px;
  min-width: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(19, 98, 19, 0.2);
}

.calc-search__submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(19, 98, 19, 0.3);
}

.calc-search__scan {
  padding: 0 1rem;
  background: white;
  color: #136213;
  border: 2px solid #136213;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  min-height: 52px;
  min-width: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.calc-search__scan:hover {
  background: #f0fdf4;
  transform: translateY(-2px);
}

/* =============================================
   SEARCH RESULTS
   ============================================= */

.calc-results {
  margin-bottom: 1.5rem;
}

.calc-product {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem;
  background: white;
  border: 2px solid #e9ecef;
  border-radius: 14px;
  margin-bottom: 0.625rem;
  transition: all 0.2s;
  position: relative;
}

.calc-product:hover {
  border-color: #ced4da;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Best price state */
.calc-product--best {
  border-color: #136213;
  background: linear-gradient(135deg, #f0fdf4 0%, #f8f9fa 100%);
}

/* Expensive state */
.calc-product--expensive {
  border-color: #fbbf24;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 40%, #f8f9fa 100%);
}

/* Unavailable state */
.calc-product--unavailable {
  opacity: 0.7;
  border-style: dashed;
}

.calc-product__image {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calc-product__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.calc-product__info {
  flex: 1;
  min-width: 0;
}

.calc-product__name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #212529;
  margin: 0 0 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

/* Price comparison badges */
.calc-product__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  margin-bottom: 0.375rem;
}

.calc-product__badge--best {
  background: #dcfce7;
  color: #136213;
}

.calc-product__badge--expensive {
  background: #fef3c7;
  color: #92400e;
}

.calc-product__badge--unavailable {
  background: #f3f4f6;
  color: #6b7280;
}

.calc-product__price-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.calc-product__price {
  font-size: 1.15rem;
  font-weight: 800;
  color: #136213;
}

.calc-product--expensive .calc-product__price {
  color: #d97706;
}

.calc-product--unavailable .calc-product__price {
  color: #9ca3af;
}

/* Other market prices (small, inline, scrollable) */
.calc-product__others {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;       /* Firefox */
}
.calc-product__others::-webkit-scrollbar {
  display: none;               /* Chrome/Safari */
}

.calc-product__other {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: #6c757d;
  background: #f3f4f6;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.calc-product__other--cheaper {
  color: #136213;
  background: #dcfce7;
  font-weight: 700;
}

.calc-product__other-logo {
  height: 16px;
  max-width: 40px;
  object-fit: contain;
}

.calc-product__other-price {
  white-space: nowrap;
}

/* Add button */
.calc-product__action {
  flex-shrink: 0;
}

.calc-product__add {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #136213, #0d4a0a);
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 3px 8px rgba(19, 98, 19, 0.3);
}

.calc-product__add:hover:not([disabled]) {
  transform: scale(1.1);
  box-shadow: 0 5px 14px rgba(19, 98, 19, 0.4);
}

.calc-product__add:active:not([disabled]) {
  transform: scale(0.95);
}

.calc-product__add--added {
  background: #6c757d;
  box-shadow: none;
  cursor: default;
}

/* =============================================
   CALCULATOR ITEMS LIST
   ============================================= */

.calc-items-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #6c757d;
}

.calc-items-empty i {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  display: block;
  opacity: 0.4;
}

.calc-items-empty p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.calc-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
}

.calc-items-header__count {
  font-size: 0.9rem;
  font-weight: 700;
  color: #136213;
}

.calc-items-header__clear {
  background: none;
  border: none;
  color: #dc3545;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.calc-items-header__clear:hover {
  background: #fef2f2;
}

/* Individual item */
.calc-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid #f1f3f5;
  animation: calc-slide-in 0.25s ease;
}

.calc-item:last-child {
  border-bottom: none;
}

.calc-item--expensive {
  background: #fffbeb;
  margin: 0 -0.5rem;
  padding: 0.625rem 1rem;
  border-radius: 8px;
  border-bottom: none;
  margin-bottom: 0.25rem;
}

.calc-item__img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

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

.calc-item__name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #212529;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.calc-item__saving {
  font-size: 0.72rem;
  color: #d97706;
  font-weight: 600;
  display: block;
}

.calc-item__price {
  font-size: 0.95rem;
  font-weight: 800;
  color: #136213;
  white-space: nowrap;
}

.calc-item--expensive .calc-item__price {
  color: #d97706;
}

.calc-item__remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: #f3f4f6;
  color: #6c757d;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.calc-item__remove:hover {
  background: #fef2f2;
  color: #dc3545;
}

/* =============================================
   STICKY TOTAL BAR
   ============================================= */

.calc-total-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 2px solid #136213;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  padding: 0.875rem 1rem;
  padding-bottom: calc(0.875rem + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.calc-total-bar__content {
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.calc-total-bar__info {
  flex: 1;
}

.calc-total-bar__label {
  font-size: 0.8rem;
  color: #6c757d;
  font-weight: 600;
  display: block;
}

.calc-total-bar__amount {
  font-size: 1.75rem;
  font-weight: 900;
  color: #136213;
  line-height: 1.1;
}

.calc-total--pulse {
  animation: calc-pulse 0.4s ease;
}

.calc-total-bar__savings {
  display: none;
  font-size: 0.75rem;
  color: #d97706;
  font-weight: 700;
  margin-top: 0.125rem;
}

.calc-total-bar__savings i {
  font-size: 0.7rem;
}

/* =============================================
   LOADING & EMPTY STATES
   ============================================= */

.calc-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 2rem;
  color: #6c757d;
  font-size: 0.95rem;
}

.calc-loading__spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #e9ecef;
  border-top-color: #136213;
  border-radius: 50%;
  animation: calc-spin 0.6s linear infinite;
}

.calc-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: #6c757d;
  font-size: 0.95rem;
}

.calc-error {
  text-align: center;
  padding: 1.5rem 1rem;
  color: #dc3545;
  font-size: 0.95rem;
  background: #fef2f2;
  border-radius: 12px;
}

.calc-error i {
  font-size: 1.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

/* =============================================
   SECTION SEPARATOR
   ============================================= */

.calc-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0;
  margin: 0.5rem 0;
  border-bottom: 1px solid #e9ecef;
}

/* =============================================
   ANIMATIONS
   ============================================= */

@keyframes calc-slide-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes calc-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

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

/* =============================================
   RESPONSIVE - MOBILE (max 480px)
   ============================================= */

@media (max-width: 480px) {
  /* Reduce page-level back link padding to recover vertical space */
  .calc-page__back {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
  }

  /* Market selection: tighter vertical rhythm */
  .calc-market-selection {
    padding: 0.75rem 0.875rem 1.25rem;
  }

  .calc-market-selection__icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }

  .calc-market-selection__title {
    font-size: 1.2rem;
  }

  .calc-market-selection__subtitle {
    font-size: 0.85rem;
    margin-bottom: 1rem;
  }

  /* Select + button group: ensure button never collapses */
  .calc-market-select-group {
    gap: 0.375rem;
  }

  .calc-market-select-group select {
    padding: 0.75rem 0.625rem;
    font-size: 0.9rem;
    min-height: 48px;
  }

  #calc-market-select-btn {
    padding: 0.75rem 1rem;
    min-height: 48px;
    min-width: 48px;
  }

  /* Geo hint: already column-stacked, just tighten padding */
  .calc-geo-hint {
    padding: 0.75rem 0.875rem;
    font-size: 0.85rem;
    gap: 0.5rem;
  }

  .calc-geo-hint__btn {
    width: 100%;  /* full-width tap target on very narrow screens */
    justify-content: center;
    min-height: 44px;
  }

  /* Sticky total: smaller amount text to prevent overflow */
  .calc-total-bar__amount {
    font-size: 1.45rem;
  }
}

/* Very compact phones (iPhone SE, Galaxy A series at 360px) */
@media (max-width: 360px) {
  .calc-market-selection__title {
    font-size: 1.1rem;
  }

  .calc-market-selection__subtitle {
    font-size: 0.8rem;
  }

  .calc-market-select-group select {
    font-size: 0.85rem;
  }
}

/* =============================================
   RESPONSIVE - TABLET+
   ============================================= */

@media (min-width: 576px) {
  .calc-product__image {
    width: 80px;
    height: 80px;
  }

  .calc-product__name {
    font-size: 1rem;
  }

  .calc-product__price {
    font-size: 1.3rem;
  }

  .calc-item__img {
    width: 48px;
    height: 48px;
  }

  /* On tablet+ the geo-hint can go back to a single row */
  .calc-geo-hint {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }

  .calc-geo-hint__body {
    flex: 1;
    min-width: 0;
  }

  .calc-geo-hint__footer {
    flex-shrink: 0;
  }

  .calc-geo-hint__btn {
    width: auto;
  }
}

/* =============================================
   ACCESSIBILITY
   ============================================= */

@media (prefers-reduced-motion: reduce) {
  .calc-product,
  .calc-item,
  .calc-total-bar,
  .calc-product__add,
  .calc-search__submit,
  .calc-search__scan,
  #calc-market-select-btn {
    transition: none;
  }

  .calc-product__add:hover:not([disabled]) {
    transform: none;
  }

  .calc-total--pulse {
    animation: none;
  }

  .calc-loading__spinner {
    animation-duration: 1.2s;
  }

  .calc-item {
    animation: none;
  }
}

@media (prefers-contrast: high) {
  .calc-product {
    border-width: 3px;
  }

  .calc-product--best {
    border-color: #0a4a0a;
  }

  .calc-product--expensive {
    border-color: #d97706;
  }
}

/* =============================================
   PRINT
   ============================================= */

@media print {
  .calc-search,
  .calc-results,
  .calc-total-bar,
  .calc-page__back,
  .calc-market-active__change,
  .calc-items-header__clear,
  .calc-item__remove,
  .calc-product__action {
    display: none !important;
  }

  .calc-page {
    padding-bottom: 0;
    background: white;
  }

  .calc-market-active {
    background: white !important;
    color: #212529 !important;
    border: 2px solid #136213;
    box-shadow: none;
  }

  .calc-item {
    border-bottom: 1px solid #ccc;
  }
}
