*, *::before, *::after {
  box-sizing: border-box;
  transition: all 0.3s ease;
}

body {
  font-family: 'Arial', sans-serif;
  padding: 20px;
  background: linear-gradient(to bottom, #dff0df 0%, #ffffff 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  box-sizing: border-box;
  overflow-x: hidden;
  padding-bottom: 70px;
}

/* New base class for card panels */
.card-panel {
  background-color: #fff;
  padding: 20px;
  width: 99%;
  max-width: 750px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  margin: 0 auto 12px auto;
  position: relative;
  overflow: hidden;
}

.input-section {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  border-bottom: none;
  position: relative;
}

/* Added for toggling form visibility */
.input-section.hidden {
  display: none;
}

.input-section input[type="text"] {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
}

/* NEW: Combined wrapper for item name input, search button, and quantity input */
.input-item-name-qty-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
  min-width: 0;
}

.item-name-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  /* Removed width: 100% and margin-bottom as it's now handled by the parent .input-item-name-qty-group */
}

.item-name-input-wrapper #item-name {
  flex: 1 1 auto;
  width: auto;
  padding-right: 12px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  box-sizing: border-box;
  height: 48px;
  min-width: 0;
}

.item-name-input-wrapper .supermarket-search-button {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  z-index: 1;
  background-image: url('search-icon.png');
  background-size: 65%;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 8px;
}

.item-name-input-wrapper .supermarket-search-button:hover {
  opacity: 1;
}

/* Quantity number input within the new combined group */
.input-item-name-qty-group .quantity-number-input {
  width: 70px;
  flex: 0 0 70px;
}

.input-item-name-qty-group .quantity-number-input input[type="number"] {
  padding: 12px;
  padding-right: 20px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  box-sizing: border-box;
  height: 48px;
  text-align: center;
  width: 100%;
}

.input-section select {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  /* Removed margin-bottom, handled by parent group */
}

.days-input-and-buttons-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 3px;
  margin-bottom: 12px;
  position: relative;
  flex-wrap: wrap;
}

/* New style for the inline "Relist" sentence */
.lasts-input-sentence {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  font-size: 0.9rem;
  line-height: 48px;
  color: #495057;
  flex-shrink: 1;
  flex-basis: auto;
  flex-grow: 0;
}

.lasts-input-sentence #dynamic-qty-display {
  font-size: 0.9rem;
}

.lasts-input-sentence .number-input-container.days-number-input {
  width: 70px;
  flex-shrink: 0;
  margin-bottom: 0;
  height: 36px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  position: relative;
}

.lasts-input-sentence #item-days-last {
  padding: 6px 8px 6px 10px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 0.9rem;
  box-sizing: border-box;
  height: 36px;
  text-align: left;
  width: 100%;
  line-height: 1;
}

/* Shrink chevrons so they fit inside the reduced height */
.days-number-input .number-input-controls {
  right: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: calc(100% - 8px);
  justify-content: center;
}

.days-number-input .number-input-up,
.days-number-input .number-input-down {
  width: 10px;
  height: 10px;
}

.days-number-input .number-input-up svg,
.days-number-input .number-input-down svg {
  width: 10px;
  height: 10px;
}

.total-days-display {
  margin-left: 5px;
  color: #666;
  font-size: 0.9em;
  white-space: nowrap;
}

.buttons-container {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}

/* Ensure buttons container in the days/buttons row stays right aligned */
.days-input-and-buttons-group .buttons-container,
.input-item-name-qty-group .buttons-container {
  margin-left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.image-camera-button,
.image-upload-button,
.price-button { /* Added */
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: white;
  border: 1px solid #ced4da;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.9;
  background-size: 60%;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
}

.image-camera-button {
  background-image: url('CameraUpload.svg');
}

.image-camera-button:hover {
  opacity: 1;
}

.image-upload-button {
  background-image: url('ImageUpload.svg');
}

.image-upload-button:hover {
  opacity: 1;
}

.image-upload-button input[type="file"] {
  display: none;
}

/* NEW: Image Upload Preview Container */
.image-upload-preview-container {
  position: relative;
  width: 40px;
  height: 40px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
}

.image-upload-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  mix-blend-mode: darken;
}

/* NEW: Price button styles */
.price-button {
  background-image: url('/Price.svg'); /* Changed to Price.svg */
  background-size: 54%; /* Adjusted size for consistency */
}

.price-button:hover {
  opacity: 1;
}

.thumbnail-image {
  height: 40px;
  width: 40px;
  border-radius: 4px;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.3s ease;
  mix-blend-mode: darken; /* NEW: Image blend mode */
}

.thumbnail-image:hover {
  opacity: 0.8;
}

.input-section button {
  background-color: #2a7bce;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.2s ease-in-out;
}

.input-section button:hover {
  background-color: #1a5a9e;
}

/* Adjusted for the button being inside the new card-panel */
#save-item-btn {
  width: 100%;
  margin-top: 12px;
  background-color: #2a7bce;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.2s ease-in-out;
}

#save-item-btn:hover {
  background-color: #1a5a9e;
}

.store-input-group {
  display: flex;
  margin-bottom: 12px;
  gap: 5px;
}

.store-input-group label {
  font-size: 0.9rem;
  margin-bottom: 5px;
  color: #777;
}

/* Ensure store name input takes full width when select is hidden */
#store-name-input {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  margin-bottom: 0;
  width: 100%;
  box-sizing: border-box;
  height: 48px;
  cursor: pointer;
}

#store-select {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  width: 50%;
  box-sizing: border-box;
  height: 48px;
}

ul {
  list-style: none;
  padding: 0;
  margin-top: 10px;
}

/* List Item (li) Styling */
li {
  position: relative; /* allow absolute-positioning of the trash button */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 15px;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 4px;
  border-radius: 8px;
  background-color: #f6f6f6;
  font-size: 0.9rem;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

li:last-child {
  border-bottom: none;
}

li input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-right: 0;
}

.checked {
  color: #495057;
  
  opacity: 0.75;
}

.checked .item-name-display-only {
  text-decoration: line-through;
  opacity: 0.75;
}

/* Remove strikethrough from other elements in checked items */
.checked .item-quantity-text,
.checked .item-total-price-display,
.checked .expiry-timer,
.checked .item-unit-price-display {
  text-decoration: none!important;
}

/* New: Container for store heading and share button */
.store-heading-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 5px;
  padding-top: 20px;
}

.store-heading {
  color: #343a40;
  margin-top: 0;
  margin-bottom: 0;
  font-size: 1.3rem;
  cursor: grab;
  flex-grow: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* NEW: Collapse/Expand Icon for Store Heading */
.store-heading .collapse-icon {
  width: 18px;
  height: 18px;
  fill: #343a40;
  transition: transform 0.3s ease;
}

.store-heading.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

/* NEW: Headings for "Items to Buy" and "Already Bought" sections */
.list-section-heading {
  font-size: 1.1rem;
  color: #555;
  margin-top: 15px;
  margin-bottom: 5px;
  padding-left: 5px;
  font-weight: bold;
  border-bottom: 1px dashed #e0e0e0;
  padding-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.list-section-heading .collapse-icon {
  width: 14px;
  height: 14px;
  fill: #555;
  transition: transform 0.3s ease;
}

.list-section-heading.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

/* Store filter row buttons (logo chips) */
.store-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  width: 100%;
  box-sizing: border-box;
  justify-content: center;
  flex-wrap: wrap;
  overflow: visible;
  margin: 12px auto;
}

/* Make filter buttons fluid and responsive so they fit without scrolling */
.store-filter-button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e6e6e6;
  cursor: pointer;

  /* Flexible sizing: allow width to grow/shrink to image natural width, but keep equal height */
  flex: 0 1 auto;
  height: 56px;
  min-width: 64px;
  max-width: 320px;

  /* Ensure background logos scale to fit the button while preserving aspect ratio */
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain !important;
}

/* Ensure selected state remains visually distinct */
.store-filter-button.selected {
  border-color: #2a7bce;
  box-shadow: 0 2px 8px rgba(42,123,206,0.15);
  transform: translateY(-2px);
}

/* Force images to render normally and scale to button height while preserving aspect */
.store-filter-button img {
  height: auto !important;
  max-height: 100% !important; /* allow image height to match button */
  width: auto !important;
  max-width: 100%;
  object-fit: contain;
  display: block !important;
  mix-blend-mode: normal !important;
  background: transparent !important;
  filter: none !important;
  border-radius: 6px;
}

/* Ensure background logos scale to the button height while preserving aspect */
background-repeat: no-repeat;
background-position: center;
/* Force background logos to match button height while preserving aspect ratio */
background-size: contain;

/* Ensure images are visible in shared lists */
.store-list img,
.checked-list img,
.unchecked-list img {
  display: block !important;
  mix-blend-mode: darken !important;
  background: transparent !important;
}

/* Ensure unit price and weight display under name (left aligned) */
.store-list .item-unit-price-display,
.checked-list .item-unit-price-display,
.unchecked-list .item-unit-price-display {
  display: inline-block !important;
  color: #666;
  font-size: 0.85rem;
  white-space: nowrap;
  margin: 0;
  padding: 0;
}

/* Container for left-aligned unit info under the item name */
.item-unit-info-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* When both unit and weight are present, show them inline instead of stacked */
.item-unit-info-left.inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

/* Ensure the left info doesn't push the price; let price align right */
.item-total-price-display {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0;
  padding-left: 0;
  flex-shrink: 0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

/* Medium-small screens: 3 columns */
@media (max-width: 480px) {
  .store-filter-button {
    height: 52px;
    min-width: 60px;
    padding: 6px;
  }
  .store-filter-button img {
    max-height: 100%;
  }
}

/* Very small / narrow screens: 2 columns to avoid overflow */
@media (max-width: 360px) {
  .store-filter-button {
    height: 48px;
    min-width: 56px;
  }
  .store-filter-button img {
    max-height: 100%;
  }
}

/* Ensure container spacing above logos is preserved */
.store-heading-container {
  padding-top: 18px;
}

/* Make the grocery-list-wrapper full-width and centered */
#grocery-list-wrapper {
  width: 99%;
  max-width: 750px;
  margin: 12px auto;
  margin-bottom: 20px;
  position: relative;
}

/* Make list cards full-width and centered within their wrapper */
.list-card {
  width: 100%;
  /* Remove top/bottom padding to make it a tighter container for lists */
  padding-top: 0;
  padding-bottom: 0;
}

/* NEW: Styles for collapsed store cards/lists
   Removed restrictive max-height and overflow clipping so lists render at their full height.
   Keep a gentle transition removed to avoid accidental clipping on dynamic content. */
.list-card.collapsed .store-list,
.list-section-heading + .store-list {
  max-height: none !important;
  overflow: visible !important;
  transition: none !important;
}

.list-section-heading.collapsed + .store-list {
  /* Ensure collapse state no longer forcibly hides content — keep visible */
  max-height: none !important;
  overflow: visible !important;
}

/* Make bought items semi-transparent */
.checked-list-card {
  opacity: 0.7;
}

/* New: Wrapper for all content inside li that should be on one line */
.list-item-content {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-grow: 1;
  flex-wrap: nowrap;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f1f1f1;
  width: 100%;
}

/* For Webkit browsers (Chrome, Safari) */
.list-item-content::-webkit-scrollbar {
  height: 6px;
}

.list-item-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.list-item-content::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 10px;
}

.list-item-content::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* New style for item name display only */
.item-name-display-only {
  border: 1px solid transparent;
  padding: 2px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex-shrink: 1;
}

.item-name-display-only:hover {
  background-color: #f0f0f0;
}

/* NEW: Item quantity on the left, simple text display */
.item-quantity-text {
  font-weight: bold;
  padding: 2px;
  border-radius: 5px;
  flex-shrink: 0;
  width: 20px;
  text-align: right;
  cursor: pointer;
}

.item-quantity-text:hover {
  background-color: #f0f0f0;
}

/* NEW: Container for all elements that should be right-aligned after the item name */
.right-aligned-elements-container {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  flex-shrink: 0;
}

/* NEW: Container for relist days and price, on a separate line */
.secondary-info-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: 5px;
  padding-left: 65px;
  padding-right: 5px;
  box-sizing: border-box;
  flex-wrap: wrap;
  gap: 5px;
}

/* Adjustments for existing elements within the new container */
.expiry-timer {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0;
  padding-left: 0;
  flex-shrink: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-total-price-display {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0;
  padding-left: 0;
  flex-shrink: 0;
  white-space: nowrap;
  /* NEW: Make it a flex container to align icon and text */
  display: flex;
  align-items: center;
  gap: 4px;
  text-align: right;
  margin-left: auto;
}

/* NEW: Style for price text when on sale (keep layout, apply red background to price number only) */
.item-price-on-sale {
  /* keep parent as an inline-flex container so layout and positions don't change */
  display: inline-flex;
  align-items: center;
  /*gap: 8px;*/
  font-weight: 700;
}

/* Apply the red pill only to the numeric price span so other text remains normal.
   Numeric price text should be yellow while the pill remains red. */
.item-price-on-sale .price-number {
  background-color: #FFD700; /* Yellow background behind the number only */
  color: #dc3545; /* red price text for on-sale numeric price */
  padding: 2px 4px;
  border-radius: 6px;
  font-weight: 600;
}

/* Replace textual "On Sale" label with a small sale image (no background) placed to the left of the price */
.item-price-on-sale .on-sale-image {
  width: 25px;
  height: 15px;
  
  margin-right: 0px;
  display: inline-block;
  vertical-align: middle;
}

/* NEW: Style for unit price display in list items */
.item-unit-price-display {
  font-size: 0.85rem; /* match price sizing */
  color: #666;        /* grey tone like price */
  margin: 0 6px 0 0;
  padding: 0;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: left;
}

/* left-aligned variant (used when unit price sits left of name) */
.item-unit-price-display.left-aligned {
  order: 0;
  align-self: normal;
  margin-right: 8px;
  font-size: 0.85rem;
  color: #666;
}

.item-actions {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.delete-button {
  position: absolute;
  top: 3px;
  right: 0px;
  border: 0px solid rgba(0,0,0,0.06);
  cursor: pointer;
  padding: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  z-index: 3;
}

.delete-button svg,
.delete-button img {
  /* Make trash icon 40% smaller than before using em-based height */
  height: 0.6em;
  width: auto;
  display: block;
  vertical-align: middle;
  transition: opacity 0.18s ease, transform 0.18s ease, fill 0.18s ease;
  opacity: 0.5; /* 50% transparent by default */
  /* Keep SVG fill for older SVG usage */
  fill: #dc3545;
}

/* On hover hide the icon (0% opacity) */
.delete-button:hover svg,
.delete-button:hover img {
  opacity: 0;
  transform: translateY(-1px);
}
/* Slightly reduce lid/can visual crowding by nudging lid up via transform on the lid path group */
.delete-button svg .trash-lid {
  transform-origin: center;
  transform: translateY(-2px);
}

.delete-button:hover svg {
  fill: #c82333;
}

.input-section input:focus,
.input-section select:focus,
#store-name-input:focus,
.days-input-and-buttons-group input[type="number"]:focus,
.input-item-name-qty-group .quantity-number-input input[type="number"]:focus,
.item-name-input-wrapper #item-name:focus { /* Add focus for new wrapper input */
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Override image popup for transparent background and blur */
.image-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent !important;
  backdrop-filter: blur(8px) !important;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* Ensure popup content has transparent background */
.image-popup-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: transparent !important;
  background-image: none !important;
  padding: 0 !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
}

/* Apply darken blend mode to popup images */
.image-popup-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  mix-blend-mode: darken !important;
  background: transparent !important;
}

/* Make image upload preview container transparent */
.popup-image-preview-wrapper {
  background-color: transparent !important;
}

.image-popup-close {
  position: absolute;
  top: -30px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 30px;
  cursor: pointer;
  z-index: 1001;
}

/* Adjust thumbnail container */
.thumbnail-container {
  flex-shrink: 0;
  width: 30px;
}

.thumbnail-image {
  height: 30px;
  width: 30px;
  border-radius: 4px;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.3s ease;
  mix-blend-mode: darken;
}

.thumbnail-image:hover {
  opacity: 0.8;
}

.number-input-container {
  position: relative;
  display: flex;
  align-items: center;
  /* Removed height property to allow content to dictate height */
}

.number-input-controls {
  position: absolute;
  right: 5px;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  gap: 2px;
  opacity: 1;
}

.quantity-number-input .number-input-controls,
.days-number-input .number-input-controls {
  display: flex;
}

.number-input-up,
.number-input-down {
  width: 12px;
  height: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

.number-input-up:hover,
.number-input-down:hover {
  opacity: 1;
}

.number-input-up svg,
.number-input-down svg {
  width: 12px;
  height: 12px;
}

/* NEW: Generic Modal Styles for consistency */
.websim-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  box-sizing: border-box;
  overflow-y: auto;
}

.websim-modal-content {
  background: rgba(255, 255, 255, 0.0);
  backdrop-filter: blur(24px);
  padding: 15px;
  border-radius: 8px;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.24);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 30px;
  max-height: 95vh;
  overflow-y: auto;
}

/* Apply new generic overlay/content styles to existing popups */
.item-details-popup-overlay {
  /* No background property here, it's handled by .websim-modal-overlay */
  z-index: 2000;
}

.item-details-popup-content {
  /* This now adds or overrides styles on .websim-modal-content */
  /* No need to redefine background/box-shadow/padding if they are the same as websim-modal-content */
}

.price-input-popup-overlay {
  /* No background property here, it's handled by .websim-modal-overlay */
  z-index: 2002;
}

.price-input-popup-content {
  /* This now adds or overrides styles on .websim-modal-content */
  /* No need to redefine background/box-shadow/padding if they are the same as websim-modal-content */
}

.popup-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #f0f0f0;
  color: #555;
  border: none;
  font-size: 24px;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.popup-close-button:hover {
  background-color: #e0e0e0;
}

/* NEW: Container for name and quantity in popup (the blue box) */
.popup-name-qty-card {
  /* Re-purposed to be a container for name, and quantity */
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 12px;
  box-sizing: border-box;
  border-radius: 8px;
  background-color: #e8f4fd;
  border: 1px solid #b8e0ff;
  margin-top: 0px;
  cursor: default;
  transition: background-color 0.2s;
  padding-top: 10px;
  padding-bottom: 10px;
}

.popup-name-qty-card:hover {
  background-color: #dff0f9;
}

/* NEW: Container for name and quantity inside the blue box */
.popup-name-qty-inner-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 0px;
  flex-wrap: wrap;
}

/* Adjustments for name/qty elements inside the new blue container */
.popup-name-qty-inner-container .popup-item-name-display,
.popup-name-qty-inner-container .popup-item-name-input,
.popup-name-qty-inner-container .popup-item-weight-input {
  flex-grow: 1;
  width: auto;
  margin-bottom: 0;
}

.popup-name-qty-inner-container .popup-qty-display {
  flex-shrink: 0;
  width: 45px;
  max-width: 45px;
  margin-bottom: 0;
}

.popup-name-qty-inner-container .popup-qty-input-container {
  flex-shrink: 0;
  width: 55px;
  max-width: 55px;
  margin-bottom: 0;
}

.popup-name-qty-inner-container .popup-qty-input-container input[type="number"] {
  padding: 10px;
  padding-right: 22px;
  height: 40px;
}

.popup-name-qty-inner-container .number-input-controls {
  right: 2px;
  gap: 1px;
}

/* NEW: Price Display Row (outside the blue box) */
.popup-price-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
  font-size: 1.1rem;
  color: #333;
  width: 100%;
  box-sizing: border-box;
  flex-wrap: wrap;
}

.popup-price-row:hover {
  background-color: #e9ecef;
  border-color: #a7a7a7;
}

.popup-price-row span {
  flex-grow: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Add an indicator or icon to the price row to show it's clickable */
.popup-price-row::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  background-image: url('/sale.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.popup-price-row:hover::after {
  opacity: 1;
}

/* NEW: Relist section in popup */
.popup-relist-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  justify-content: center;
}

.popup-relist-section label,
.popup-relist-section span {
  white-space: nowrap;
  font-size: 1.1rem;
  color: #495057;
}

.popup-relist-section .number-input-container {
  flex-grow: 1;
  flex-shrink: 1;
  width: 70px;
  max-width: 85px;
}

.popup-relist-section input[type="number"] {
  padding: 12px -10px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1.1rem;
  box-sizing: border-box;
  height: 40px;
  text-align: center;
  width: 100%;
}

.popup-relist-section input[type="number"]:disabled {
  background-color: #e9ecef;
  cursor: not-allowed;
  opacity: 0.7;
}

.popup-image-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.popup-image-preview-container { /* NEW */
  position: relative;
  width: 100%;
  max-width: 300px;
  height: 250px;
  overflow: hidden;
  /*border-radius: 8px;
  border: 1px solid #eee;*/
  display: flex;
  justify-content: center;
  align-items: center;
/*  box-shadow: 0 2px 10px rgba(0,0,0,0.1); /* Subtle shadow */

  background-color: transparent;
 /* background-image: url('/ImageBG.png'); /* Set ImageBG.png as background */
  background-size: cover;
  background-position: center;
}

.popup-image-preview {
  max-width: 50%;
  max-height: 10%;
  object-fit: contain;
  border-radius: 8px;
  cursor: pointer;
  background-color: transparent;
}

.popup-remove-image-x-button { /* NEW */
  position: absolute;
  top: 5px;
  right: 5px;
  background-color: rgba(220, 53, 69, 0.8); /* Red with transparency */
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 1;
  transition: background-color 0.2s;
}

.popup-remove-image-x-button:hover {
  background-color: #dc3545; /* Solid red on hover */
}

.popup-image-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Re-use existing image button styles for popup */
.popup-camera-button,
.popup-upload-button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
  border: 1px solid #ced4da;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.3s ease;
  background-size: 65%;
  background-repeat: no-repeat;
  background-position: center;
}

.popup-camera-button {
  background-image: url('CameraUpload.svg');
}

.popup-camera-button:hover {
  opacity: 1;
}

.popup-upload-button {
  background-image: url('ImageUpload.svg');
}

.popup-upload-button:hover {
  opacity: 1;
}

.popup-upload-button input[type="file"] {
  display: none;
}

.popup-remove-image-button { /* Hidden, functionality replaced by X button */
  display: none;
}

.popup-save-button {
  width: 100%;
  background-color: #2a7bce;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.2s ease-in-out;
  margin-top: 10px;
}

.popup-save-button:hover {
  background-color: #1a5a9e;
}

/* NEW: Total price and relist info display below inputs */
.item-info-display {
  margin-top: 10px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  color: #333;
  text-align: center;
  padding: 8px;
  background-color: #f0f8ff;
  border: 1px solid #add8e6;
  border-radius: 8px;
  display: none;
}

/* NEW: Price Input Popup Styles */
.price-input-popup-content .price-input-group {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
}

.price-input-popup-content .price-input-group label {
  flex-shrink: 0;
  font-size: 1.1rem;
  font-weight: bold;
}

/* Applying modal-input-field for price and other text inputs in the price modal */
.price-input-popup-content .modal-input-field {
  padding: 10px;
  height: 40px;
  font-size: 1rem;
}

/* Hide default number input arrows in Chrome, Safari, Edge */
.price-input-popup-content input[type=number]::-webkit-inner-spin-button,
.price-input-popup-content input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* NEW: On Sale Toggle Button */
.on-sale-toggle-button {
  flex-shrink: 0;
  /* allow the button to size to its label while keeping a minimum tappable area */
  min-width: 100px;
  height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  background-color: #f0f0f0;
  color: #555;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

.on-sale-toggle-button:hover {
  background-color: #e0e0e0;
}

.on-sale-toggle-button.active {
  background: linear-gradient(to right, #dc3545, #ff4c4c);
  color: white;
  font-weight: 700;
  border-color: #dc3545;
}

/* Overlay the sale.png when active */
.on-sale-toggle-button::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background-image: url('/sale.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.on-sale-toggle-button.active::after {
  opacity: 1;
}

/* NEW: On Sale icon for list items */
.on-sale-indicator {
  color: #28a745;
  font-size: 0.75em;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.on-sale-icon {
  width: 16px;
  height: 16px;
  background-image: url('/sale.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: inline-block;
}

.price-input-popup-content .popup-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.price-input-popup-content button {
  padding: 10px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  border: none;
}

.price-input-popup-content .save-btn {
  background-color: #2a7bce;
  color: white;
}

.price-input-popup-content .cancel-btn {
  background-color: #f0f0f0;
  color: #333;
}

/* NEW: Grand Total Price Display - sticky at bottom */
.grand-total-price {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 15px 20px;
  background-color: #2a7bce;
  color: white;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.10);
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  z-index: 999;
  transition: transform 0.3s ease;
}

/* NEW: Container for bottom action buttons */
.bottom-actions-container {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  width: 99%;
  max-width: 750px;
  margin: 15px auto 20px auto;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-direction: column;
  gap: 6px;
  flex-grow: 1;
  min-width: 140px;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.2s ease-in-out, box-shadow 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: none;
  color: #111; /* Changed from white to near-black for better visibility */
}

#downloadListBtn {
  background-color: #4CAF50; /* Green */
}

#downloadListBtn:hover {
  background-color: #45a049;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#uploadListBtn {
  background-color: #007bff; /* Blue */
}

#uploadListBtn:hover {
  background-color: #0056b3;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Retain migrate button specific styles, make it also an action-button */
.migrate-button {
  background: linear-gradient(135deg, #ff6b35, #ff8c42);
}

.migrate-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4);
}

/* NEW: Styles for elements within the custom store selection modal */
.store-selection-modal-content {
  /* Inherits websim-modal-content styles */
}

.store-selection-modal-content input[type="text"] {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  box-sizing: border-box;
  height: 40px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.store-selection-modal-content input[type="text"]:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.store-selection-modal-content button {
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.2s ease-in-out, border-color 0.2s, box-shadow 0.2s ease;
  border: 1px solid #ced4da;
  height: 40px;
  box-sizing: border-box;
}

.store-selection-modal-content button:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.store-selection-modal-content button.add-btn { /* Specific style for Add button */
  background-color: #28a745; /* Green for prominence */
  color: white;
  border-color: #28a745;
}

.store-selection-modal-content button.add-btn:hover {
  background-color: #218838;
  border-color: #218838;
}

.store-selection-modal-content button.store-list-button {
  /* Neutral button so logos (when present) are shown centered,
     and plain text is clearly visible when no logo exists. */
  background-color: #f6f6f6;
  color: #333;
  border-color: #e6e6e6;
  width: 100%;
  margin-bottom: 5px;

  display: flex;
  align-items: center;
  justify-content: center; /* center logos when present */
  gap: 8px;
  padding: 8px;
  box-sizing: border-box;
  text-align: center;

  /* Make store modal buttons rounded and touch-friendly */
  border-radius: 10px;
  transition: background-color 0.15s ease, transform 0.08s ease;
  overflow: hidden;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

/* Ensure hover/selected states keep rounded corners and subtle elevation */
.store-selection-modal-content button.store-list-button:hover {
  background-color: #e9eef8;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}

.store-selection-modal-content button.store-list-button.selected {
  background-color: #0056b3;
  border-color: #0056b3;
  box-shadow: 0 8px 24px rgba(42,123,206,0.18);
  transform: translateY(-2px);
  color: #fff;
}

/* When a logo image is present inside the button keep it centered and prevent any broken-icon fallback from being visible.
   The JS sets img.onerror to hide broken images, but ensure the image itself scales nicely here. */
.store-selection-modal-content button.store-list-button img {
  display: block;
  max-height: 56px;
  height: auto;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* If a button contains only text (no img), ensure the label is readable and centered */
.store-selection-modal-content button.store-list-button span {
  display: block !important;
  color: #333 !important;
  font-size: 1rem;
  text-align: center;
  width: 100%;
}

.store-selection-modal-content button.store-list-button:last-of-type {
  margin-bottom: 0;
}

.store-selection-modal-content button.store-list-button:hover {
  background-color: #1a5a9e;
  border-color: #1a5a9e;
}

.store-selection-modal-content button.store-list-button.selected {
  background-color: #0056b3;
  border-color: #0056b3;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.5);
}

.store-selection-modal-content button.cancel-btn {
  background-color: #f0f0f0;
  color: #333;
  border-color: #ced4da;
}

.store-selection-modal-content button.cancel-btn:hover {
  background-color: #e0e0e0;
}

.modal-secondary-button { /* New class for "Find Nearby Supermarkets" */
  background-color: #f8f9fa; 
  color: #495057; 
  border: 1px solid #ced4da;
  width: 100%; 
  margin-bottom: 10px;
}

.modal-secondary-button:hover {
  background-color: #e2e6ea;
  border-color: #dae0e5;
}

/* NEW: Styles for the image viewer modal */
.image-viewer-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: 8px;
  background-color: white;
  background-image: url('/ImageBG.png');
  background-size: cover;
  background-position: center;
  padding: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.10);
}

.image-viewer-modal-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  mix-blend-mode: darken;
}

/* NEW: Styles for the Change Store button in the edit modal */
.edit-item-change-store-btn {
  background: #4CAF50; /* Green */
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.2s ease-in-out;
  margin-top: 8px;
  flex-grow: 1;
}

.edit-item-change-store-btn:hover {
  background-color: #45a049;
}

/* NEW: Popup item name and weight inputs */
.popup-item-name-input,
.popup-item-weight-input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  box-sizing: border-box;
  height: 40px;
  margin-bottom: 5px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.popup-item-name-input:focus,
.popup-item-weight-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.popup-item-weight-input {
  margin-top: 0;
  margin-bottom: 0;
}

/* NEW: Global input field style for modals */
.modal-input-field {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ced4da;
  font-size: 1rem;
  height: 48px;
  box-sizing: border-box;
  transition: all 0.3s ease;
  width: 100%;
}

.modal-input-field:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* NEW: Styles for the Import Data Modal content */
.import-data-modal-content h4 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #343a40;
  font-size: 1.2rem;
}

.import-data-modal-content #paste-checklist-input {
  height: 120px;
  resize: vertical;
  font-family: 'Arial', sans-serif;
  white-space: pre-wrap;
  overflow-y: auto;
}

/* Add styles for store logo upload button */
.store-logo-upload-btn {
  width: 32px;
  height: 32px;
  background: url('ImageUpload.svg') no-repeat center center;
  background-size: 60%;
  border: 1px solid #ced4da;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.3s ease;
}

.store-logo-upload-btn:hover {
  opacity: 1;
}

/* New grand total container styles */
.grand-total-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 15px 20px;
  background-color: #2a7bce;
  color: white;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.10);
   display: flex;
   justify-content: space-between;
   align-items: center;
   z-index: 999;
   transition: all 0.3s ease;
}

.grand-total-display {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  flex-grow: 1;
}

#start-shop-btn,
#finish-shop-btn {
  width: 50px;
  height: 50px;
  border: none;
  cursor: pointer;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-color: transparent;
  transition: transform 0.2s ease;
}

#start-shop-btn:hover,
#finish-shop-btn:hover {
  transform: scale(1.1);
}

/* Shopping session active styles */
.shopping-session-active .grand-total-container {
  display: flex;
}

/* Ensure the PWA install button uses the app icon (override any residual camera/icon rules) */
/* REMOVED the #installAppBtn block so no install button is shown and automatic prompt is used instead */


@media (max-width: 768px) {
  /* Mobile: scale global font sizes 10% smaller to keep layout proportional on small screens */
  html, body { font-size: 90%; }
  .days-input-and-buttons-group {
    gap: 6px;
    flex-wrap: wrap;
    overflow-x: visible;
    scrollbar-width: none;
  }
  .days-input-and-buttons-group::-webkit-scrollbar {
    display: none;
  }
  body {
    padding: 10px;
  }

  /* card panels for smaller screens */
  .card-panel {
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    width: 99%;
    max-width: 750px;
  }

  h1 {
    font-size: 2rem;
    margin-bottom: 15px;
  }

  .input-section {
    margin-bottom: 15px;
    padding-bottom: 0;
    border-bottom: none;
  }

  .lasts-input-sentence #item-days-last {
    padding: 10px 20px;
    height: 44px;
    font-size: 1rem;
  }

  /* NEW: Combined input group for mobile */
  .input-item-name-qty-group {
    flex-direction: row;
    gap: 6px;
    margin-bottom: 12px;
  }

  /* item-name-input-wrapper adjustments */
  .item-name-input-wrapper #item-name {
    width: auto;
    padding: 10px;
    font-size: 0.9rem;
    height: 44px;
    padding-right: 40px;
  }

  .item-name-input-wrapper .supermarket-search-button {
    width: 28px;
    height: 28px;
    right: 6px;
    background-size: 60%;
    border-radius: 8px;
  }

  /* Quantity input within the combined group for mobile */
  .input-item-name-qty-group .quantity-number-input {
    width: 45px;
  }

  .input-item-name-qty-group .quantity-number-input input[type="number"] {
    width: 100%;
    padding: 10px;
    height: 44px;
    padding-right: 15px;
    font-size: 0.9rem;
  }

  .input-section select,
  .input-section input[type="text"] {
    padding: 10px;
    font-size: 0.9rem;
  }

  .input-section button {
    padding: 10px 18px;
    font-size: 1rem;
  }

  #store-name-input,
  #store-select {
    height: 44px;
    padding: 10px;
    font-size: 0.9rem;
  }

  li {
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 0.9rem;
  }

  .store-heading {
    font-size: 1.1rem;
    margin-top: 0;
    margin-bottom: 0;
  }

  .expiry-timer {
    font-size: 0.75rem;
  }

  .image-camera-button,
  .image-upload-button,
  .price-button { /* Added */
    height: 34px;
    width: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: white;
    border: 1px solid #ced4da;
    border-radius: 8px;
  }
 button {  padding: 6px; border: 1px solid #ced4da; border-radius: 5px;}
  }
  .thumbnail-image {
    height: 25px;
    width: 25px;
  }

  /* Item Details Popup for mobile */
  .item-details-popup-overlay {
    padding: 20px;
  }

  .item-details-popup-content {
    padding: 10px;
    margin-bottom: 15px;
    gap: 6px;
    max-height: 95vh;
  }

  .popup-item-name-input,
  .popup-item-name-input, /* Added for mobile */
  .popup-item-weight-input {
    font-size: 1rem;
    padding: 10px;
  }
  
  .popup-relist-section input[type="number"] { /* Mobile-specific adjustments for relist days input */
    font-size: 1rem;
    height: 44px;
    padding: 10px 20px;
  }
  
  .popup-camera-button,
  .popup-upload-button,
  .popup-remove-image-button {
    padding: 8px 12px;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  .popup-save-button {
    padding: 10px 18px;
    font-size: 1rem;
  }

  .popup-qty-input-container,
  .popup-relist-section .number-input-container {
    width: 100px;
    max-width: 100px;
  }
  
  .store-input-group,
  .days-input-and-buttons-group {
    margin-bottom: 12px;
  }
  
  #save-item-btn {
    margin-top: 12px;
  }

  /* NEW: Total price and relist info display below inputs */
  .item-info-display {
    font-size: 0.85rem;
  }

  /* Adjust grand total for mobile */
  .grand-total-price {
    font-size: 1rem;
    padding: 10px 15px;
    border-radius: 10px 10px 0 0;
    bottom: 50px;
  }

  /* NEW: Adjust download button for mobile */
  .bottom-actions-container {
    padding: 10px 15px;
    font-size: 1rem;
    margin-bottom: 15px;
  }

  /* Adjust name/qty elements inside the new blue container for mobile */
  .popup-name-qty-inner-container .popup-item-name-display {
    min-width: 0;
  }
  .popup-name-qty-inner-container .popup-item-name-input,
  .popup-name-qty-inner-container .popup-item-weight-input {
    min-width: unset;
    width: 100%;
  }

  .popup-name-qty-inner-container .popup-qty-display,
  .popup-name-qty-inner-container .popup-qty-input-container {
    width: 60px;
    max-width: 60px;
  }

  /* Adjustments for mobile for the new price row */
  .popup-price-row {
    font-size: 1rem;
    padding: 6px 10px;
  }

  /* Mobile specific adjustments for edit-item-change-store-btn */
  .edit-item-change-store-btn {
    padding: 10px 15px;
    font-size: 0.8rem;
  }

  /* Buttons within store selection modal for mobile */
  .store-selection-modal-content button {
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .popup-image-section {
    margin-top: 5px;
  }

  .popup-image-buttons {
    flex-direction: row;
    justify-content: center;
  }

  /* Background removal modal styles for mobile */
  .websim-modal-content {
    max-height: 95vh;
  }

  .popup-image-preview-wrapper {
    max-height: calc(50vh - 150px);
  }

  /* Ensure buttons are visible and accessible */
  .popup-save-button,
  .cancel-btn {
    padding: 12px 16px;
    font-size: 1rem;
    min-height: 44px;
  }
}

/* Ensure top padding equals card-panel padding on small screens */
.store-heading-container {
  padding-top: 15px;
}

/* Make popup qty input match other inputs in height and be slightly wider */
.popup-name-qty-card .popup-qty-input-container input[type="number"],
.popup-name-qty-card .popup-item-name-input,
.popup-name-qty-card .modal-input-field {
  height: 48px;
  min-height: 48px;
  padding: 10px;
  box-sizing: border-box;
}

/* Ensure numeric inputs inside the edit modal fill their container and show 2-decimal behavior elsewhere */
.popup-name-qty-card .popup-qty-input-container,
.popup-name-qty-card .popup-qty-input-container input[type="number"] {
  width: 100%;
  min-width: 60px;
}

/* NEW: Similarity control row - iOS style switch left, slider fills remaining row */
.similarity-control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
}

/* Container for switch + label */
.similarity-switch-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* iOS-style switch */
.similarity-switch {
  --switch-width: 44px;
  --switch-height: 26px;
  --switch-bg: #e6e6e6;
  --switch-bg-checked: #34c759;
  --switch-knob: #fff;
  position: relative;
  width: var(--switch-width);
  height: var(--switch-height);
  border-radius: calc(var(--switch-height) / 2);
  background: var(--switch-bg);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.03);
  cursor: pointer;
  transition: background 180ms ease;
  display: inline-block;
  vertical-align: middle;
}

/* hidden checkbox for accessibility */
.similarity-switch input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

/* knob */
.similarity-switch .knob {
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  width: calc(var(--switch-height) - 6px);
  height: calc(var(--switch-height) - 6px);
  background: var(--switch-knob);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
  transition: left 180ms cubic-bezier(.2,.9,.2,1), transform 120ms ease;
}

/* checked state */
.similarity-switch.checked {
  background: var(--switch-bg-checked);
}

/* knob moves when checked */
.similarity-switch.checked .knob {
  left: calc(100% - (var(--switch-height) - 3px));
}

/* Slider takes remaining space to the right of the switch row */
.similarity-control-row .similarity-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 32px;
  flex: 1 1 auto;
  min-width: 80px;
  background: transparent;
  display: block;
  margin: 0;
}

/* slider track and thumb styling */
.similarity-control-row .similarity-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d0e7ff, #cfeef0);
}
.similarity-control-row .similarity-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d0e7ff, #cfeef0);
}
.similarity-control-row .similarity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  margin-top: -5px;
}
.similarity-control-row .similarity-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  border: none;
}

/* show the numeric value next to slider if needed */
.similarity-control-row .similarity-value {
  width: 48px;
  text-align: right;
  font-weight: 700;
  color: #333;
  flex-shrink: 0;
}

/* Responsive: tighten spacing on small screens */
@media (max-width: 420px) {
  .similarity-control-row { gap: 8px; padding: 6px 4px; }
  .similarity-switch { --switch-width: 40px; --switch-height: 22px; }
  .similarity-control-row .similarity-value { width: 44px; font-size: 0.95rem; }
}

/* Number input chevron visibility:
   - Desktop / landscape: controls appear on hover to keep UI clean
   - Mobile (<=420px): always-visible polygon-style controls (touch-friendly)
*/
.number-input-controls {
  opacity: 0;
  transition: opacity 0.16s ease;
  pointer-events: none;
}

/* Show controls when hovering parent container (desktop) */
.number-input-container:hover > .number-input-controls,
.number-input-container:focus-within > .number-input-controls {
  opacity: 1;
  pointer-events: auto;
}

/* On small screens make controls always visible and slightly larger for touch */
@media (max-width: 420px) {
  .number-input-controls {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .number-input-up svg,
  .number-input-down svg {
    width: 14px;
    height: 14px;
  }
  .number-input-up,
  .number-input-down {
    width: 18px;
    height: 18px;
  }
}

/* Globally hide scrollbars while preserving scroll functionality */
*::-webkit-scrollbar {
  display: none !important;
}
* {
  -ms-overflow-style: none !important;  /* IE and Edge */
  scrollbar-width: none !important;     /* Firefox */
}

/* Edit item modal: explicit two-row layout for the blue form (pure CSS)
   - Force the modal into "edit form only" mode by hiding display-only elements
   - Top row: Qty 10%, Item Name 90% (name left-aligned)
   - Second row: Price (with $ prefix), Unit Price, Amount — equal thirds filling 100% */

/* Container that holds the blue card */
.popup-name-qty-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  box-sizing: border-box;
  opacity: 75%;
}

/* Logical rows inside the blue box */
.popup-name-qty-card .edit-top-row,
.popup-name-qty-card .edit-second-row {
  display: flex;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
}

/* Top row children: Qty (10%) then Item Name (90%) */
/* Qty should be first (left) and occupy ~10% */
.popup-name-qty-card .edit-qty-field {
  order: 0;
  /* Slightly wider column for qty so it aligns visually with other inputs */
  flex: 0 0 12%;
  max-width: 12%;
  min-width: 60px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

/* Name occupies remaining width and is left-aligned */
.popup-name-qty-card .edit-name-field {
  order: 1;
  flex: 1 1 90%;
  max-width: 90%;
  min-width: 0;
  text-align: left;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

/* Ensure editable inputs are shown and display-only elements are hidden
   so the modal is the edit form (CSS-only change, JS remains unchanged) */
.popup-name-qty-card .popup-item-name-display,
.popup-name-qty-card .popup-qty-display {
  display: none !important; /* hide static/display-only views */
}

/* Show inputs for editing */
.popup-name-qty-card .modal-input-field,
.popup-name-qty-card .popup-qty-input-container,
.popup-name-qty-card .popup-item-name-input,
.popup-name-qty-card .popup-item-weight-input {
  display: block !important;
}

/* Second row children — three equal columns (Price, Unit Price, Amount) */
/* Use flex: 1 so they fill available width equally */
/* Make Price column narrower and let Unit/Amount auto-resize to fill remaining space */
.popup-name-qty-card .edit-price-field {
  flex: 0 0 28%;
  max-width: 28%;
  min-width: 120px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Let Unit and Amount expand to fill the remainder responsively */
.popup-name-qty-card .edit-unit-field,
.popup-name-qty-card .edit-amount-field {
  flex: 1 1 36%;
  max-width: none;
  min-width: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Hide the secondary weight/amount input that was rendering in the top row so top row only shows Qty + Item */
.popup-name-qty-card .edit-top-row .popup-item-weight-input,
.popup-name-qty-card .edit-top-row .popup-item-weight-input + * {
  display: none !important;
}

/* Make Change Store and Save buttons equal width inside the edit modal */
.edit-item-change-store-btn,
.popup-save-button {
  flex: 1 1 0;
  min-width: 0;
}

/* Price wrapper: show $ prefix as a left static element next to numeric input */
.popup-name-qty-card .edit-price-field .popup-price-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}
.popup-name-qty-card .edit-price-field .popup-price-input-wrapper .dollar-prefix {
  font-weight: 700;
  color: #333;
  margin-left: 6px;
  flex: 0 0 auto;
}

/* Make numeric inputs fill their columns */
.popup-name-qty-card .edit-price-field input[type="number"],
.popup-name-qty-card .edit-unit-field input[type="text"],
.popup-name-qty-card .edit-amount-field input[type="text"],
.popup-name-qty-card .popup-qty-input-container input[type="number"],
.popup-name-qty-card .popup-item-name-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #ced4da;
}

/* Ensure qty input container (with controls) is visible and styled */
.popup-name-qty-card .popup-qty-input-container {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Responsive fallback: on very small screens stack second row into vertical flow */
@media (max-width: 420px) {
  /* Keep the same two-row proportions on small screens in landscape: do not stack second row */
  .popup-name-qty-card .edit-top-row {
    flex-direction: row;
  }
  .popup-name-qty-card .edit-qty-field {
    flex-basis: 22%;
    max-width: 22%;
  }
  .popup-name-qty-card .edit-name-field {
    flex-basis: 78%;
    max-width: 78%;
  }
  /* Keep second row horizontal but slightly adjust proportions for narrow screens */
  .popup-name-qty-card .edit-second-row {
    flex-direction: row;
    gap: 6px;
  }
  .popup-name-qty-card .edit-price-field {
    flex: 0 0 30%;
    max-width: 30%;
    min-width: 100px;
  }
  .popup-name-qty-card .edit-unit-field,
  .popup-name-qty-card .edit-amount-field {
    flex: 1 1 35%;
    max-width: none;
    min-width: 0;
  }

  /* Slightly reduce input text size so fields fit proportionally */
  .popup-name-qty-card .modal-input-field,
  .popup-name-qty-card .popup-price-input {
    font-size: 0.95rem;
    height: 40px;
  }
}