/* ============================================================
   ALDEAPATH — Unified Notification & Feedback System
   ------------------------------------------------------------
   One canonical visual language for every message the user sees:
   toasts, inline form validation, page-level banners and the
   branded error screen.

   Tokens come from aldeapath-system.css (--success / --danger /
   --warning / --info / --card / --border / --text / --muted).
   Fallbacks are provided so this file also works standalone on
   pages that do not load the full design system.
   ============================================================ */

:root {
  --ap-n-radius: 14px;
  --ap-n-shadow: 0 12px 34px rgba(8, 26, 20, .16), 0 2px 6px rgba(8, 26, 20, .08);
  --ap-n-gap: .625rem;
}

/* ── Toast stack ─────────────────────────────────────────── */
#ap-notify-root {
  position: fixed;
  z-index: 100000;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: var(--ap-n-gap);
  width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.ap-toast {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  padding: .85rem .9rem .85rem .95rem;
  border-radius: var(--ap-n-radius);
  background: var(--card, #fff);
  color: var(--text, #10201a);
  border: 1px solid var(--border, #e5e6e0);
  border-left: 4px solid var(--ap-n-accent, var(--info, #1f5f7a));
  box-shadow: var(--ap-n-shadow);
  font-family: inherit;
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(.98);
  transition: opacity .26s cubic-bezier(.22, 1, .36, 1),
              transform .26s cubic-bezier(.22, 1, .36, 1);
}

.ap-toast.is-visible { opacity: 1; transform: translateY(0) scale(1); }
.ap-toast.is-leaving { opacity: 0; transform: translateY(6px) scale(.98); }

.ap-toast--success { --ap-n-accent: var(--success, #0f7a4f); }
.ap-toast--error   { --ap-n-accent: var(--danger,  #b3261e); }
.ap-toast--warning { --ap-n-accent: var(--warning, #a3701a); }
.ap-toast--info    { --ap-n-accent: var(--info,    #1f5f7a); }

.ap-toast__icon {
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ap-n-accent);
  color: #fff;
  font-size: .78rem;
  line-height: 1;
  margin-top: .05rem;
}

.ap-toast__body { flex: 1 1 auto; min-width: 0; }

.ap-toast__title {
  margin: 0 0 .12rem;
  font-size: .855rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text, #10201a);
}

.ap-toast__message {
  margin: 0;
  font-size: .8rem;
  line-height: 1.45;
  color: var(--muted, #6b7a73);
  overflow-wrap: anywhere;
}

.ap-toast__action {
  margin-top: .5rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .7rem;
  border: 1px solid var(--ap-n-accent);
  border-radius: 999px;
  background: transparent;
  color: var(--ap-n-accent);
  font: inherit;
  font-size: .76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.ap-toast__action:hover { background: var(--ap-n-accent); color: #fff; }

.ap-toast__close {
  flex: 0 0 auto;
  width: 1.65rem;
  height: 1.65rem;
  min-width: 1.65rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #6b7a73);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: .7;
  transition: opacity .18s ease, background .18s ease;
}
.ap-toast__close:hover { opacity: 1; background: rgba(0, 0, 0, .05); }
.ap-toast__close:focus-visible,
.ap-toast__action:focus-visible {
  outline: 2px solid var(--ap-n-accent);
  outline-offset: 2px;
}

.ap-toast__progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left center;
  background: var(--ap-n-accent);
  opacity: .5;
  animation: ap-toast-progress linear forwards;
}

@keyframes ap-toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ── Mobile: dock to the bottom so nothing covers the header ─── */
@media (max-width: 640px) {
  #ap-notify-root {
    right: .625rem;
    left: .625rem;
    top: auto;
    bottom: calc(.625rem + env(safe-area-inset-bottom, 0px));
    width: auto;
    flex-direction: column;
  }
  .ap-toast { transform: translateY(10px) scale(.98); }
  .ap-toast.is-visible { transform: translateY(0) scale(1); }
  .ap-toast.is-leaving { transform: translateY(6px) scale(.98); }
  .ap-toast__close { width: 2.75rem; height: 2.75rem; min-width: 2.75rem; }
}

/* ── Page-level banner (persistent context, e.g. offline) ── */
.ap-banner {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  padding: .8rem .9rem;
  margin: 0 0 1rem;
  border-radius: var(--ap-n-radius);
  border: 1px solid var(--ap-n-accent, var(--info, #1f5f7a));
  background: var(--ap-n-surface, var(--info-bg, #e9f2f6));
  color: var(--text, #10201a);
  font-size: .82rem;
  line-height: 1.5;
}
.ap-banner--success { --ap-n-accent: var(--success-border, #b9e0cd); --ap-n-surface: var(--success-bg, #e9f6ef); }
.ap-banner--error   { --ap-n-accent: var(--danger-border,  #f0c4c1); --ap-n-surface: var(--danger-bg,  #fbeceb); }
.ap-banner--warning { --ap-n-accent: var(--warning-border, #e8d5a3); --ap-n-surface: var(--warning-bg, #fbf4e3); }
.ap-banner--info    { --ap-n-accent: var(--info-border,    #bfd8e3); --ap-n-surface: var(--info-bg,    #e9f2f6); }
.ap-banner__icon { flex: 0 0 auto; margin-top: .1rem; }
.ap-banner__title { display: block; font-weight: 700; margin-bottom: .1rem; }

/* ── Inline form validation ──────────────────────────────── */
.ap-field-error {
  display: flex;
  align-items: flex-start;
  gap: .35rem;
  margin: .35rem 0 0;
  font-size: .765rem;
  line-height: 1.4;
  font-weight: 500;
  color: var(--danger, #b3261e);
  animation: ap-field-in .22s cubic-bezier(.22, 1, .36, 1);
}
.ap-field-error::before {
  content: "!";
  flex: 0 0 auto;
  width: .95rem;
  height: .95rem;
  margin-top: .1rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--danger, #b3261e);
  color: #fff;
  font-size: .62rem;
  font-weight: 800;
}

.ap-field-hint {
  margin: .35rem 0 0;
  font-size: .765rem;
  line-height: 1.4;
  color: var(--muted, #6b7a73);
}

.ap-invalid,
input.ap-invalid,
select.ap-invalid,
textarea.ap-invalid {
  border-color: var(--danger, #b3261e) !important;
  box-shadow: 0 0 0 3px rgba(179, 38, 30, .12) !important;
}

.ap-valid,
input.ap-valid,
select.ap-valid,
textarea.ap-valid {
  border-color: var(--success, #0f7a4f) !important;
}

@keyframes ap-field-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Branded full-screen error state ─────────────────────── */
.ap-error-screen {
  position: fixed;
  inset: 0;
  z-index: 100001;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg, #f6f7f4);
  color: var(--text, #10201a);
  font-family: inherit;
  animation: ap-fade-in .3s ease;
}
.ap-error-screen__card {
  width: min(440px, 100%);
  text-align: center;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e5e6e0);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  box-shadow: var(--ap-n-shadow);
}
.ap-error-screen__mark {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-light, #e8f4ef);
  color: var(--brand, #0d7a5f);
  font-size: 1.2rem;
}
.ap-error-screen__title {
  margin: 0 0 .5rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.ap-error-screen__text {
  margin: 0 0 1.35rem;
  font-size: .875rem;
  line-height: 1.6;
  color: var(--muted, #6b7a73);
}
.ap-error-screen__actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
}
.ap-error-screen__btn {
  appearance: none;
  border: 1px solid var(--brand, #0d7a5f);
  background: var(--brand, #0d7a5f);
  color: #fff;
  border-radius: 999px;
  padding: .65rem 1.35rem;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: filter .18s ease;
}
.ap-error-screen__btn:hover { filter: brightness(1.06); }
.ap-error-screen__btn--ghost {
  background: transparent;
  color: var(--brand, #0d7a5f);
}
.ap-error-screen__btn:focus-visible {
  outline: 2px solid var(--brand, #0d7a5f);
  outline-offset: 3px;
}
.ap-error-screen__ref {
  margin: 1rem 0 0;
  font-size: .7rem;
  color: var(--muted, #6b7a73);
  opacity: .8;
}

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

/* ── Screen-reader only live region ──────────────────────── */
.ap-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ap-toast,
  .ap-field-error,
  .ap-error-screen { transition: none !important; animation: none !important; }
  .ap-toast { opacity: 1; transform: none; }
  .ap-toast__progress { display: none; }
}

/* ── High contrast / forced colors ───────────────────────── */
@media (forced-colors: active) {
  .ap-toast { border: 1px solid CanvasText; }
  .ap-toast__icon { forced-color-adjust: none; }
}
