/* Container: responsive grid with safe fallback */
.milk-subscription-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  background: #fff;
  border: 2px solid #80bb01;
  border-radius: 10px;
  padding: 20px;
  max-width: 760px;
  margin: 0 auto 30px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.04);
  align-items: start;
  box-sizing: border-box;
}

/* Target WooCommerce form rows inside the wrapper */
.milk-subscription-fields .form-row {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Labels: consistent, compact */
.milk-subscription-fields label {
  font-weight: 600;
  color: #333;
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

/* Inputs and selects: unified appearance */
.milk-subscription-fields select,
.milk-subscription-fields input[type="text"],
.milk-subscription-fields input[type="date"],
.milk-subscription-fields input[type="number"],
.milk-subscription-fields input,
.milk-subscription-fields textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d6d6d6;
  border-radius: 6px;
  background: #fff;
  transition: border-color .18s ease, box-shadow .18s ease;
  box-sizing: border-box;
  font-size: 14px;
}

/* Focus state */
.milk-subscription-fields select:focus,
.milk-subscription-fields input:focus,
.milk-subscription-fields textarea:focus {
  border-color: #80bb01;
  box-shadow: 0 0 6px rgba(128,187,1,0.12);
  outline: none;
}

/* Make the Add to cart button visually part of the box */
.milk-subscription-fields .single_add_to_cart_button,
.milk-subscription-fields .button.single_add_to_cart_button {
  grid-column: 1 / -1; /* span full width */
  display: inline-block;
  width: 100%;
  background-color: #80bb01 !important;
  border-color: #80bb01 !important;
  color: #fff !important;
  font-weight: 700;
  border-radius: 6px;
  padding: 12px 16px;
  text-align: center;
  margin-top: 6px;
  box-shadow: none;
}

/* Slight hover */
.milk-subscription-fields .single_add_to_cart_button:hover {
  background-color: #6aa300 !important;
}

/* Reduce visual noise for small helper text / errors */
.milk-subscription-fields .description,
.milk-subscription-fields .help {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
}

/* Make sure WooCommerce inline labels (if any) don't break layout */
.milk-subscription-fields .form-row .woocommerce-input-wrapper {
  width: 100%;
}

/* Mobile: single column, comfortable padding */
@media (max-width: 640px) {
  .milk-subscription-fields {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 12px;
    max-width: 92%;
  }
  .milk-subscription-fields label { font-size: 15px; }
  .milk-subscription-fields select,
  .milk-subscription-fields input { font-size: 15px; padding: 12px; }
}

/* Subscription list grid */
.sa-subs-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

/* Each subscription card */
.sa-sub {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* Subscription title */
.sa-sub h3 {
  font-size: 18px;
  margin-bottom: 10px;
  color: #333;
}

/* Status label */
.sa-sub-status {
  font-weight: 600;
  color: #80bb01; /* ShopApni brand green */
  margin-left: 6px;
}

/* Details paragraph */
.sa-sub p {
  font-size: 14px;
  color: #555;
  margin-bottom: 15px;
}

/* Action buttons */
.sa-sub-actions .sa-btn {
  margin-right: 10px;
  padding: 8px 14px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

/* Button color coding */
.sa-sub-actions .sa-open-pause-modal { background: #f0ad4e; color: #fff; }
.sa-sub-actions .sa-resume { background: #80bb01; color: #fff; }
.sa-sub-actions .sa-cancel { background: #d9534f; color: #fff; }
.sa-sub-actions .sa-toggle-deliveries { background: #6aa300; color: #fff; }

/* Deliveries container: mobile friendly scroll + stable layout */
/* Deliveries container: mobile friendly scroll + stable layout */
.sa-deliveries {
  box-sizing: border-box;
  max-height: 300px;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  margin-top: 12px;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 8px;
  background: #fafafa;
  position: relative;
  z-index: 2;
}

/* Make table responsive: allow horizontal scroll inside the deliveries box */
.sa-deliveries .sa-deliveries-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Table base */
.sa-deliveries-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  min-width: 640px; /* desktop readable width; mobile will scroll */
  table-layout: auto;
}

/* Cells and headers: allow wrapping for headers on small screens */
.sa-deliveries-table th,
.sa-deliveries-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f1f1;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
  white-space: normal;
  word-break: break-word;
}

/* Make header visually distinct and ensure it is fully visible */
.sa-deliveries-table thead th {
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}

/* Mobile specific adjustments */
@media (max-width: 640px) {
  .sa-deliveries {
    max-height: 220px;
    padding: 6px;
  }

  /* Wrap table in a scrollable wrapper on mobile */
  .sa-deliveries .sa-deliveries-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Reduce min-width so table can fit better; still allow horizontal scroll */
  .sa-deliveries-table {
    min-width: 560px;
  }

  .sa-deliveries-table th,
  .sa-deliveries-table td {
    font-size: 13px;
    padding: 8px;
  }
}

/* Safety: ensure ancestors don't clip child scrolling */
.sa-sub,
.sa-milk-account,
.sa-subs-list {
  overflow: visible !important;
  -webkit-overflow-scrolling: auto;
}

/* Modal root should cover viewport */
.sa-modal-root {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 99990;
}

/* When open */
.sa-modal-root[aria-hidden="false"] { display: block; }

/* Backdrop */
.sa-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99990;
  pointer-events: auto;
  backdrop-filter: blur(3px);
}

/* ====== sa-milk modal: full stylesheet (paste as-is) ====== */

/* Safety: ensure modal root is direct child of body */
body > .sa-modal-root { position: fixed; top:0; left:0; right:0; bottom:0; z-index:99990; }

/* Backdrop covers the page */
.sa-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99990;
  pointer-events: auto;
}

/* Modal card must be above backdrop and accept pointer events */
.sa-modal-card,
.sa-modal-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 99991;
  pointer-events: auto;
  width: 420px;
  max-width: 94%;
  background: linear-gradient(180deg,#ffffff 0%, #fbfff5 100%);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.28);
  box-sizing: border-box;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

/* Close button and controls remain interactive */
.sa-modal-close,
.sa-modal-card button,
.sa-modal-card input,
.sa-modal-panel button,
.sa-modal-panel input,
.sa-modal-card select,
.sa-modal-panel select,
.sa-modal-card textarea,
.sa-modal-panel textarea {
  pointer-events: auto;
}

/* If you blur the page when modal opens, keep modal interactive */
body.modal-open { overflow: hidden; }

/* Close button */
.sa-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 18px;
  color: #666;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
}
.sa-modal-close:hover { background: rgba(0,0,0,0.04); }

/* Hero */
.sa-modal-hero {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.sa-modal-icon { flex: 0 0 36px; width:36px; height:36px; }
.sa-modal-hero h3 { margin: 0; font-size: 18px; color: #223; }
.sa-modal-sub { margin: 4px 0 0; color: #4b4b4b; font-size: 14px; }

/* Body fields */
.sa-modal-body { margin-top: 8px; display: grid; gap: 10px; }
.sa-field { display: flex; flex-direction: column; gap: 6px; }
.sa-field-label { font-weight: 600; color: #333; font-size: 13px; }
.sa-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  background: #fff;
  font-size: 14px;
  box-sizing: border-box;
}
.sa-field-inline { display:flex; gap:8px; align-items:center; font-size:14px; color:#333; }

/* Actions */
.sa-modal-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:12px; }
.sa-btn { padding: 9px 14px; border-radius: 8px; font-weight:700; cursor:pointer; border: none; }
.sa-btn-primary { background: #80bb01; color: #fff; }
.sa-btn-primary:hover { background: #6aa300; }
.sa-btn-ghost { background: transparent; border: 1px solid #ddd; color: #333; }

/* Accessibility focus */
.sa-btn:focus, .sa-input:focus, .sa-modal-close:focus { outline: 3px solid rgba(128,187,1,0.18); outline-offset: 2px; }

/* Mobile tweaks */
@media (max-width: 480px) {
  .sa-modal-card, .sa-modal-panel { padding: 14px; width: 92%; }
  .sa-modal-hero h3 { font-size: 16px; }
  .sa-modal-sub { font-size: 13px; }
  .sa-btn { padding: 9px 12px; font-size: 14px; }
}

/* Small helper: spinner inside action column */
.row-spinner { margin-left:8px; font-size:16px; opacity:0.85; }

/* Lock info small badge */
.lock-info { display:block; margin-top:6px; font-size:12px; color:#666; background:#fff9e6; padding:6px 8px; border-radius:6px; border:1px solid #f0e6c8; }
