/* ============================================================
   Craveon shared UI layer
   Toasts, confirm dialog, busy buttons, skeletons, error panels.
   Uses the host page's CSS custom properties (with fallbacks) so
   it works in both light and dark themes on every page.
   ============================================================ */

/* ---------- Busy / disabled buttons ---------- */
.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: qb-spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
  flex: 0 0 auto;
}

@keyframes qb-spin {
  to { transform: rotate(360deg); }
}

button:disabled,
button.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.is-busy {
  pointer-events: none;
  opacity: 0.85;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Reason line shown under a gated (not-yet-valid) submit button */
.btn-gate-hint {
  display: block;
  margin-top: 0.4rem;
  font-size: 12px;
  color: var(--text-muted, var(--cream-muted, #6B7280));
  text-align: center;
  min-height: 1em;
}

/* ---------- Toasts ---------- */
#qb-toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.qb-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card, #FFFFFF);
  color: var(--text-main, var(--cream, #111827));
  border: 1px solid var(--border, #E5E7EB);
  border-left: 4px solid var(--green, #22C55E);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  font-size: 14px;
  line-height: 1.4;
  animation: qb-toast-in 0.22s ease;
}

@keyframes qb-toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.qb-toast.qb-toast-out {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.qb-toast-error { border-left-color: var(--red, #EF4444); }
.qb-toast-warning { border-left-color: #F59E0B; }
.qb-toast-info { border-left-color: var(--blue, #3B82F6); }

.qb-toast-icon {
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1.3;
}

.qb-toast-error .qb-toast-icon { color: var(--red, #EF4444); }
.qb-toast-warning .qb-toast-icon { color: #F59E0B; }
.qb-toast-info .qb-toast-icon { color: var(--blue, #3B82F6); }
.qb-toast-success .qb-toast-icon { color: var(--green, #22C55E); }

.qb-toast-msg {
  flex: 1 1 auto;
  word-break: break-word;
}

.qb-toast-close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted, var(--cream-muted, #6B7280));
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  line-height: 1;
}

.qb-toast-close:hover {
  background: var(--border, #E5E7EB);
  color: var(--text-main, var(--cream, #111827));
}

/* ---------- Confirm dialog ---------- */
.qb-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: qb-fade-in 0.15s ease;
}

@keyframes qb-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.qb-confirm-card {
  background: var(--card, #FFFFFF);
  color: var(--text-main, var(--cream, #111827));
  border: 1px solid var(--border, #E5E7EB);
  border-radius: 16px;
  padding: 22px;
  width: min(92vw, 380px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.qb-confirm-title {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text-main, var(--cream, #111827));
}

.qb-confirm-body {
  font-size: 14px;
  color: var(--text-muted, var(--cream-muted, #6B7280));
  margin: 0 0 18px;
  line-height: 1.5;
}

.qb-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.qb-confirm-actions .btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border, #E5E7EB);
  background: var(--surface, var(--card, #FFFFFF));
  color: var(--text-main, var(--cream, #111827));
}

.qb-confirm-ok {
  background: var(--accent, var(--green, #16A34A)) !important;
  border-color: var(--accent, var(--green, #16A34A)) !important;
  color: #FFFFFF !important;
}

.qb-confirm-ok-danger {
  background: var(--red, #EF4444) !important;
  border-color: var(--red, #EF4444) !important;
}

/* ---------- Skeletons ---------- */
.qb-skeleton {
  position: relative;
  overflow: hidden;
  background: var(--border, #E5E7EB);
  border-radius: 12px;
}

.qb-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: qb-shimmer 1.3s infinite;
}

[data-theme="dark"] .qb-skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
}

@keyframes qb-shimmer {
  100% { transform: translateX(100%); }
}

.qb-skeleton-card {
  height: 150px;
}

.qb-skeleton-row {
  height: 64px;
  margin-bottom: 10px;
}

.qb-skeleton-line {
  height: 14px;
  margin-bottom: 8px;
}

/* ---------- Error panel with retry ---------- */
.qb-error-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 26px 18px;
  text-align: center;
  color: var(--text-muted, var(--cream-muted, #6B7280));
  font-size: 14px;
}

.qb-error-panel p {
  margin: 0;
  max-width: 320px;
  line-height: 1.5;
}

.qb-error-panel .qb-retry-btn {
  min-height: 44px;
  padding: 0 22px;
  border-radius: 12px;
  border: 1px solid var(--border, #E5E7EB);
  background: var(--surface, #FFFFFF);
  color: var(--text-main, var(--cream, #111827));
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.qb-error-panel .qb-retry-btn:hover {
  border-color: var(--accent, var(--green, #16A34A));
  color: var(--accent, var(--green, #16A34A));
}

/* ---------- Offline banner ---------- */
#qb-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10002;
  background: #B91C1C;
  color: #FFFFFF;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  display: none;
}

#qb-offline-banner.qb-show {
  display: block;
  animation: qb-toast-in 0.2s ease;
}
