/* ================================================================
   HEALTHY HUNGER — Reusable UI Components
   Loader overlay + Toast notifications
   Palette: #00462E · #158555 · #BDE80D
   ================================================================ */

:root {
  --hh-dark: #00462E;
  --hh-green: #158555;
  --hh-lime: #BDE80D;
  --hh-loader-z: 10900;
  --hh-toast-z: 10950;
  --hh-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --hh-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Global loader overlay ── */
.hh-loader-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--hh-loader-z);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 70, 46, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s var(--hh-ease), visibility 0.28s var(--hh-ease);
  pointer-events: none;
}

.hh-loader-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.hh-loader-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  width: min(22rem, 100%);
  padding: 2rem 1.75rem 1.65rem;
  border-radius: 18px;
  background: #fff;
  border: 1px solid rgba(0, 70, 46, 0.08);
  box-shadow:
    0 4px 6px rgba(0, 70, 46, 0.04),
    0 24px 56px rgba(0, 70, 46, 0.18);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.32s var(--hh-spring);
}

.hh-loader-overlay.is-visible .hh-loader-panel {
  transform: translateY(0) scale(1);
}

.hh-loader-spinner {
  position: relative;
  width: 3.25rem;
  height: 3.25rem;
}

.hh-loader-spinner::before,
.hh-loader-spinner::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.hh-loader-spinner::before {
  border: 3px solid rgba(0, 70, 46, 0.10);
}

.hh-loader-spinner::after {
  border: 3px solid transparent;
  border-top-color: var(--hh-green);
  border-right-color: var(--hh-lime);
  animation: hhLoaderSpin 0.85s linear infinite;
}

.hh-loader-spinner-core {
  position: absolute;
  inset: 0.55rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(189, 232, 13, 0.35), rgba(21, 133, 85, 0.12));
  animation: hhLoaderPulse 1.6s ease-in-out infinite;
}

@keyframes hhLoaderSpin {
  to { transform: rotate(360deg); }
}

@keyframes hhLoaderPulse {
  0%, 100% { opacity: 0.55; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1); }
}

.hh-loader-text {
  margin: 0;
  font-family: 'Inter', 'Nunito', sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--hh-dark);
  text-align: center;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

.hh-loader-subtext {
  margin: -0.35rem 0 0;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: rgba(0, 70, 46, 0.55);
  text-align: center;
}

.hh-loader-bar {
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: rgba(0, 70, 46, 0.08);
  overflow: hidden;
}

.hh-loader-bar span {
  display: block;
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hh-green), var(--hh-lime));
  animation: hhLoaderBar 1.2s var(--hh-ease) infinite;
}

@keyframes hhLoaderBar {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(320%); }
}

body.hh-loader-active {
  overflow: hidden;
}

body.hh-loader-active .hh-loader-overlay {
  pointer-events: auto;
}

/* ── Toast container positions ── */
.hh-toast-container {
  position: fixed;
  z-index: var(--hh-toast-z);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: min(24rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  overflow: hidden;
  pointer-events: none;
}

.hh-toast-container--top-right {
  top: 1rem;
  right: 1rem;
  align-items: flex-end;
}

.hh-toast-container--top-left {
  top: 1rem;
  left: 1rem;
  align-items: flex-start;
}

.hh-toast-container--bottom-right {
  bottom: 1rem;
  right: 1rem;
  align-items: flex-end;
  flex-direction: column-reverse;
}

.hh-toast-container--bottom-left {
  bottom: 1rem;
  left: 1rem;
  align-items: flex-start;
  flex-direction: column-reverse;
}

.hh-toast-container--top-center {
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
}

.hh-toast-container--bottom-center {
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
  flex-direction: column-reverse;
}

/* ── Toast item ── */
.hh-toast {
  --hh-toast-accent: var(--hh-green);
  --hh-toast-bg: #fff;
  --hh-toast-icon-bg: rgba(21, 133, 85, 0.12);
  --hh-toast-icon-color: var(--hh-green);

  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 0.85rem 0.85rem 0;
  border-radius: 14px;
  background: var(--hh-toast-bg);
  border: 1px solid rgba(0, 70, 46, 0.08);
  box-shadow:
    0 4px 6px rgba(0, 70, 46, 0.04),
    0 16px 40px rgba(0, 70, 46, 0.12);
  overflow: hidden;
  pointer-events: auto;
  opacity: 0;
  transform: translateX(110%);
  transition:
    opacity 0.32s var(--hh-ease),
    transform 0.38s var(--hh-spring);
}

.hh-toast-container--top-left .hh-toast,
.hh-toast-container--bottom-left .hh-toast {
  transform: translateX(-110%);
}

.hh-toast-container--top-center .hh-toast,
.hh-toast-container--bottom-center .hh-toast {
  transform: translateY(-110%);
}

.hh-toast.is-visible {
  opacity: 1;
  transform: translateX(0);
}

.hh-toast-container--top-center .hh-toast.is-visible,
.hh-toast-container--bottom-center .hh-toast.is-visible {
  transform: translateY(0);
}

.hh-toast.is-leaving {
  opacity: 0;
  transform: translateX(110%) scale(0.96);
  transition-duration: 0.22s;
}

.hh-toast-container--top-left .hh-toast.is-leaving,
.hh-toast-container--bottom-left .hh-toast.is-leaving {
  transform: translateX(-110%) scale(0.96);
}

.hh-toast-container--top-center .hh-toast.is-leaving,
.hh-toast-container--bottom-center .hh-toast.is-leaving {
  transform: translateY(-110%) scale(0.96);
}

.hh-toast-accent {
  width: 4px;
  align-self: stretch;
  border-radius: 14px 0 0 14px;
  background: var(--hh-toast-accent);
  flex-shrink: 0;
}

.hh-toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin-top: 0.05rem;
  border-radius: 10px;
  background: var(--hh-toast-icon-bg);
  color: var(--hh-toast-icon-color);
  flex-shrink: 0;
}

.hh-toast-body {
  min-width: 0;
  padding-top: 0.1rem;
}

.hh-toast-title {
  display: block;
  font-family: 'Inter', 'Nunito', sans-serif;
  font-size: 0.8125rem;
  font-weight: 800;
  color: var(--hh-dark);
  line-height: 1.3;
  margin-bottom: 0.15rem;
}

.hh-toast-message {
  display: block;
  font-family: 'Nunito', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: rgba(0, 70, 46, 0.78);
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  max-height: 8rem;
  overflow-y: auto;
}

.hh-toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin-top: 0.05rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(0, 70, 46, 0.4);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.hh-toast-close:hover {
  color: var(--hh-dark);
  background: rgba(0, 70, 46, 0.06);
}

.hh-toast-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(189, 232, 13, 0.5);
}

.hh-toast-progress {
  position: absolute;
  left: 4px;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(0, 70, 46, 0.06);
}

.hh-toast-progress span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: var(--hh-toast-accent);
  animation: hhToastProgress linear forwards;
}

@keyframes hhToastProgress {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* ── Toast types ── */
.hh-toast--success {
  --hh-toast-accent: var(--hh-green);
  --hh-toast-icon-bg: rgba(21, 133, 85, 0.12);
  --hh-toast-icon-color: var(--hh-green);
}

.hh-toast--error {
  --hh-toast-accent: #c0392b;
  --hh-toast-icon-bg: rgba(192, 57, 43, 0.10);
  --hh-toast-icon-color: #c0392b;
}

.hh-toast--warning {
  --hh-toast-accent: #c47f17;
  --hh-toast-icon-bg: rgba(196, 127, 23, 0.12);
  --hh-toast-icon-color: #c47f17;
}

.hh-toast--info {
  --hh-toast-accent: var(--hh-dark);
  --hh-toast-icon-bg: rgba(0, 70, 46, 0.08);
  --hh-toast-icon-color: var(--hh-dark);
}

/* ── Responsive ── */
@media (max-width: 575.98px) {
  .hh-toast-container {
    width: calc(100vw - 1rem);
  }

  .hh-toast-container--top-right,
  .hh-toast-container--top-left,
  .hh-toast-container--bottom-right,
  .hh-toast-container--bottom-left {
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    align-items: stretch;
  }

  .hh-toast-container--top-center,
  .hh-toast-container--bottom-center {
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    transform: none;
    align-items: stretch;
  }

  .hh-loader-panel {
    padding: 1.65rem 1.35rem 1.35rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hh-loader-spinner::after,
  .hh-loader-spinner-core,
  .hh-loader-bar span,
  .hh-toast-progress span {
    animation: none !important;
  }

  .hh-loader-overlay,
  .hh-loader-panel,
  .hh-toast {
    transition: none !important;
  }
}
