/* ==========================================================================
   AI Cook & Auto-Fill Cart Styles — Punjabi Mandi
   ========================================================================== */

/* --- Homepage Embedded Section --- */
.pm-ai-recipe-wrapper {
  margin: 35px 0 25px 0;
  width: 100%;
}

.pm-ai-recipe-card {
  position: relative;
  background: linear-gradient(135deg, #184e27 0%, #1f6432 50%, #154522 100%);
  border-radius: 20px;
  padding: 38px 45px;
  color: #ffffff;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(20, 78, 38, 0.22);
}

/* Watermark illustration in the background */
.pm-ai-card-watermark {
  position: absolute;
  right: 25px;
  bottom: 10px;
  width: 170px;
  height: 170px;
  opacity: 0.14;
  pointer-events: none;
  z-index: 1;
}

.pm-ai-card-content {
  position: relative;
  z-index: 2;
  max-width: 820px;
}

/* Feature Badge */
.pm-ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fef08a;
  margin-bottom: 14px;
  backdrop-filter: blur(4px);
}

.pm-ai-badge svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Headings */
.pm-ai-title {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.25;
  color: #ffffff;
  margin: 0 0 8px 0;
  font-family: inherit;
}

.pm-ai-subtitle {
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 22px;
}

/* Search Form */
.pm-ai-form {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 18px;
  max-width: 650px;
}

.pm-ai-input-wrap {
  position: relative;
  flex: 1;
}

.pm-ai-input {
  width: 100%;
  height: 52px;
  padding: 0 20px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 500;
  outline: none;
  transition: all 0.25s ease;
}

.pm-ai-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.pm-ai-input:focus {
  background: rgba(0, 0, 0, 0.35);
  border-color: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22);
}

.pm-ai-submit-btn {
  height: 52px;
  padding: 0 26px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #1a1a1a;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.pm-ai-submit-btn:hover {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.45);
  color: #111827;
}

.pm-ai-submit-btn:active {
  transform: translateY(1px);
}

.pm-ai-submit-btn svg {
  width: 16px;
  height: 16px;
}

/* Quick Pick Chips */
.pm-ai-quick-picks {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.pm-ai-quick-label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  margin-right: 4px;
}

.pm-ai-chip {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  line-height: 1.2;
}

.pm-ai-chip:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.45);
  transform: translateY(-1px);
}

/* --- Modal Overlay & Dialog --- */
.pm-ai-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10500;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.pm-ai-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.pm-ai-modal {
  position: relative;
  background: #ffffff;
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  transform: scale(0.95) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pm-ai-modal-overlay.active .pm-ai-modal {
  transform: scale(1) translateY(0);
}

/* Modal Header */
.pm-ai-modal-header {
  padding: 24px 28px 18px 28px;
  border-bottom: 1px solid #f1f5f9;
  position: relative;
}

.pm-modal-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #15803d;
  margin-bottom: 4px;
}

.pm-modal-title {
  font-size: 26px;
  font-weight: 800;
  color: #14532d;
  margin: 0;
  line-height: 1.25;
}

.pm-ai-modal-close {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.pm-ai-modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
  transform: rotate(90deg);
}

/* Modal Meta Strip */
.pm-modal-meta-strip {
  background: #eef7ee;
  border: 1px solid #d8ebd8;
  border-radius: 12px;
  padding: 10px 18px;
  margin: 14px 28px 6px 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px 24px;
  font-size: 13px;
  font-weight: 600;
  color: #166534;
}

.pm-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pm-meta-item.matched-badge {
  color: #15803d;
  background: #dcfce7;
  padding: 3px 10px;
  border-radius: 6px;
}

.pm-modal-instructions {
  padding: 8px 28px 12px 28px;
  font-size: 13px;
  color: #64748b;
}

/* Modal Body / Table Scroll */
.pm-ai-modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 28px;
  max-height: 480px;
  position: relative;
}

.pm-recipe-table {
  width: 100% !important;
  border-collapse: collapse !important;
  border-spacing: 0 !important;
  table-layout: fixed !important;
  border: none !important;
  margin: 0 !important;
  min-width: 620px;
}

.pm-recipe-table thead {
  position: static !important;
}

.pm-recipe-table thead tr {
  border: none !important;
}

.pm-recipe-table thead th {
  display: table-cell !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 10 !important;
  background-color: #f8fafc !important;
  padding: 12px 10px !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  color: #64748b !important;
  border: none !important;
  border-bottom: 2px solid #e2e8f0 !important;
  vertical-align: middle !important;
  height: 44px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
}

.pm-recipe-table tbody tr {
  border: none !important;
  transition: background 0.15s ease;
}

.pm-recipe-table tbody tr:hover {
  background-color: #f8fafc !important;
}

.pm-recipe-table tbody td {
  display: table-cell !important;
  padding: 12px 10px !important;
  border: none !important;
  border-bottom: 1px solid #f1f5f9 !important;
  vertical-align: middle !important;
  font-size: 14px !important;
  box-sizing: border-box !important;
  background: transparent !important;
}

/* Explicit Column Width Distribution & Alignment (6 distinct columns = 100%) */
.pm-recipe-table th.pm-ai-col-ingredient,
.pm-recipe-table td.pm-ai-col-ingredient {
  width: 25% !important;
  text-align: left !important;
}

.pm-recipe-table td.pm-ai-col-ingredient {
  font-weight: 700 !important;
  color: #0f172a !important;
  word-break: normal !important;
  overflow-wrap: break-word !important;
}

.pm-recipe-table th.pm-ai-col-qty,
.pm-recipe-table td.pm-ai-col-qty {
  width: 13% !important;
  text-align: center !important;
}

.pm-qty-badge {
  display: inline-block;
  background: #f1f5f9;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  line-height: 1.2;
  white-space: nowrap;
}

.pm-mobile-qty {
  display: none !important;
}

.pm-desktop-only {
  display: table-cell !important;
}

.pm-recipe-table th.pm-ai-col-match,
.pm-recipe-table td.pm-ai-col-match {
  width: 36% !important;
  text-align: left !important;
}

.pm-recipe-table th.pm-ai-col-status,
.pm-recipe-table td.pm-ai-col-status {
  width: 11% !important;
  text-align: center !important;
}

/* Price column: strictly right-aligned in header and body */
.pm-recipe-table th.pm-ai-col-price,
.pm-recipe-table td.pm-ai-col-price {
  width: 11% !important;
  text-align: right !important;
}

.pm-recipe-table th.pm-ai-col-price {
  color: #64748b !important;
  font-size: 11px !important;
  font-weight: 700 !important;
}

.pm-price-val {
  font-weight: 700 !important;
  font-size: 18px !important;
  color: var(--price-color, #fb3737) !important;
  white-space: nowrap !important;
}

.pm-recipe-table td.pm-ai-col-price.dimmed .pm-price-val {
  color: #94a3b8 !important;
  font-weight: 500 !important;
}

/* Dedicated Action column (✕ button) */
.pm-recipe-table th.pm-ai-col-action,
.pm-recipe-table td.pm-ai-col-action {
  width: 4% !important;
  text-align: center !important;
  vertical-align: middle !important;
}

/* Best Match column */
.pm-matched-product {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pm-product-thumb-link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  border-radius: 8px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.pm-product-thumb-link:hover {
  transform: scale(1.06);
  opacity: 0.9;
}

.pm-product-thumb {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 2px;
  flex-shrink: 0;
}

.pm-product-info {
  display: flex;
  flex-direction: column;
}

.pm-product-name-link {
  text-decoration: none;
  color: inherit;
  display: inline-block;
  transition: color 0.15s ease;
}

.pm-product-name-link:hover .pm-product-name {
  color: #15803d;
  text-decoration: underline;
}

.pm-product-name {
  font-weight: 600;
  color: #1e293b;
  line-height: 1.3;
  font-size: 13px;
  transition: color 0.15s ease;
}

.pm-product-brand {
  font-size: 12px;
  color: #64748b;
}

/* Status Column */
.pm-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.pm-status-pill.matched {
  background: #dcfce7;
  color: #15803d;
}

.pm-status-pill.unavailable {
  background: #f1f5f9;
  color: #94a3b8;
  text-decoration: line-through;
}

/* Remove Row Action */
.pm-remove-row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  margin: 0 auto;
  transition: all 0.2s ease;
}

.pm-remove-row-btn:hover {
  color: #ef4444;
  background: #fee2e2;
  border-color: #fca5a5;
  transform: scale(1.08);
}

/* Removed row animation */
.pm-recipe-row.removed {
  opacity: 0.35;
  background: #f8fafc;
  text-decoration: line-through;
  pointer-events: none;
}

/* Modal Sticky Footer */
.pm-ai-modal-footer {
  padding: 18px 28px;
  border-top: 1px solid #f1f5f9;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.pm-footer-total {
  display: flex;
  flex-direction: column;
}

.pm-total-label {
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pm-total-amount {
  font-size: 26px;
  font-weight: 800;
  color: var(--price-color, #fb3737);
  line-height: 1.15;
}

.pm-add-all-btn {
  height: 50px;
  padding: 0 32px;
  background: #165d29;
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all 0.25s ease;
  box-shadow: 0 4px 16px rgba(22, 93, 41, 0.3);
}

.pm-add-all-btn:hover:not(:disabled) {
  background: #124a20;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(22, 93, 41, 0.4);
}

.pm-add-all-btn:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.pm-add-all-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --- Skeleton Loading State --- */
.pm-ai-loading-container {
  padding: 30px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pm-skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: pmShimmer 1.5s infinite;
  border-radius: 8px;
}

.pm-skeleton-text {
  height: 16px;
  width: 70%;
}

.pm-skeleton-title {
  height: 28px;
  width: 45%;
}

.pm-skeleton-strip {
  height: 40px;
  width: 100%;
  border-radius: 10px;
}

.pm-skeleton-row {
  height: 52px;
  width: 100%;
}

@keyframes pmShimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.pm-loading-message {
  text-align: center;
  padding: 10px 0;
  font-size: 14px;
  color: #166534;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pm-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #bbf7d0;
  border-top-color: #15803d;
  border-radius: 50%;
  animation: pmSpin 0.8s linear infinite;
}

@keyframes pmSpin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Responsive Adjustments --- */

/* Tablet Optimization (768px - 1024px Table View) */
@media (min-width: 768px) and (max-width: 1024px) {
  .pm-ai-modal {
    width: 95% !important;
    max-width: 95% !important;
  }

  .pm-ai-modal-body {
    padding: 0 16px !important;
  }

  .pm-recipe-table {
    min-width: 600px !important;
  }

  .pm-product-thumb {
    width: 40px !important;
    height: 40px !important;
  }

  .pm-product-name {
    font-size: 13px !important;
  }

  .pm-recipe-table td.pm-ai-col-ingredient {
    font-size: 13px !important;
  }
}

/* Mobile Card View (< 768px) */
@media (max-width: 767px) {
  .pm-ai-recipe-wrapper {
    margin: 20px 0;
  }

  .pm-ai-recipe-card {
    padding: 24px 18px;
    border-radius: 16px;
  }

  .pm-ai-title {
    font-size: 22px;
  }

  .pm-ai-subtitle {
    font-size: 14px;
    margin-bottom: 16px;
  }

  .pm-ai-form {
    flex-direction: column;
    gap: 10px;
  }

  .pm-ai-input {
    height: 48px;
    font-size: 14px;
  }

  .pm-ai-submit-btn {
    width: 100%;
    height: 48px;
    justify-content: center;
  }

  .pm-ai-modal-overlay {
    padding: 10px;
  }

  .pm-ai-modal {
    max-width: 100%;
    max-height: 94vh;
    border-radius: 16px;
  }

  .pm-ai-modal-header {
    padding: 18px 16px 12px 16px;
  }

  .pm-modal-title {
    font-size: clamp(18px, 4vw, 22px);
    padding-right: 32px;
  }

  .pm-ai-modal-close {
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .pm-modal-meta-strip {
    margin: 10px 16px 4px 16px;
    padding: 8px 12px;
    gap: 8px 12px;
    font-size: 12px;
  }

  .pm-modal-instructions {
    padding: 6px 16px 10px 16px;
    font-size: 12px;
  }

  .pm-ai-modal-body {
    padding: 0 16px;
    max-height: 52vh;
  }

  /* Responsive Mobile Card View for Recipe Table */
  .pm-recipe-table {
    display: block !important;
    width: 100% !important;
    min-width: 100% !important;
  }

  .pm-recipe-table thead {
    display: none !important;
  }

  .pm-recipe-table tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .pm-recipe-table tbody tr.pm-recipe-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-areas:
      "ingredient ingredient"
      "match match"
      "status price" !important;
    row-gap: 8px !important;
    column-gap: 8px !important;
    align-items: center !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 14px !important;
    padding: 14px !important;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04) !important;
    box-sizing: border-box !important;
    width: 100% !important;
    position: relative !important;
  }

  .pm-recipe-table tbody tr.pm-recipe-row > td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
    width: 100% !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }

  /* Completely hide desktop Qty cell on mobile */
  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-qty {
    display: none !important;
  }

  /* Top line: Ingredient name + mobile qty badge */
  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-ingredient {
    grid-area: ingredient !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    padding-right: 36px !important; /* Space for the top-right delete button */
    word-break: normal !important;
    overflow-wrap: normal !important;
  }

  .pm-recipe-table td.pm-ai-col-ingredient .pm-ing-title {
    display: inline !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    white-space: normal !important;
  }

  .pm-mobile-qty {
    display: inline-block !important;
    font-size: 11px !important;
    padding: 2px 8px !important;
    border-radius: 12px !important;
    background: #f1f5f9 !important;
    color: #475569 !important;
    white-space: nowrap !important;
  }

  /* Middle line: Product match */
  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-match {
    grid-area: match !important;
    padding: 8px 0 !important;
    border-top: 1px dashed #f1f5f9 !important;
    border-bottom: 1px dashed #f1f5f9 !important;
  }

  /* Bottom line: Status badge on left, Price on right */
  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-status {
    grid-area: status !important;
    display: block !important;
    text-align: left !important;
    width: auto !important;
  }

  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-price {
    grid-area: price !important;
    display: block !important;
    text-align: right !important;
    width: auto !important;
  }

  .pm-price-val {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--price-color, #fb3737) !important;
  }

  /* Top-right delete button in card */
  .pm-recipe-table tbody tr.pm-recipe-row > td.pm-ai-col-action {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .pm-remove-row-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 18px !important;
  }

  .pm-ai-modal-footer {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .pm-footer-total {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .pm-total-amount {
    font-size: 22px;
  }

  .pm-add-all-btn {
    width: 100%;
    height: 48px;
    justify-content: center;
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  .pm-ai-modal-overlay {
    padding: 6px;
  }

  .pm-modal-meta-strip {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .pm-meta-item.matched-badge {
    align-self: flex-start;
  }
}
