/* WL Buy Buttons — Modal & Controls
   Theming via CSS variables
*/
:root {
  --wl-overlay-bg: rgba(0,0,0,.35);
  --wl-bg: #fff;
  --wl-text: #111;
  --wl-muted: #555;
  --wl-border: #ddd;
  --wl-accent: #111;
  --wl-accent-contrast: #fff;
  --wl-success: #0a7;
  --wl-radius: 12px;
  --wl-radius-sm: 8px;
  --wl-shadow: 0 10px 30px rgba(0,0,0,.2);
  --wl-font: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Overlay (backdrop) */
.wl-overlay {
  position: fixed;
  inset: 0;
  display: none;              /* JS toggles to "flex" when open */
  background: var(--wl-overlay-bg);
  z-index: 99999;
  align-items: center;
  justify-content: center;

  /* Mobile-friendly scrolling when content is tall */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Modal shell */
.wl-modal {
  background: var(--wl-bg);
  color: var(--wl-text);
  max-width: 680px;
  width: 94%;
  padding: 16px;
  border-radius: var(--wl-radius);
  box-shadow: var(--wl-shadow);
  font-family: var(--wl-font);

  /* Mobile/tall-content scrolling */
  max-height: 92vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Prevent page background from scrolling when modal is open */
html.wl-modal-open,
body.wl-modal-open {
  overflow: hidden;
  touch-action: none;
}

/* Header */
.wl-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.wl-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.wl-close {
  font-size: 20px;
  background: none;
  border: 0;
  cursor: pointer;
  line-height: 1;
}

/* Lines */
.wl-lines {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wl-line {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 10px 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--wl-border);
}
.wl-line:last-child { border-bottom: 0; }

.wl-line-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.wl-img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--wl-radius-sm);
}

.wl-titles { min-width: 0; }
.wl-product {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wl-variant,
.wl-unit {
  font-size: 12px; color: var(--wl-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.wl-line-ctrls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.wl-qtyctrl {
  display: flex; align-items: center; gap: 6px;
}
.wl-qty {
  width: 52px;
  padding: 6px;
  border: 1px solid var(--wl-border);
  border-radius: var(--wl-radius-sm);
  text-align: center;
}

.wl-linetotal {
  min-width: 110px; text-align: right;
}

.wl-remove {
  background: none;
  border: none;
  color: #888;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
}

/* Footer / actions */
.wl-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.wl-input,
.wl-select {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--wl-border);
  border-radius: var(--wl-radius-sm);
  min-width: 180px;
}

.wl-summary {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wl-msg {
  margin-top: 8px;
  color: #b00;
}

/* Buttons */
.wl-btn {
  padding: 10px 14px;
  border-radius: var(--wl-radius-sm);
  cursor: pointer;
  font-weight: 600;
  border: 1px solid transparent;
  background: #f6f6f6;
}
.wl-btn--primary {
  background: var(--wl-accent);
  color: var(--wl-accent-contrast);
  border-color: var(--wl-accent);
}
.wl-btn--outline {
  background: #fff;
  color: var(--wl-accent);
  border-color: var(--wl-accent);
}

.wl-checkout {
  display: inline-block;
  padding: 10px 14px;
  border-radius: var(--wl-radius-sm);
  background: var(--wl-success);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}

/* Buy slot group (outside modal) */
.wl-group { display: flex; align-items: center; gap: 8px; }
.wl-variant-select { min-width: 240px; }

/* NEW: Stack dropdown above buttons for dropdown mode */
.wl-group--dropdown {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.wl-select-row { width: 100%; }
.wl-group--dropdown .wl-select { width: 100%; }
.wl-btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* Focus states */
.wl-input:focus,
.wl-select:focus,
.wl-btn:focus,
.wl-checkout:focus,
.wl-close:focus {
  outline: 2px solid var(--wl-accent);
  outline-offset: 2px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --wl-bg: #1a1a1a;
    --wl-text: #f1f1f1;
    --wl-muted: #aaa;
    --wl-border: #333;
    --wl-shadow: 0 10px 30px rgba(0,0,0,.6);
  }
  .wl-btn { background: #2a2a2a; color: var(--wl-text); border-color: #444; }
  .wl-btn--outline { background: transparent; }
  .wl-input, .wl-select, .wl-qty { background: #121212; color: var(--wl-text); border-color: var(--wl-border); }
}
