/* =====================================================================
   emil.css — Emil Kowalski-style design layer
   • Sonner-style toasts (stack, spring-in, swipe-to-dismiss, hover-expand)
   • Vaul-style bottom drawer (drag, momentum, grab handle, scaled bg)
   • Motion polish (spring easing, staggered card entrance, soft focus)

   Self-contained: only adds new classes + a few progressive enhancements.
   Honors prefers-reduced-motion (the global reduce rule in styles.css
   neutralizes the transitions/animations below).
   ===================================================================== */

:root {
  /* Emil's motion language: gentle overshoot springs + soft standard ease */
  --emil-spring: cubic-bezier(0.22, 1.0, 0.36, 1.0);
  --emil-spring-out: cubic-bezier(0.34, 1.56, 0.64, 1.0);
  --emil-ease: cubic-bezier(0.4, 0.0, 0.2, 1.0);
  --emil-shadow: 0 4px 12px rgba(27, 42, 74, 0.10), 0 12px 32px rgba(27, 42, 74, 0.12);
  --emil-shadow-lg: 0 8px 24px rgba(27, 42, 74, 0.14), 0 24px 64px rgba(27, 42, 74, 0.20);
}

/* =====================================================================
   1. Page scaler — Vaul scales the page back while the drawer is open.
   emil.js wraps the original <body> children in #emilPage so we can
   transform the whole page as one layer (the drawer/overlay/toasts are
   appended as siblings, so they are NOT scaled).
   ===================================================================== */
#emilPage {
  transform-origin: 50% 0;
  transition: transform 0.5s var(--emil-spring), border-radius 0.5s var(--emil-spring);
  will-change: transform;
}
body.emil-drawer-open {
  background: #0c1326; /* dark backdrop revealed behind the scaled page */
  overflow: hidden;
}
body.emil-drawer-open #emilPage {
  transform: scale(0.965) translateY(8px);
  border-radius: 16px;
  overflow: hidden;
}

/* =====================================================================
   2. Sonner-style toasts
   ===================================================================== */
.emil-toaster {
  position: fixed;
  z-index: 9999;
  bottom: 24px;
  right: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  /* height is set inline by emil.js to match the live stack */
  pointer-events: none; /* the toasts themselves opt back in */
}
.emil-toaster[data-expanded="true"] { pointer-events: auto; } /* catch hover over gaps */

.emil-toast {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  transform-origin: 50% 100%;
  transition:
    transform 0.45s var(--emil-spring),
    opacity 0.4s var(--emil-ease);
  pointer-events: auto;
}
.emil-toast-inner {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 14px 15px;
  background: #fff;
  border: 1px solid var(--line, #d9dee8);
  border-radius: 13px;
  box-shadow: var(--emil-shadow);
  transition: transform 0.3s var(--emil-spring);
  touch-action: pan-y;
  cursor: grab;
}
.emil-toast-inner:active { cursor: grabbing; }

/* swipe-out + enter states are driven by emil.js toggling classes */
.emil-toast.emil-toast--enter { opacity: 0; transform: translateY(18px) scale(0.96); }
.emil-toast.emil-toast--out   { opacity: 0; }

.emil-toast-icon {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
  color: #fff;
}
.emil-toast[data-type="success"] .emil-toast-icon { background: var(--ok, #1c8a4d); }
.emil-toast[data-type="error"]   .emil-toast-icon { background: var(--danger, #c0392b); }
.emil-toast[data-type="info"]    .emil-toast-icon { background: var(--navy, #1b2a4a); }
.emil-toast[data-type="default"] .emil-toast-icon { display: none; }
.emil-toast[data-type="loading"] .emil-toast-icon { background: none; }
.emil-toast[data-type="loading"] .emil-toast-icon::after {
  content: "";
  width: 15px; height: 15px;
  border: 2px solid rgba(27, 42, 74, 0.2);
  border-top-color: var(--navy, #1b2a4a);
  border-radius: 50%;
  animation: emil-spin 0.7s linear infinite;
}
@keyframes emil-spin { to { transform: rotate(360deg); } }

.emil-toast-body { flex: 1 1 auto; min-width: 0; }
.emil-toast-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text, #1d2433);
  line-height: 1.35;
  word-wrap: break-word;
}
.emil-toast-desc {
  font-size: 13px;
  color: var(--muted, #6b7488);
  line-height: 1.4;
  margin-top: 2px;
}
.emil-toast-action {
  margin-top: 9px;
  display: inline-flex;
  align-items: center;
  background: var(--navy, #1b2a4a);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s var(--emil-ease), transform 0.12s var(--emil-ease);
}
.emil-toast-action:hover { filter: brightness(1.1); }
.emil-toast-action:active { transform: scale(0.96); }

.emil-toast-close {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  margin: -2px -3px 0 0;
  border: none;
  background: none;
  color: var(--muted, #6b7488);
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s var(--emil-ease), background 0.15s var(--emil-ease);
}
.emil-toaster[data-expanded="true"] .emil-toast-close,
.emil-toast:hover .emil-toast-close { opacity: 1; }
.emil-toast-close:hover { background: rgba(27, 42, 74, 0.08); }

/* mobile: dock toasts to the bottom edge, full width */
@media (max-width: 600px) {
  .emil-toaster {
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
  }
}

/* =====================================================================
   3. Vaul-style drawer
   ===================================================================== */
.emil-overlay {
  position: fixed;
  inset: 0;
  z-index: 9990;
  background: rgba(8, 15, 33, 0.45);
  opacity: 0;
  transition: opacity 0.45s var(--emil-ease);
  -webkit-tap-highlight-color: transparent;
}
.emil-overlay[data-show="true"] { opacity: 1; }

.emil-drawer {
  position: fixed;
  z-index: 9991;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 520px;
  background: var(--bg, #f4f6fa);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--emil-shadow-lg);
  transform: translateY(100%);
  /* transition is toggled on by emil.js so the initial drag is 1:1 */
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  touch-action: none;
}
.emil-drawer[data-animate="true"] {
  transition: transform 0.5s var(--emil-spring);
}
.emil-drawer-grip {
  flex: 0 0 auto;
  width: 40px;
  height: 5px;
  margin: 11px auto 4px;
  border-radius: 999px;
  background: #c8cedb;
  cursor: grab;
}
.emil-drawer:active .emil-drawer-grip { cursor: grabbing; }
.emil-drawer-head {
  flex: 0 0 auto;
  padding: 6px 22px 10px;
}
.emil-drawer-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  color: var(--navy, #1b2a4a);
}
.emil-drawer-sub {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--muted, #6b7488);
}
.emil-drawer-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 22px calc(22px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* share grid inside the drawer */
.emil-share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.emil-share-grid .emil-share-btn:first-child { grid-column: 1 / -1; } /* copy spans full width */
.emil-share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 14px;
  background: #fff;
  border: 1px solid var(--line, #d9dee8);
  border-radius: 13px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--navy, #1b2a4a);
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 0.18s var(--emil-spring),
    box-shadow 0.18s var(--emil-ease),
    border-color 0.15s var(--emil-ease);
}
.emil-share-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--emil-shadow);
  border-color: var(--navy, #1b2a4a);
}
.emil-share-btn:active { transform: translateY(0) scale(0.98); }

/* the trigger button shown inline on the success page */
.emil-share-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

/* =====================================================================
   4. Motion polish pass (progressive — applies to the existing UI)
   ===================================================================== */
@media (prefers-reduced-motion: no-preference) {
  /* spring lift + press on the public buttons */
  #signView .btn-primary,
  #successView .btn-primary,
  .gate-card .btn-primary,
  #signView .btn-ghost,
  #successView .btn-ghost {
    transition:
      background 0.18s var(--emil-ease),
      transform 0.2s var(--emil-spring),
      box-shadow 0.2s var(--emil-ease);
  }
  #signView .btn-primary:hover,
  #successView .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(27, 42, 74, 0.22);
  }
  #signView .btn-primary:active,
  #successView .btn-primary:active,
  #signView .btn-ghost:active,
  #successView .btn-ghost:active { transform: scale(0.975); }

  /* staggered entrance for the sign-view cards (delay set inline by emil.js) */
  #signView .card.emil-rise {
    animation: emil-rise 0.6s var(--emil-spring) both;
  }
  /* success check draws itself in */
  #successView .success-card .check.emil-pop {
    animation: emil-pop 0.55s var(--emil-spring-out) both;
  }
}

@keyframes emil-rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes emil-pop {
  0%   { opacity: 0; transform: scale(0.3); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}

/* softer, animated focus ring on the form inputs (Emil-style glow) */
input[type="text"], input[type="date"], input[type="email"],
input[type="tel"], input[type="search"], select {
  transition:
    border-color 0.16s var(--emil-ease),
    box-shadow 0.18s var(--emil-ease),
    background 0.16s var(--emil-ease);
}
#signView input:focus, #signView select:focus,
#successView input:focus,
.gate-card input:focus {
  outline: none;
  border-color: var(--focus, #3a6df0);
  box-shadow: 0 0 0 3px rgba(58, 109, 240, 0.18);
}

/* the progress fill gets a slightly springier travel + sheen */
.progress-fill {
  transition: width 0.8s var(--emil-spring) !important;
}
