/* ==================== SHARED STYLES FOR AUTH MODAL & TOAST ==================== */

/* Hidden attribute must always override any display rule */
[hidden] {
  display: none !important;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

/* Auth button user display */
.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  color: #fff;
  background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
  border: 1px solid var(--primary);
  border-radius: 12px;
  height: 42px;
  padding: 0 22px;
  box-shadow: 0 10px 22px rgba(19, 88, 255, 0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.auth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(19, 88, 255, 0.22);
  background: linear-gradient(180deg, var(--primary, #2b72ff) 0%, var(--primary-dark) 100%);
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.auth-btn svg {
  width: 18px;
  height: 18px;
  color: currentColor;
  flex-shrink: 0;
}

.auth-btn-text {
  white-space: nowrap;
}

.auth-card {
  background: var(--bg-white);
  border-radius: 16px;
  padding: 32px;
  width: min(420px, 90vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  position: relative;
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  font-size: 22px;
  color: var(--auth-muted);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-close:hover { background: var(--bg-page); color: var(--text-dark); }

.auth-card h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 0 0 20px;
  letter-spacing: -0.045em;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-page);
  border-radius: 10px;
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--auth-muted);
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
}

.auth-tab.active {
  background: var(--bg-white);
  color: var(--text-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.auth-field {
  display: block;
  margin-bottom: 14px;
  font-family: inherit;
}

.auth-field label,
.auth-field {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
}

.auth-field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.18s ease;
}

.auth-field input:focus { border-color: var(--primary); }

.auth-submit {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
  box-shadow: 0 10px 22px rgba(19, 88, 255, 0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.auth-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(19, 88, 255, 0.22);
}

.auth-message {
  margin-top: 12px;
  font-size: 13px;
  color: var(--danger, #ef4444);
  min-height: 20px;
  text-align: center;
}

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(90vw, 480px);
  padding: 12px 20px 12px 14px;
  background: linear-gradient(180deg, var(--bg-white, #ffffff) 0%, var(--bg-page, #fbfcff) 100%);
  border: 1px solid var(--premium-border);
  border-left: 4px solid var(--premium-green);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--text-dark);
  text-align: left;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.05);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  /* Above every popup (auth modal 10000, plan modal 1250, camera modal 10000)
     so toasts are never hidden by an open dialog. */
  z-index: 120000;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Stacked toasts (shared toast() in app.js). The container is fixed at the
   bottom center; each toast inside drops its own fixed positioning. */
.toast-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* Above every popup (auth modal 10000, plan modal 1250, camera modal 10000). */
  z-index: 120000;
  pointer-events: none;
}
.toast-stack .toast {
  position: relative;
  transform: translateY(10px);
  pointer-events: auto;
}
.toast-stack .toast.show {
  transform: translateY(0);
}
.toast-icon {
  display: inline-flex;
  flex-shrink: 0;
  line-height: 0;
}
.toast-msg {
  flex: 1;
  min-width: 0;
}
.toast.toast-error {
  border-left-color: #ef765f;
}
.toast.toast-warning {
  border-left-color: #f0a020;
}
.toast.toast-info {
  border-left-color: var(--primary);
}

/* ==================== TOAST (small devices) ==================== */
/* On phones the toast spans the width with small side margins so it stays
   readable and never overflows the viewport. */
@media (max-width: 640px) {
  .toast {
    bottom: 12px;
    left: 12px;
    right: 12px;
    transform: translateY(20px);
    max-width: none;
    width: auto;
    padding: 12px 16px;
    font-size: 13px;
    border-radius: 12px;
  }
  .toast.show {
    transform: translateY(0);
  }
  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: none;
    align-items: stretch;
  }
  .toast-stack .toast {
    position: relative;
    left: auto;
    right: auto;
    transform: translateY(10px);
    width: auto;
    max-width: none;
  }
  .toast-stack .toast.show {
    transform: translateY(0);
  }
}

/* ==================== SPINNER ==================== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== LOADING HEADER ==================== */
.loading-header {
  grid-column: 1/-1;
  text-align: center;
  padding: 20px 0 12px;
}

.loading-spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

.loading-text {
  color: var(--text-dark, #000000);
  font-size: 18px;
  font-weight: 700;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  vertical-align: middle;
}

/* Brand link styling */
.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(19, 88, 255, 0.06);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}

.brand-link:hover {
  background: rgba(19, 88, 255, 0.12);
  color: var(--primary-dark, #0d47cc);
}

.brand-link svg {
  opacity: 0.7;
  flex-shrink: 0;
}

#brand-detecting {
  font-style: italic;
  opacity: 0.7;
}

/* ==================== AUTH MODAL OVERLAY ==================== */
[hidden] { display: none !important; }

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.auth-modal.open { display: flex; }

.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.auth-modal-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.auth-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border: 0;
  background: var(--overlay, rgba(255,255,255,0.85));
  font-size: 22px;
  color: var(--auth-muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.auth-close:hover { background: var(--bg-white); color: var(--text-dark); }

body.auth-modal-open { overflow: hidden; }

/* Auth card container for modal - centers the card */
.auth-modal .auth-card-container {
  width: 100%;
  max-width: 420px;
  position: relative;
}

/* ==================== INFO TOOLTIPS ==================== */
/* Add class="tip" plus data-tip="message" to any element to show a hover
   tooltip. Matches the tooltip styling used elsewhere in the app. */
.tip {
  position: relative;
  cursor: help;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(2px);
  z-index: 30;
  width: max-content;
  max-width: 250px;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--text-dark);
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  box-shadow: 0 10px 26px rgba(11, 20, 48, 0.22);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  border: 5px solid transparent;
  border-top-color: var(--text-dark);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease, visibility 0.16s ease;
}

.tip:hover::after,
.tip:focus-visible::after,
.tip:hover::before,
.tip:focus-visible::before {
  opacity: 1;
  visibility: visible;
}

.tip:hover::after,
.tip:focus-visible::after {
  transform: translateX(-50%) translateY(0);
}

/* ==================== PRICE DISTRIBUTION CHARTS ==================== */
/* Shared controls + SVG charts for the product and brand pages. */
.distribution-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.chart-type-wrap,
.brand-marketplace-filter {
  flex-shrink: 0;
}
.chart-type-select {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  background: var(--bg-white);
  border: 1px solid var(--auth-border);
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
  max-width: 220px;
}
.chart-type-select:focus-visible {
  outline: 3px solid rgba(19, 88, 255, 0.18);
  outline-offset: 1px;
}
.price-chart {
  display: block;
}
.price-chart .price-chart-svg,
.price-chart svg {
  width: 100%;
  height: auto;
  display: block;
}
.mini-histogram.price-chart {
  display: block;
  height: auto;
}

/* Saved/bookmarked product indicator — shared across pages.
   Applied to the card bookmark button (.icon-circle) and the product
   page save button (.icon-btn) once the product is saved to a collection. */
.icon-circle.bookmarked,
.icon-btn.bookmarked {
  color: var(--primary, #1358ff);
}
.icon-circle.bookmarked svg path,
.icon-btn.bookmarked svg path {
  fill: currentColor;
}
/* ==================== COLLAPSIBLE CARD FILTERS (funnel toggle) ==================== */
/* Product/brand price cards hide their filter controls behind a funnel icon in
   the card title row; clicking it reveals the controls panel. */
.card-filters-toggle {
  appearance: none; -webkit-appearance: none; border: 1.5px solid var(--border, #e2e8f2); border-radius: 10px;
  background: var(--bg-white); width: 34px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-light, #66758d); cursor: pointer; flex-shrink: 0; margin-left: auto;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.card-filters-toggle:hover { border-color: var(--primary, #1358ff); color: var(--primary, #1358ff); }
.card-filters-toggle.is-open { border-color: var(--primary, #1358ff); color: var(--primary, #1358ff); background: var(--primary-bg, #edf3ff); }
.card-filters-panel { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
.card-filters-panel[hidden] { display: none; }
