/* EB motion and interaction layer. Loaded last on every page, so it is the one place durations, curves and
   site-wide interaction rules live. Rules follow the "UX & Animation" procedure:
   1. should it move  2. where the eye goes  3. how it moves  4. can people hit it  5. can they finish. */

:root {
  /* curves */
  --ease-enter: cubic-bezier(0.32, 0.72, 0, 1);    /* things appearing: menus, popovers, modals, toasts */
  --ease-exit: cubic-bezier(0.55, 0, 1, 0.45);     /* things leaving, on the shorter exit duration */
  --ease-move: cubic-bezier(0.77, 0, 0.175, 1);    /* moving or resizing while on screen */
  --ease-press: cubic-bezier(0.23, 1, 0.32, 1);    /* press feedback */
  /* durations */
  --dur-press: 150ms;   /* press, hover, colour */
  --dur-pop: 200ms;     /* dropdown, popover */
  --dur-modal: 240ms;   /* modal, drawer, toast entering */
  --dur-exit: 180ms;    /* modal, drawer, toast leaving (20-30% shorter) */
  --dur-move: 260ms;    /* progress fills, expanders, reorders */
}

/* ---------- 1. Should it move? ----------
   App pages are opened many times a session: content already on the page when it paints does not play an entrance. */
.page > *, .page [data-view]:not(.hidden) > * { animation: none; }
.stat-value { animation: none; }
.nav a[aria-current="page"]::before { animation: none; }
.nav a:hover svg { animation: none; }          /* navigation is used constantly: no wiggle */
.up-hero .up-badge { animation: none; }         /* never loop text people are reading */

/* ---------- 3. How should it move? ---------- */

/* Press: every button confirms the press on the same frame, and glides back if released mid-press. */
.btn { transition: transform var(--dur-press) var(--ease-press), background-color var(--dur-press) ease, border-color var(--dur-press) ease, box-shadow var(--dur-press) ease, color var(--dur-press) ease, opacity var(--dur-press) ease; }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { transform: none; }

/* Hover motion only where a real pointer hovers. Wide surfaces (cards) change colour and shadow, never jump. */
@media (hover: hover) {
  .card:hover { transform: none; }
  .nav a:hover { transform: none; }
  .btn:hover { transform: none; }
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { transform: translateY(-1px); }
  .btn:active:not(:disabled) { transform: scale(0.96); }
  .card-hover:hover { transform: none; background-color: #fff; border-color: #d4cec6; box-shadow: 0 10px 28px rgba(17, 17, 17, 0.08); }
}

/* The skip link slides with transform, never by animating `top`. */
.skip-link { top: 12px; transform: translateY(calc(-100% - 24px)); transition: transform var(--dur-pop) var(--ease-enter); }
.skip-link:focus { transform: none; }

/* Alerts and inline notices appear on the popover clock. */
.alert { animation-duration: var(--dur-pop); animation-timing-function: var(--ease-enter); }

/* Modals created by scripts: one clock for the panel and its backdrop. */
.modal-backdrop, .scrim { animation-duration: var(--dur-modal); animation-timing-function: var(--ease-enter); }
.modal { animation-duration: var(--dur-modal); animation-timing-function: var(--ease-enter); }
.board-panel { animation-duration: var(--dur-modal); }

/* Native <dialog> windows (plans, view plans): enter on the modal clock, leave faster and quieter,
   and stay inert while closing. @starting-style gives the entrance; allow-discrete keeps them painted on exit. */
dialog.upgrade-dialog {
  opacity: 0; transform: translateY(10px) scale(0.98);
  transition: opacity var(--dur-exit) var(--ease-exit), transform var(--dur-exit) var(--ease-exit),
    overlay var(--dur-exit) allow-discrete, display var(--dur-exit) allow-discrete;
}
dialog.upgrade-dialog[open] {
  opacity: 1; transform: none; animation: none;
  transition: opacity var(--dur-modal) var(--ease-enter), transform var(--dur-modal) var(--ease-enter),
    overlay var(--dur-modal) allow-discrete, display var(--dur-modal) allow-discrete;
}
@starting-style { dialog.upgrade-dialog[open] { opacity: 0; transform: translateY(10px) scale(0.97); } }
dialog.upgrade-dialog:not([open]) { pointer-events: none; }
dialog.upgrade-dialog::backdrop { background: rgba(17, 17, 17, 0); transition: background-color var(--dur-exit) var(--ease-exit), overlay var(--dur-exit) allow-discrete, display var(--dur-exit) allow-discrete; }
dialog.upgrade-dialog[open]::backdrop { background: rgba(17, 17, 17, 0.5); transition-duration: var(--dur-modal); transition-timing-function: var(--ease-enter); }
@starting-style { dialog.upgrade-dialog[open]::backdrop { background: rgba(17, 17, 17, 0); } }

/* Plan cards (plans window, registration): wide surfaces, so colour and shadow on hover, no lift. */
.up-card, .plan-card { transition: border-color var(--dur-press) ease, box-shadow var(--dur-press) ease, background-color var(--dur-press) ease; }
@media (hover: hover) { .up-card:hover { transform: none; } }
@media (hover: hover) and (pointer: fine) { .up-card:hover { box-shadow: 0 12px 30px rgba(17, 17, 17, 0.1); } }
.plan-card:active { transform: none; }

/* Busy buttons (set by ux.js): the label stays, a spinner joins it after 300ms, and it holds at least 500ms. */
.btn.is-busy { opacity: 0.85; cursor: progress; }
.btn.is-busy::before {
  content: ""; flex: none; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: eb-spin 700ms linear infinite;
}
@keyframes eb-spin { to { transform: rotate(360deg); } }

/* Error shake: only on a failed submit, on the field that's wrong (set by ux.js). */
.shake { animation: eb-shake 360ms var(--ease-move); }
@keyframes eb-shake {
  0%, 100% { transform: translateX(0); } 16% { transform: translateX(-10px); } 33% { transform: translateX(10px); }
  50% { transform: translateX(-6px); } 66% { transform: translateX(6px); } 83% { transform: translateX(-3px); }
}

/* ---------- 4. Can people hit it? ----------
   Small icon controls keep their look but get a 44px target (40px is the floor with a mouse). */
.upgrade-close, .menu-btn, .icon-btn, .hq-d-close, #hq-d-close { position: relative; }
.upgrade-close::after, .menu-btn::after, .icon-btn::after, #hq-d-close::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: max(100%, 44px); height: max(100%, 44px); translate: -50% -50%;
}
input[type="checkbox"], input[type="radio"] { min-width: 18px; min-height: 18px; }

/* ---------- Reduced motion ----------
   Everything settles at once and loops stop (no 1ms flicker); work-in-progress indicators keep moving,
   because a frozen spinner looks like a hang. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .btn.is-busy::before, .skeleton, .spinner { animation-duration: 700ms !important; animation-iteration-count: infinite !important; }
  .shake { animation: none !important; }
  dialog.upgrade-dialog, dialog.upgrade-dialog[open], dialog.upgrade-dialog::backdrop { transition: none !important; }
}

/* ---------- Exits for script-built layers ----------
   Mobile menu overlay: fades on the drawer's clock (paired elements share one duration and curve). */
.scrim { animation-duration: 280ms; animation-timing-function: var(--ease-drawer, var(--ease-enter)); }
.scrim.is-closing { animation: eb-fade-out 280ms var(--ease-drawer, var(--ease-enter)) both; pointer-events: none; }
/* Goal / task modal (dashboard): quieter and faster on the way out. */
.modal-backdrop.is-closing { animation: eb-fade-out var(--dur-exit) var(--ease-exit) both; pointer-events: none; }
.modal-backdrop.is-closing .modal { animation: eb-modal-out var(--dur-exit) var(--ease-exit) both; }
@keyframes eb-fade-out { to { opacity: 0; } }
@keyframes eb-modal-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }
/* HQ company drawer and its backdrop: one 300ms clock, drawer leaves the way it came. */
.hq-drawer { transition-duration: 300ms; }
.hq-scrim { transition: opacity 300ms var(--ease-drawer, var(--ease-enter)); }

/* ---------- App screens ---------- */
/* Company setup progress: grows from the left with transform, on the move curve. */
.setup-progress > div { width: 100%; transform: scaleX(0); transform-origin: left center; transition: transform var(--dur-move) var(--ease-move); }
/* Board meeting: each executive's finding opens with the grid-rows expander, never by animating height. */
.seat .finding-wrap { display: grid; grid-template-rows: 0fr; overflow: hidden; transition: grid-template-rows var(--dur-move) var(--ease-move); }
.seat .finding-wrap:has(.finding.shown) { grid-template-rows: 1fr; }
.seat .finding { min-height: 0; max-height: none; margin-top: 0; padding-top: 10px; overflow: hidden; opacity: 0; transition: opacity var(--dur-move) ease; }
.seat .finding.shown { max-height: none; margin-top: 0; padding-top: 10px; opacity: 1; }
/* Dashboard goal cards are wide surfaces: shadow and border on hover, no jump. */
@media (hover: hover) and (pointer: fine) { .goal-card:hover { transform: none; } }
/* EB HQ is opened many times a day: usage bars show their value at once. */
.hq-bar > i { animation: none; }

/* Toast (ux.js): enters from the bottom on the modal clock, leaves quieter and faster. */
.eb-toast { position: fixed; left: 50%; bottom: 24px; z-index: 300; display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 18px; border-radius: 12px; background: #111; color: #f3eee3; font-size: 14px; font-weight: 600; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.25);
  translate: -50% 0; animation: eb-toast-in var(--dur-modal) var(--ease-enter) both; }
.eb-toast.is-closing { animation: eb-toast-out var(--dur-exit) var(--ease-exit) both; pointer-events: none; }
.eb-toast-btn { position: relative; border: 0; border-radius: 8px; padding: 6px 12px; background: rgba(255, 255, 255, 0.12); color: #fff; font: inherit; font-weight: 700; cursor: pointer;
  transition: background-color var(--dur-press) ease, transform var(--dur-press) var(--ease-press); }
.eb-toast-btn::after { content: ""; position: absolute; top: 50%; left: 50%; width: max(100%, 44px); height: max(100%, 44px); translate: -50% -50%; }
.eb-toast-btn:active { transform: scale(0.96); }
@media (hover: hover) and (pointer: fine) { .eb-toast-btn:hover { background: rgba(255, 255, 255, 0.2); } }
@keyframes eb-toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes eb-toast-out { to { opacity: 0; transform: translateY(8px); } }
/* An item removed with Undo leaves the view at once; Undo puts it back. */
.eb-leaving { display: none !important; }
