// Variables
$primary-color: #3f51b5;
$secondary-color: #f50057;
$success-color: #4caf50;
$warning-color: #ff9800;
$danger-color: #f44336;
$text-color: #333;
$light-gray: #f5f5f5;
$medium-gray: #e0e0e0;
$dark-gray: #9e9e9e;
$white: #fff;

// Mixins
@mixin card {
  background-color: $white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@mixin flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

// Main container
.machine-details-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 100%;
}

// Header bar
.header-bar {
  @include flex-between;
  padding: 0.5rem 0;
  margin-bottom: 1rem;

  .back-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: transparent;
    border: 1px solid $medium-gray;
    border-radius: 4px;
    color: $text-color;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover { background-color: $light-gray; }
  }

  .save-button {
    padding: 0.5rem 1rem;
    background-color: $primary-color;
    color: $white;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;

    &:hover { background-color: darken($primary-color, 10%); }
  }
}

// Info card
.info-card {
  @include card;
  padding: 1.5rem;
  margin-bottom: 1.5rem;

  h3 {
    font-size: 1.2rem;
    margin-top: 0;
    margin-bottom: 1rem;
    font-weight: 500;
    color: $text-color;
  }

  .info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;

    .info-item {
      display: flex;
      flex-direction: column;
      gap: 0.25rem;

      .label {
        color: $dark-gray;
        font-size: 0.85rem;
      }

      .value {
        font-weight: 500;
        font-size: 1rem;

        &.status-active, &.status-online { color: $success-color; }
        &.status-inactive, &.status-offline { color: $danger-color; }
      }
    }
  }
}

// Vending container & row
.vending-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.vending-row {
  @include card;
  padding: 1.5rem;
  position: relative;

  .row-title {
    @include flex-between;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 500;

    .scroll-hint {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      font-size: 0.8rem;
      color: $dark-gray;
    }
  }

  // Scrollable slots container
  .slots-container {
    display: flex;
    overflow-x: auto;
    gap: 1rem;
    padding-bottom: 1rem;
    position: relative;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: $dark-gray $light-gray;

    &::-webkit-scrollbar {
      height: 6px;
      &-track { background: $light-gray; border-radius: 3px; }
      &-thumb { background-color: $dark-gray; border-radius: 3px; }
    }
  }

  // Scroll shadows
  .scroll-shadows {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: linear-gradient(90deg, rgba(0,0,0,0.1) 0%, transparent 10%, transparent 90%, rgba(0,0,0,0.1) 100%);
    pointer-events: none;
  }
}

// Slot card
.slot-card {
  min-width: 180px;
  width: 180px;
  background-color: $white;
  border: 1px solid $medium-gray;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.2s ease;

  &:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }

  &.disabled {
    opacity: 0.6;
    background-color: $light-gray;
    cursor: not-allowed;

    &:hover {
      box-shadow: none;
      transform: none;
    }
  }

  .slot-header {
    @include flex-between;
    padding: 0.5rem;
    background-color: $light-gray;
    border-bottom: 1px solid $medium-gray;

    .slot-name {
      font-weight: 500;
      font-size: 0.9rem;
    }

    .toggle-container {
      display: flex;
      align-items: center;
      gap: 0.25rem;

      .status-text {
        font-size: 0.7rem;
        &.enabled { color: $success-color; }
        &.disabled { color: $danger-color; }
      }
    }
  }

  .slot-body {
    height: 120px;
    padding: 0.75rem;
    cursor: pointer;

    .empty-slot {
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 0.5rem;
      color: $dark-gray;

      .add-product-icon { font-size: 1.5rem; }
      .add-product-text { font-size: 0.85rem; margin: 0; }
    }

    .product-image-container {
      height: 60px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 0.5rem;
      position: relative; // Added for pseudo-element positioning
      background-color: $light-gray; // Added subtle background for visibility
      overflow: hidden; // Prevent image overflow
    
      .product-image {
        max-height: 100%;
        max-width: 100%;
        object-fit: contain;
        display: block; // Ensure proper rendering
        transition: opacity 0.2s ease; // Smooth transition for error state
    
        // Error state when image fails to load
        &.error {
          opacity: 0;
        }
      }
    
      // Placeholder for when image fails to load
      &::after {
        content: 'No Image';
        position: absolute;
        display: none;
        color: $dark-gray;
        font-size: 0.8rem;
        font-style: italic;
      }
    
      // Show placeholder when image has error
      &.has-error::after {
        display: block;
      }
    }

    .product-details {
      .product-header {
        @include flex-between;
        align-items: flex-start;
        margin-bottom: 0.25rem;

        .product-name {
          font-weight: 500;
          font-size: 0.85rem;
          margin: 0;
          line-height: 1.2;
          max-width: 130px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .remove-product {
          background: none;
          border: none;
          color: $danger-color;
          padding: 0;
          font-size: 0.8rem;
          cursor: pointer;
        }
      }

      .product-stats {
        margin: 0;
        font-size: 0.8rem;
        color: $dark-gray;
        display: flex;
        align-items: center;
        gap: 0.25rem;

        .units-input {
          width: 40px;
          padding: 0.25rem;
          text-align: center;
          border: 1px solid $medium-gray;
          border-radius: 3px;
        }
      }
    }
  }
}
// ... Previous SCSS remains the same ...

.error-message {
  background-color: #ffebee;
  border: 1px solid #ef5350;
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;

  p {
    margin: 0;
    color: #d32f2f;
    font-weight: 500;
  }

  .retry-button {
    padding: 0.5rem 1rem;
    background-color: #ef5350;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;

    &:hover {
      background-color: darken(#ef5350, 10%);
    }
  }
}

// ... Rest of the SCSS remains the same ...

// Switch toggle
.switch {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 16px;

  input {
    opacity: 0;
    width: 0;
    height: 0;

    &:checked + .slider {
      background-color: $success-color;
      &:before { transform: translateX(14px); }
    }
  }

  .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: $dark-gray;
    transition: .4s;
    border-radius: 16px;

    &:before {
      position: absolute;
      content: "";
      height: 12px;
      width: 12px;
      left: 2px;
      bottom: 2px;
      background-color: $white;
      transition: .4s;
      border-radius: 50%;
    }
  }
}

// Modal styles
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.product-selector-modal {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  @include flex-between;
  background-color: #f5f7fa;

  h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
  }

  .close-modal {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #666;
    &:hover { color: #333; }
  }
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 70vh;
}

.search-container {
  margin-bottom: 20px;

  .search-input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
  }
}

.products-table {
  width: 100%;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.product-row {
  display: grid;
  grid-template-columns: 40px 130px 1fr 100px 80px 120px;
  grid-gap: 10px;
  align-items: center;
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;

  &:last-child { border-bottom: none; }
  &.odd { background-color: #f9f9f9; }
  &.selected { background-color: #e8f0fe; }
  &:hover { background-color: #f0f7ff; }

  .checkbox-cell { display: flex; justify-content: center; align-items: center; }
  .number-cell { text-align: center; color: #666; }
  .product-name-cell { font-weight: 500; color: #333; }
  .price-cell { text-align: right; font-weight: 500; color: #333; }
  
  .image-cell {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .quantity-cell { display: flex; justify-content: flex-end; }
}

.product-thumbnail {
  height: 30px;
  width: auto;
  max-width: 50px;
  object-fit: contain;
}

.quantity-spinner {
  display: flex;
  align-items: center;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}

.quantity-btn {
  background-color: #f0f0f0;
  border: none;
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  &:hover { background-color: #e0e0e0; }
}

.quantity-input {
  width: 40px;
  text-align: center;
  border: none;
  border-left: 1px solid #ddd;
  border-right: 1px solid #ddd;
  height: 30px;
}

.no-products {
  padding: 20px;
  text-align: center;
  color: #666;
}

.quantity-section {
  margin-top: 20px;
  padding: 15px;
  border-top: 1px solid #e0e0e0;

  h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #333;
  }

  .quantity-controls {
    display: flex;
    align-items: center;
    justify-content: center;

    .quantity-btn {
      width: 36px;
      height: 36px;
      background-color: #f0f0f0;
      border: 1px solid #ddd;
      border-radius: 4px;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;

      &.decrease {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
      }

      &.increase {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
      }
    }

    .quantity-input {
      width: 60px;
      height: 36px;
      border: 1px solid #ddd;
      text-align: center;
      border-radius: 0;
    }
  }
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background-color: #f5f7fa;
}

.btn-cancel, .btn-add {
  padding: 8px 16px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
}

.btn-cancel {
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  color: #333;
  &:hover { background-color: #e0e0e0; }
}

.btn-add {
  background-color: #4267B2;
  border: 1px solid #3b5998;
  color: white;
  &:hover:not(:disabled) { background-color: #365899; }
  &:disabled {
    background-color: #a0a0a0;
    border-color: #909090;
    cursor: not-allowed;
  }
}

@media (max-width: 768px) {
  .info-grid { grid-template-columns: 1fr !important; }
  .slot-card { min-width: 150px; width: 150px; }
  .product-selector-modal { width: 95%; }
}