/* Motion layer for the console.
 *
 * Additive only: this file never restyles an existing component, it defines the
 * shared duration/easing tokens and the components the console did not have
 * (accordion, tooltip, popover, drawer, tab indicator, counter, button states).
 *
 * The console already ships a focus trap, scroll lock, focus restore, a
 * .skeleton shimmer and a blanket prefers-reduced-motion rule, so none of those
 * are re-implemented here.
 */

:root {
  /* Duration scale. Small controls stay snappy, large reveals get room.
   * Deliberately three steps, not one value reused everywhere. */
  --motion-fast: 180ms;   /* buttons, icons, checkboxes: 150-200ms */
  --motion-mid: 340ms;    /* cards, menus, drawers: 300-400ms */
  --motion-slow: 600ms;   /* hero / large reveals: 500-700ms */

  /* Easing. Entrances decelerate; only continuous motion is linear. */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-linear: linear;

  /* Reading-order entrance delay. Enough to build hierarchy, not to feel slow. */
  --motion-stagger: 100ms;
}

/* ---------- Accordion ---------------------------------------------------- */
/* Height is animated in JS (auto height cannot be interpolated in CSS), so the
 * panel only needs to clip and the icon only needs to rotate. */
.mo-accordion__panel {
  overflow: hidden;
}

.mo-accordion__item.is-open > .mo-accordion__trigger {
  background: var(--surface-2, rgba(15, 23, 42, 0.04));
  font-weight: 600;
}

.mo-accordion__trigger {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  text-align: start;
  /* An expandable region must look expandable before any animation runs. */
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out);
}

.mo-accordion__trigger:hover {
  background: var(--surface-2, rgba(15, 23, 42, 0.04));
}

/* The plus/minus is one glyph: the vertical bar of a "+" rotates and fades. */
.mo-accordion__icon {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
}

.mo-accordion__icon::before,
.mo-accordion__icon::after {
  position: absolute;
  border-radius: 1px;
  background: currentColor;
  content: "";
}

.mo-accordion__icon::before {
  top: 6px;
  left: 0;
  width: 14px;
  height: 2px;
}

.mo-accordion__icon::after {
  top: 0;
  left: 6px;
  width: 2px;
  height: 14px;
  transition: transform var(--motion-fast) var(--ease-out), opacity var(--motion-fast) var(--ease-out);
}

.mo-accordion__item.is-open .mo-accordion__icon::after {
  transform: rotate(90deg);
  opacity: 0;
}

/* ---------- Tooltip and popover ----------------------------------------- */
.mo-tip {
  position: fixed;
  z-index: 90;
  max-width: 18rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.82rem;
  line-height: 1.4;
  pointer-events: none;
}

.mo-popover {
  position: fixed;
  z-index: 90;
  max-width: 22rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  border-radius: 12px;
  background: var(--surface, #fff);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
}

/* ---------- Drawer ------------------------------------------------------- */
.mo-drawer-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
}

.mo-drawer {
  position: fixed;
  z-index: 81;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(26rem, 100%);
  height: 100%;
  background: var(--surface, #fff);
  box-shadow: -18px 0 44px rgba(15, 23, 42, 0.18);
}

/* Declared before the media query below, which reveals it on phones. */
.mo-drawer__handle {
  display: none;
  flex: none;
  width: 2.5rem;
  height: 4px;
  margin: 0.6rem auto;
  border-radius: 2px;
  background: var(--border, rgba(15, 23, 42, 0.2));
}

@media (max-width: 640px) {
  /* Near-full-screen on phones, with a grab handle for the swipe-down close. */
  .mo-drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .mo-drawer__handle {
    display: block;
  }
}

/* ---------- Tab indicator ----------------------------------------------- */
.mo-tabs {
  position: relative;
}

.mo-tabs__indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent, #2563eb);
}

.mo-tabs__panels {
  position: relative;
  overflow: hidden;
}

/* ---------- Button async states ----------------------------------------- */
.mo-btn {
  position: relative;
}

/* A disabled async button must still read as "working", not as "broken". */
.mo-btn[aria-busy="true"] {
  cursor: progress;
}

.mo-btn__spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-radius: 50%;
  /* Continuous rotation is the one place linear timing is correct. */
  border-top-color: transparent;
  animation: mo-spin 700ms var(--ease-linear) infinite;
  vertical-align: -0.15em;
}

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

.mo-btn__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 2px 2px 0;
  background: currentColor;
  opacity: 0.55;
  transition: width var(--motion-fast) var(--ease-out);
}

/* Errors never rely on colour alone: an icon and text carry the meaning. */
.mo-field-error {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  margin-top: 0.35rem;
  color: var(--danger, #b42318);
  font-size: 0.85rem;
}

.mo-field-error__icon {
  flex: none;
  font-weight: 700;
}

/* ---------- Focus visibility -------------------------------------------- */
/* One focus language everywhere, and always a ring -- never a bare shift. */
.mo-scope :focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Card hover / press ------------------------------------------ */
.mo-card {
  transition:
    transform var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
}

@media (hover: hover) {
  .mo-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.14);
  }
}

/* Keyboard focus earns exactly the hover treatment, not a lesser one. */
.mo-card:focus-within {
  transform: translateY(-3px);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.14);
}

.mo-press:active {
  transform: scale(0.97);
}

/* ---------- Reveal on scroll -------------------------------------------- */
/* Pre-animation state. Applied by JS only when it will actually animate, so
 * content is never left invisible if the script fails to load. */
.mo-reveal-armed {
  opacity: 0;
}

/* ---------- Reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  /* Keep state feedback, drop travel: no pointer-following, no card lift. */
  .mo-card:hover,
  .mo-card:focus-within,
  .mo-press:active {
    transform: none;
  }

  .mo-reveal-armed {
    opacity: 1;
  }

  /* Spinners stay -- a load indicator that does not move conveys nothing --
   * but slow enough to avoid a strobing edge. */
  .mo-btn__spinner {
    animation-duration: 1.4s;
  }
}

/* ---------- Card spotlight ---------------------------------------------- */
/* Driven by --mo-spot-* custom properties set from JS. Only this overlay
 * repaints, so no child element is transformed and text cannot wobble. */
.mo-spotlight {
  position: relative;
  --mo-spot-alpha: 0;
}

.mo-spotlight::before {
  position: absolute;
  z-index: 0;
  inset: 0;
  background: radial-gradient(
    16rem circle at var(--mo-spot-x, 50%) var(--mo-spot-y, 50%),
    rgba(37, 99, 235, var(--mo-spot-alpha)),
    transparent 65%
  );
  content: "";
  opacity: 1;
  transition: background 220ms var(--ease-out);
  pointer-events: none;
}

.mo-spotlight > * {
  position: relative;
  z-index: 1;
}

/* ---------- Toast ------------------------------------------------------- */
.mo-toast {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

@media (prefers-reduced-motion: reduce) {
  .mo-spotlight::before { display: none; }
}
