/* ---------- Katibox motion layer ----------
   Built on Emil Kowalski's design-engineering rules:
   - strong custom easings, ease-out for anything entering or responding
   - UI under 300ms, exits faster than enters
   - never animate from scale(0); no ease-in; no springs on utility UI
   - frequent actions get little or no motion
   - animate transform + opacity only
   - hover effects only on real hover devices
   - reduced motion keeps opacity fades, drops movement

   Some rules use the `html:root` prefix so they win over the inline <style>
   in index.html and over gallery-modern.css, which load after this file. */

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-press: 140ms;
  --dur-fast: 160ms;
  --dur-med: 220ms;
  --dur-slow: 320ms;
}

/* ---------- Page + subpage transitions ----------
   Keep directional slide classes from styles.css intact while smoothly settling subpages. */
.page.active:not(.anim-forward):not(.anim-backward) { animation: pageEnter 220ms var(--ease-out) both; }
html:root .page.active.anim-forward { animation: pageSlideInRight 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
html:root .page.active.anim-backward { animation: pageSlideInLeft 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes pageEnter {
  from { opacity: 0; transform: translate3d(0, 6px, 0); }
  to   { opacity: 1; transform: none; }
}
html:root .subpage.active { animation: subpageEnter 210ms cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes subpageEnter {
  from { opacity: 0; transform: translate3d(0, 6px, 0); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Card / list entrance ----------
   Light stagger (JS sets --stagger and capped inline delays). */
.stat, .card, .info-tile, .report-card, .photo,
.activity-row, .receipt, .account-pick, .bo-card {
  animation: cardEnter 240ms var(--ease-out) backwards;
  animation-delay: calc(min(var(--stagger, 0), 8) * 30ms);
}
html:root .activity-row,
html:root .receipt,
html:root .photo,
html:root #historyTable tbody tr,
html:root #reportTable tbody tr {
  animation: cardEnter 240ms var(--ease-out) backwards;
}
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Press feedback instead of ripple ----------
   The ripple is decorative on very frequent controls. JS still adds the
   span, so keep it inert and let :active scale carry the feedback. */
.ripple { display: none !important; }

.primary, .secondary, .chip, .icon-btn, .tab, .pw-toggle, .row-edit,
.close, .item-remove, .bo-btn, .bo-icon-btn, .bo-link, .bo-menu-item,
.lockbox-chip, .lockbox-action, .paybill-copy, .buy-pack, .plan-card {
  transition: transform var(--dur-press) var(--ease-out),
              background-color var(--dur-fast) ease,
              border-color var(--dur-fast) ease,
              color var(--dur-fast) ease,
              box-shadow var(--dur-fast) ease,
              filter var(--dur-fast) ease;
}
.primary:active, .secondary:active, .chip:active, .icon-btn:active,
.bo-btn:active, .bo-icon-btn:active, .bo-menu-item:active,
.lockbox-chip:active, .paybill-copy:active, .buy-pack:active,
.plan-card:active { transform: scale(0.97); }
.tab:active, .row-edit:active, .item-remove:active { transform: scale(0.95); }

html:root .snap-fab,
html:root .bo-fab {
  transition: transform var(--dur-press) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              filter var(--dur-fast) var(--ease-out);
}
html:root .snap-fab:active,
html:root .bo-fab:active { transform: scale(0.95); }

/* Hover polish only where a real pointer exists */
@media (hover: hover) and (pointer: fine) {
  .row-edit:hover { background: var(--surface-2); color: var(--ink); }
}

/* ---------- Clickable stat cards ---------- */
.stat-clickable {
  transition: transform var(--dur-med) var(--ease-out),
              box-shadow var(--dur-med) var(--ease-out),
              border-color var(--dur-med) var(--ease-out);
}
.stat-clickable:active { transform: scale(0.99); }

/* ---------- Number change feedback ----------
   A colour flash. No scaling, so values never jump around. */
.pulse { animation: valuePulse 500ms var(--ease-out); }
@keyframes valuePulse {
  0%   { color: var(--green); }
  100% { color: inherit; }
}

/* ---------- Notifications ----------
   Occasional and meaningful, so a short bell wiggle is fine. */
.icon-btn.new-notif { animation: bellShake 450ms var(--ease-out); }
@keyframes bellShake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  50% { transform: rotate(8deg); }
  75% { transform: rotate(-4deg); }
}
.notif-badge, .bo-badge { animation: badgePop 200ms var(--ease-out) both; }
@keyframes badgePop {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Notification / account panels scale from their trigger (top right) */
.notif-panel, .bo-notif-panel, .bo-account-panel {
  transform-origin: top right;
  animation: popoverIn 160ms var(--ease-out) both;
}
@keyframes popoverIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Toast ----------
   Transition (not keyframes) so rapid toasts retarget smoothly. */
html:root .toast {
  transition: opacity var(--dur-med) var(--ease-out),
              transform var(--dur-med) var(--ease-out);
}
.bo-toast {
  transition: opacity var(--dur-med) var(--ease-out),
              transform var(--dur-med) var(--ease-out);
}

/* ---------- Modals ----------
   Backdrop fades, box scales from 0.96 and stays centred. */
.modal.open { animation: modalFade 150ms var(--ease-out) both; }
.modal.open .modal-box { animation: kbModalPop var(--dur-med) var(--ease-out) both; }
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes kbModalPop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: none; }
}
.bo-modal.open .bo-modal-box { animation: kbModalPop var(--dur-med) var(--ease-out) both; }

/* Mobile: modals are bottom sheets, so slide up & down smoothly with the drawer curve */
@media (max-width: 900px) {
  .modal.open .modal-box { animation: sheetUp 280ms var(--ease-drawer) both; }
  .modal.closing { animation: modalFadeOut 170ms ease forwards; }
  .modal.closing .modal-box { animation: sheetDown 170ms cubic-bezier(0.4, 0, 1, 1) forwards; }
  @keyframes sheetUp {
    from { opacity: 0.92; transform: translate3d(0, 100%, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 0); }
  }
  @keyframes sheetDown {
    from { opacity: 1; transform: translate3d(0, 0, 0); }
    to   { opacity: 0.9; transform: translate3d(0, 100%, 0); }
  }
  @keyframes modalFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
  }
}

/* ---------- Charts ----------
   Bars rise from the baseline, starting partly formed. */
.bar {
  transform-origin: bottom;
  animation: barGrow 420ms var(--ease-out) both;
  animation-delay: calc(min(var(--bar-i, 0), 8) * 40ms);
}
@keyframes barGrow {
  from { transform: scaleY(0.5); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}

/* ---------- Table rows ----------
   Rows reload on every filter keystroke, so opacity only. */
tbody tr {
  animation: rowFade 160ms var(--ease-out) both;
  animation-delay: calc(min(var(--row-i, 0), 8) * 20ms);
}
@keyframes rowFade { from { opacity: 0; } to { opacity: 1; } }
html:root #historyTable tbody tr,
html:root #reportTable tbody tr {
  animation: rowFade 160ms var(--ease-out) both;
}

/* ---------- Lightbox ---------- */
.lightbox:not(.hidden) .lightbox-img-wrap img {
  animation: lightboxZoom var(--dur-med) var(--ease-out) both;
}
@keyframes lightboxZoom {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- Gallery images fade in without scaling ---------- */
html:root .photo-image img { animation: imageFade 200ms var(--ease-out) both; }
@keyframes imageFade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Loading ---------- */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface-2) 25%,
    color-mix(in srgb, var(--surface-2) 60%, var(--surface)) 50%,
    var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s linear infinite;
  border-radius: 8px;
  color: transparent !important;
  pointer-events: none;
}
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Approval flash (rare, so a little delight is fine) ---------- */
.approve-flash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 500;
  animation: flashFade 1.2s var(--ease-out) forwards;
}
.approve-flash .check-circle {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--green, #176b55);
  display: grid; place-items: center;
  box-shadow: 0 20px 60px rgba(23,107,85,.4);
  animation: checkPop 320ms var(--ease-out) both;
}
.approve-flash svg {
  width: 48px; height: 48px;
  stroke: #fff; stroke-width: 3;
  fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.approve-flash svg path {
  stroke-dasharray: 50; stroke-dashoffset: 50;
  animation: drawCheck 380ms var(--ease-out) 100ms forwards;
}
@keyframes checkPop {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes drawCheck { to { stroke-dashoffset: 0; } }
@keyframes flashFade {
  0% { opacity: 0; }
  15%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Highlights + validation ---------- */
.row-highlight { animation: rowHighlight 1.1s var(--ease-out); }
@keyframes rowHighlight {
  0%   { background: color-mix(in srgb, var(--green-soft, #e4f0eb) 75%, transparent); }
  100% { background: transparent; }
}
.shake { animation: shake 350ms var(--ease-out) both; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ---------- Theme switch ---------- */
html.theme-transitioning, html.theme-transitioning * {
  transition: background-color 200ms ease,
              color 200ms ease,
              border-color 200ms ease,
              fill 200ms ease !important;
}
html:root #themeBtn,
html:root #themeBtn svg { transition: transform 250ms var(--ease-in-out); }

/* ---------- Navigation ---------- */
.tabbar-item {
  transition: color var(--dur-fast) ease,
              transform var(--dur-press) var(--ease-out);
}
.tabbar-item:active { transform: scale(0.96); }
/* No icon bounce: switching tabs is a frequent action. */

html:root .nav-item.active::before { animation: navIndicator 160ms var(--ease-out) both; }
@keyframes navIndicator { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Reduced motion ----------
   Keep gentle opacity fades, remove movement and decoration. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }

  .page.active, .subpage.active, .stat, .card, .info-tile, .report-card,
  .photo, .activity-row, .receipt, .account-pick, .bo-card,
  .modal.open .modal-box, .bo-modal.open .bo-modal-box,
  .notif-panel, .bo-notif-panel, .bo-account-panel,
  .lightbox:not(.hidden) .lightbox-img-wrap img, .bar,
  html:root .activity-row, html:root .receipt, html:root .photo {
    animation: reducedFade 150ms ease both !important;
  }
  @keyframes reducedFade { from { opacity: 0; } to { opacity: 1; } }

  .icon-btn.new-notif, .shake, .pulse, .approve-flash svg path {
    animation: none !important;
  }
  .approve-flash svg path { stroke-dashoffset: 0; }
  .skeleton { animation: none; }
  .primary:active, .secondary:active, .chip:active, .icon-btn:active,
  .tab:active, .tabbar-item:active, .stat-clickable:active { transform: none; }
}

/* ============================================================
   Overrides for leftovers in index.html (inline <style>) and
   gallery-modern.css, which load after this file.
   `html:root` raises specificity so no other file needs editing.
   ============================================================ */

/* Keep the stagger the inline rules used (shorthand above resets it) */
html:root .activity-row:nth-child(n),
html:root .receipt:nth-child(n),
html:root .photo:nth-child(n) {
  animation-delay: calc(min(var(--stagger, 0), 8) * 30ms);
}
html:root #historyTable tbody tr,
html:root #reportTable tbody tr {
  animation-delay: calc(min(var(--row-i, 0), 8) * 20ms);
}

/* ---------- Chips: no spring, no ungated lift ---------- */
html:root .chip {
  transition: transform var(--dur-press) var(--ease-out),
              background-color var(--dur-fast) ease,
              color var(--dur-fast) ease,
              border-color var(--dur-fast) ease,
              box-shadow var(--dur-fast) ease;
}
html:root .chip:hover { transform: none; box-shadow: none; }
html:root .chip.active:hover { box-shadow: 0 6px 18px rgba(23,107,85,.28); }
html:root .chip:active { transform: scale(0.97); }
html:root .chip.bounce { animation: none; }
@media (hover: hover) and (pointer: fine) {
  html:root .chip:hover:not(.active) { box-shadow: 0 4px 12px rgba(23,107,85,.08); }
}

/* ---------- Photos: hover only on real pointers ---------- */
html:root .photo {
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-med) var(--ease-out),
              border-color var(--dur-med) var(--ease-out);
}
html:root .photo:hover {
  transform: none;
  box-shadow: 0 1px 3px rgba(15,25,20,.04);
  border-color: var(--line);
}
html:root .photo:active { transform: scale(0.98); }
html:root .photo-image img { transition: transform var(--dur-slow) var(--ease-out); }
html:root .photo:hover .photo-image img { transform: none; }
html:root .photo-remove {
  transform: scale(0.95);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              color var(--dur-fast) ease;
}
html:root .photo:hover .photo-remove { transform: none; }
html:root .photo-remove:hover { transform: none; }
@media (hover: hover) and (pointer: fine) {
  html:root .photo:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(23,107,85,.16);
    border-color: color-mix(in srgb, var(--green) 30%, var(--line));
  }
  html:root .photo:hover .photo-image img { transform: scale(1.04); }
  html:root .photo-remove:hover { transform: scale(1.1); }
}
@media (hover: none) { html:root .photo-remove { transform: none; } }

/* ---------- Profile avatar badge: no scale(.6) ---------- */
html:root .avatar-edit-badge { transform: scale(0.9); }

/* ---------- Full-screen layers: ease-out fade ---------- */
@keyframes kbFade { from { opacity: 0; } to { opacity: 1; } }
html:root .lightbox,
html:root .editor-modal { animation: kbFade var(--dur-med) var(--ease-out) both; }

/* ---------- Home page entrance ----------
   Seen on every visit: one short rise, tiny stagger, no sideways slide. */
html:root #page-home .hero,
html:root #page-home .stats .stat,
html:root #page-home .grid > .card:first-child,
html:root #page-home .grid > .spotlight,
html:root #page-home .card[style*="margin-top"] {
  animation: cardEnter 240ms var(--ease-out) backwards;
  animation-delay: 0ms;
}
html:root #page-home .stats .stat:nth-child(2) { animation-delay: 40ms; }
html:root #page-home .stats .stat:nth-child(3) { animation-delay: 80ms; }
html:root #page-home .stats .stat:nth-child(4) { animation-delay: 120ms; }
html:root #page-home .grid > .card:first-child { animation-delay: 140ms; }
html:root #page-home .grid > .spotlight { animation-delay: 180ms; }
html:root #page-home .card[style*="margin-top"] { animation-delay: 220ms; }

/* ---------- Decorative loops off ----------
   Ambient orbs and the "today" dot pulse ran forever behind everything. */
html:root .ambient-bg .orb,
html:root #todayDate::before { animation: none; }

/* ---------- Splash: rare, so a little delight, but no spin ---------- */
@keyframes kbSplashLogo {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: none; }
}
html:root .splash-logo { animation: kbSplashLogo 500ms var(--ease-out) both; }
html:root .splash-logo::before { animation: none; opacity: .5; }
html:root .splash-screen { transition: opacity var(--dur-slow) var(--ease-out); }
html:root .splash-dots span { animation-timing-function: ease-in-out; } /* loading dots: keep loop */

/* ---------- Goodbye overlay ---------- */
html:root .goodbye-overlay { transition: opacity var(--dur-med) var(--ease-out); }
html:root .goodbye-inner {
  transform: scale(0.96);
  transition: transform var(--dur-slow) var(--ease-out);
}
html:root .goodbye-overlay.show .goodbye-inner { transform: none; }
html:root .goodbye-logo { animation: none; }

@media (prefers-reduced-motion: reduce) {
  html:root .splash-logo, html:root .lightbox, html:root .editor-modal,
  html:root #page-home .hero, html:root #page-home .stats .stat,
  html:root #page-home .grid > .card:first-child,
  html:root #page-home .grid > .spotlight,
  html:root #page-home .card[style*="margin-top"] {
    animation: reducedFade 150ms ease both !important;
  }
  html:root .photo:hover, html:root .photo:hover .photo-image img { transform: none !important; }
}

/* ============================================================
   Fotolog: category chips reveal their sub-categories
   Only the row that just appeared animates (JS adds .is-new),
   so picking a sibling chip never replays it.
   ============================================================ */
@keyframes kbRowIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
html:root .chip-row-sub.is-new {
  animation: kbRowIn 180ms var(--ease-out) backwards;
}
html:root .chip-row-sub.is-new .chip {
  animation: kbRowIn 180ms var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
}
/* Typing in search: results swap in place, no entrance replay per keystroke */
html:root .is-searching .photo { animation: none; }

@media (prefers-reduced-motion: reduce) {
  html:root .chip-row-sub.is-new,
  html:root .chip-row-sub.is-new .chip { animation: reducedFade 150ms ease backwards !important; }
}
