/**
 * MakerFaire Wishlist — BEM + CSS custom properties.
 * All selectors are prefixed with .mfw- to avoid collisions.
 */

:where(:root) {
  --mfw-accent: #2563eb;
  --mfw-accent-ink: #fff;
  --mfw-danger: #dc2626;
  --mfw-success: #16a34a;
  --mfw-muted: #6b7280;
  --mfw-bg: #ffffff;
  --mfw-bg-alt: #f5f6f8;
  --mfw-ink: #0f172a;
  --mfw-border: #e5e7eb;
  --mfw-shadow: 0 10px 40px -10px rgba(0, 0, 0, .25);
  --mfw-radius: 10px;
  --mfw-radius-sm: 6px;
  --mfw-gap: 12px;
  --mfw-z-overlay: 10000;
  --mfw-z-modal:   10010;
  --mfw-z-toast:   10020;
  --mfw-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :where(:root) {
    --mfw-bg: #111214;
    --mfw-bg-alt: #1a1c20;
    --mfw-ink: #eaeaea;
    --mfw-border: #2b2e33;
    --mfw-muted: #9aa0a6;
    --mfw-shadow: 0 10px 40px -10px rgba(0, 0, 0, .6);
  }
}

html.mfw-scroll-lock { overflow: hidden; overscroll-behavior: contain; }

/* ========== Add-to-list button ========== */
[data-mf-wishlist] {
  font: inherit;
  cursor: pointer;
}
[data-mf-wishlist] .mfw-btn__added,
[data-mf-wishlist] .mfw-btn__visited { display: none; }
[data-mf-wishlist].is-added .mfw-btn__add { display: none; }
[data-mf-wishlist].is-added .mfw-btn__added { display: inline; }
[data-mf-wishlist].is-visited .mfw-btn__added { display: none; }
[data-mf-wishlist].is-visited .mfw-btn__visited { display: inline; }
.mfw-btn { /* default styles only if developer uses .mfw-btn class */
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--mfw-accent);
  border-radius: 999px;
  background: transparent;
  color: var(--mfw-accent);
  cursor: pointer;
  transition: background .15s;
}
.mfw-btn:hover { background: color-mix(in srgb, var(--mfw-accent) 10%, transparent); }
.mfw-btn.is-added { background: var(--mfw-accent); color: var(--mfw-accent-ink); }
.mfw-btn.is-visited { background: var(--mfw-success); border-color: var(--mfw-success); color: var(--mfw-accent-ink); }

.mfw-toggle {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--mfw-bg-alt);
  border: 1px solid var(--mfw-border);
  border-radius: 999px;
  color: var(--mfw-ink);
  cursor: pointer;
}
.mfw-toggle__count {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--mfw-accent);
  color: var(--mfw-accent-ink);
  font-size: .75rem;
  font-weight: 700;
  text-align: center;
}
.mfw-toggle__count.mfw-count--empty {
  background: var(--mfw-muted);
  opacity: .6;
}

/* ========== Overlay ========== */
.mfw-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--mfw-z-overlay);
  font-family: var(--mfw-font);
  color: var(--mfw-ink);
  pointer-events: none;
}
.mfw-overlay--open { pointer-events: auto; }
.mfw-overlay[hidden] { display: none; }

.mfw-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  transition: opacity .2s;
}
.mfw-overlay--open .mfw-overlay__backdrop { opacity: 1; }

.mfw-overlay__panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(420px, 95vw);
  background: var(--mfw-bg);
  box-shadow: var(--mfw-shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.mfw-overlay--open .mfw-overlay__panel { transform: translateX(0); }

/* Mobile: full-height fullscreen sheet */
@media (max-width: 720px) {
  .mfw-overlay__panel {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mfw-overlay--open .mfw-overlay__panel { transform: translateY(0); }
  /* Backdrop not visible on full-height sheet — panel covers it. */
  .mfw-overlay__backdrop { display: none; }
}

.mfw-overlay__header {
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--mfw-border);
}
.mfw-overlay__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 10px;
}
.mfw-overlay__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.mfw-overlay__close {
  appearance: none;
  background: transparent;
  border: 0;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--mfw-muted);
  cursor: pointer;
  padding: 0 8px;
}
.mfw-overlay__close:hover { color: var(--mfw-ink); }

.mfw-overlay__tabs {
  display: flex;
  gap: 2px;
  margin-bottom: -1px;
  overflow-x: auto;
  scrollbar-width: none;
}
.mfw-overlay__tabs::-webkit-scrollbar { display: none; }
.mfw-tab {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 10px 8px;
  font: inherit;
  font-size: .9rem;
  color: var(--mfw-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.mfw-tab__count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--mfw-bg-alt);
  font-size: .75rem;
  font-weight: 600;
  text-align: center;
}
.mfw-tab--active {
  color: var(--mfw-ink);
  border-bottom-color: var(--mfw-accent);
  font-weight: 600;
}
.mfw-tab--active .mfw-tab__count { background: var(--mfw-accent); color: var(--mfw-accent-ink); }

.mfw-overlay__body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
}
.mfw-overlay__empty {
  color: var(--mfw-muted);
  text-align: center;
  padding: 40px 16px;
  font-size: .95rem;
}

.mfw-overlay__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--mfw-border);
  background: var(--mfw-bg-alt);
}
.mfw-overlay__footer > button[data-role="pair-button"] { width: 100%; }
.mfw-overlay__footer--paired > button[data-role="pair-button"] { display: none; }
.mfw-overlay__resend-link[hidden] { display: none; }
.mfw-overlay__pair-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  font-size: .82rem;
  line-height: 1.4;
  text-align: center;
}
.mfw-overlay__pair-status { color: var(--mfw-muted); }
.mfw-overlay__footer--paired .mfw-overlay__pair-status { color: var(--mfw-success); font-weight: 500; }
.mfw-overlay__footer--paired .mfw-overlay__pair-row { margin: 0; }
.mfw-overlay__resend-link {
  color: var(--mfw-accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: .82rem;
}
/* Unpaired: hint text above big button */
.mfw-overlay__footer:not(.mfw-overlay__footer--paired) .mfw-overlay__pair-row { margin-bottom: 8px; }
/* Paired: no button, just the compact status row */
.mfw-overlay__footer--paired { padding: 10px 16px; }

/* Sync error indicator — hidden by default, shown when sync-fail event fires */
.mfw-overlay__sync-error {
  margin: 0 0 8px;
  font-size: .78rem;
  color: var(--mfw-danger);
  text-align: center;
  display: none;
}
.mfw-overlay__footer--sync-error .mfw-overlay__sync-error { display: block; }

/* Defensive reset: neutralize host-theme styles (Bricks etc. sling rules at
   section/article, including vertical padding that breaks our layout). */
.mfw-overlay__body, .mfw-overlay__body * { box-sizing: border-box; }
.mfw-overlay__body .mfw-group,
.mfw-overlay__body .mfw-card {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 0;
}

/* ========== Groups ========== */
.mfw-overlay__body .mfw-group { margin-bottom: 24px; }
.mfw-overlay__body .mfw-group:last-child { margin-bottom: 0; }
.mfw-group__title {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--mfw-muted);
  margin: 0 0 8px;
  padding: 0 2px;
}

/* ========== Card ========== */
.mfw-overlay__body .mfw-card {
  background: var(--mfw-bg);
  border: 1px solid var(--mfw-border);
  border-radius: var(--mfw-radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.mfw-card--visited { opacity: .7; }
.mfw-card--visited .mfw-card__title { text-decoration: line-through; }

.mfw-card__header {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 32px 10px 12px;
  background: transparent;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.mfw-card__title {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.3;
}
.mfw-card__meta {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.mfw-card__chevron {
  position: absolute;
  top: 12px;
  right: 10px;
  color: var(--mfw-muted);
  transition: transform .2s;
  line-height: 1;
}
.mfw-card--expanded .mfw-card__chevron { transform: rotate(180deg); }

.mfw-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--mfw-bg-alt);
  color: var(--mfw-muted);
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
}

.mfw-card__body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--mfw-border);
}
/* [hidden] attribute defaults to display:none but our display:flex above wins
   unless we restate it with the attribute selector. */
.mfw-card__body[hidden] { display: none; }

.mfw-card__dt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.mfw-card__dt-row .mfw-input {
  flex: 1 1 auto;
  min-width: 0;
}
.mfw-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .85rem;
  color: var(--mfw-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.mfw-checkbox-label input { margin: 0; }

.mfw-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .78rem;
  color: var(--mfw-muted);
}
.mfw-input, .mfw-textarea {
  font: inherit;
  padding: 8px 10px;
  background: var(--mfw-bg-alt);
  border: 1px solid var(--mfw-border);
  border-radius: var(--mfw-radius-sm);
  color: var(--mfw-ink);
}
.mfw-textarea { resize: vertical; min-height: 60px; }
.mfw-input:focus, .mfw-textarea:focus {
  outline: 2px solid var(--mfw-accent);
  outline-offset: 1px;
}

.mfw-card__contact-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mfw-card__contact-name {
  font-weight: 600;
  font-size: .92rem;
}
.mfw-card__contact {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mfw-contact-link {
  display: inline-block;
  padding: 4px 10px;
  background: var(--mfw-bg-alt);
  border: 1px solid var(--mfw-border);
  border-radius: 999px;
  font-size: .82rem;
  text-decoration: none;
  color: var(--mfw-ink);
}

.mfw-card__message {
  margin: 0;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--mfw-accent) 10%, transparent);
  border-left: 3px solid var(--mfw-accent);
  border-radius: 4px;
  font-size: .88rem;
  font-style: italic;
}


.mfw-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.mfw-card__status {
  font-size: .8rem;
  color: var(--mfw-muted);
  min-height: 1.2em;
}
.mfw-card__status--saved { color: var(--mfw-success); }

/* ========== Buttons (shared) ========== */
.mfw-btn-primary, .mfw-btn-secondary, .mfw-btn-text {
  font: inherit;
  padding: 9px 14px;
  border-radius: var(--mfw-radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: filter .15s, background .15s;
}
.mfw-btn-primary {
  background: var(--mfw-accent);
  color: var(--mfw-accent-ink);
  border: 0;
  font-weight: 600;
}
.mfw-btn-primary:hover { filter: brightness(1.05); }
.mfw-btn-secondary {
  background: var(--mfw-bg-alt);
  color: var(--mfw-ink);
  border: 1px solid var(--mfw-border);
}
.mfw-btn-secondary:hover { background: var(--mfw-border); }
.mfw-btn-text {
  background: transparent;
  border: 0;
  color: var(--mfw-muted);
}
.mfw-btn-danger { background: var(--mfw-danger); color: var(--mfw-accent-ink); }
.mfw-btn-text.mfw-btn-danger { background: transparent; color: var(--mfw-danger); }
.mfw-btn-sm { padding: 6px 10px; font-size: .88rem; }

/* ========== Modal ========== */
.mfw-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--mfw-z-modal);
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 16px;
}
.mfw-modal {
  background: var(--mfw-bg);
  border-radius: var(--mfw-radius);
  padding: 20px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--mfw-shadow);
}
.mfw-modal__title {
  margin: 0 0 10px;
  font-size: 1.1rem;
  font-weight: 700;
}
.mfw-modal__body {
  margin: 0 0 16px;
  color: var(--mfw-muted);
  font-size: .95rem;
  line-height: 1.45;
}
.mfw-modal__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mfw-modal__error {
  color: var(--mfw-danger);
  font-size: .85rem;
}
.mfw-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ========== Toast ========== */
.mfw-toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: var(--mfw-z-toast);
  pointer-events: none;
}
.mfw-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--mfw-ink);
  color: var(--mfw-bg);
  border-radius: 999px;
  font-size: .9rem;
  box-shadow: var(--mfw-shadow);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .2s, transform .2s;
}
.mfw-toast--shown {
  opacity: 1;
  transform: translateY(0);
}
.mfw-toast__action {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--mfw-accent-ink);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
