/* ============================================================
   v=385 — Animations & Micro-interactions
   Dodatek do design system: subtelne animacje które podnoszą UX
   bez rozpraszania. Wszystkie krótkie (<400ms), z reduced-motion opt-out.
   ============================================================ */

/* ============ KEYFRAMES ============ */
@keyframes fp-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fp-fade-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fp-fade-slide-down {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fp-slide-in-right {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes fp-zoom-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes fp-pop-in {
  0% { opacity: 0; transform: scale(0.85); }
  70% { transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes fp-shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
@keyframes fp-pulse-gold {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 200, 150, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(232, 200, 150, 0); }
}
@keyframes fp-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes fp-ripple {
  from { transform: scale(0); opacity: 0.55; }
  to { transform: scale(2.6); opacity: 0; }
}
@keyframes fp-gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes fp-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes fp-glow-in {
  from { opacity: 0; box-shadow: 0 0 0 rgba(232, 200, 150, 0); }
  to { opacity: 1; box-shadow: 0 4px 24px rgba(232, 200, 150, 0.28); }
}
@keyframes fp-check-in {
  0% { stroke-dashoffset: 32; opacity: 0; }
  40% { opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}

/* ============ ROUTE / VIEW ENTRANCE ============ */
/* v=386 fix: NIE animujemy .view globalnie bo transform interferuje z
   canvas.getBoundingClientRect (snap w polygon editor łapał złą pozycję).
   Zamiast tego opt-in klasą .fp-view-enter na widokach które chcą animacji. */
.fp-view-enter {
  animation: fp-fade-slide-up 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.fp-view-enter.no-anim,
.fp-view-enter[data-anim-done] { animation: none; }
/* Polygon editor i 3D viewer NIGDY nie animujemy — canvas rely on precyzyjnym rect */
.polygon-editor,
.view.polygon-editor,
.view#view-3d,
#view-3d,
.view#view-visualize { animation: none !important; transform: none !important; }

/* ============ CARDS (project cards, room cards, etc.) ============ */
.project-card,
.room-card,
.turbo-card,
.cad-props-section {
  transition:
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.18s ease;
  will-change: transform;
}
.project-card:hover,
.room-card:hover,
.turbo-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(42, 24, 16, 0.14), 0 4px 10px rgba(42, 24, 16, 0.08);
}

/* Stagger entrance: dodawaj klasę .fp-stagger do rodzica, .fp-stagger-item do dzieci */
.fp-stagger .fp-stagger-item {
  opacity: 0;
  animation: fp-fade-slide-up 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.fp-stagger .fp-stagger-item:nth-child(1) { animation-delay: 0.02s; }
.fp-stagger .fp-stagger-item:nth-child(2) { animation-delay: 0.06s; }
.fp-stagger .fp-stagger-item:nth-child(3) { animation-delay: 0.10s; }
.fp-stagger .fp-stagger-item:nth-child(4) { animation-delay: 0.14s; }
.fp-stagger .fp-stagger-item:nth-child(5) { animation-delay: 0.18s; }
.fp-stagger .fp-stagger-item:nth-child(6) { animation-delay: 0.22s; }
.fp-stagger .fp-stagger-item:nth-child(7) { animation-delay: 0.26s; }
.fp-stagger .fp-stagger-item:nth-child(8) { animation-delay: 0.30s; }
.fp-stagger .fp-stagger-item:nth-child(n+9) { animation-delay: 0.34s; }

/* ============ BUTTONS ============ */
.btn-primary,
.btn-secondary,
button:not(.cad-iconbtn):not(.wall-tex-tile):not(.cad-mode) {
  position: relative;
  overflow: hidden;
  transition:
    transform 0.16s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.16s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.15s ease;
}
.btn-primary:hover,
.btn-secondary:hover {
  transform: translateY(-1px);
}
.btn-primary:active,
.btn-secondary:active,
button:active {
  transform: translateY(0) scale(0.98);
  transition-duration: 0.08s;
}
/* Ripple effect — element dodawany przez JS */
.fp-ripple {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0) 70%);
  pointer-events: none;
  width: 60px; height: 60px;
  margin-left: -30px; margin-top: -30px;
  animation: fp-ripple 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Primary CTA — subtelny pulse gdy jest jedyny na widoku */
.btn-cta-pulse {
  animation: fp-pulse-gold 2.4s ease-in-out infinite;
}

/* Floating Save FAB — subtelny float */
.cad-floating-save {
  animation: fp-float 3.2s ease-in-out infinite;
}
.cad-floating-save:hover {
  animation-play-state: paused;
}

/* ============ MODALS / OVERLAYS ============ */
[style*="position:fixed"][style*="inset:0"] {
  animation: fp-fade-in 0.22s ease-out;
}
[style*="position:fixed"][style*="inset:0"] > [style*="background"]:not([style*="rgba(0"]):not([style*="0,0,0"]) {
  animation: fp-zoom-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
#cad-help-modal > div,
#mobile-props-modal {
  animation: fp-zoom-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============ TOAST ============ */
.toast,
.app-toast,
#toast-container > * {
  animation: fp-slide-in-right 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.toast-leaving {
  animation: fp-slide-in-right 0.24s cubic-bezier(0.4, 0, 0.6, 1) reverse forwards;
}

/* ============ SKELETON LOADER (loading state) ============ */
.fp-skeleton {
  background: linear-gradient(
    90deg,
    rgba(200, 180, 140, 0.10) 0%,
    rgba(232, 200, 150, 0.28) 50%,
    rgba(200, 180, 140, 0.10) 100%
  );
  background-size: 800px 100%;
  animation: fp-shimmer 1.6s linear infinite;
  border-radius: 8px;
  color: transparent;
  user-select: none;
}
.fp-skeleton-block {
  width: 100%; height: 1em; margin: 0.3em 0;
}
.fp-skeleton-card {
  height: 140px; margin: 0.5rem 0;
}

/* ============ FOCUS RING (upgrade over v=382) ============ */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent-gold-dark, #9F7F4F);
  box-shadow: 0 0 0 3px rgba(232, 200, 150, 0.35);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

/* ============ CAD BREADCRUMB — floating micro-pulse gdy nowa lokalizacja ============ */
.cad-breadcrumb {
  transition: color 0.2s ease, transform 0.2s ease;
}
.cad-breadcrumb:not(:empty) {
  animation: fp-fade-slide-down 0.28s ease-out;
}

/* ============ 3D VIEWER LOAD ============ */
#three-mount {
  animation: fp-fade-in 0.45s ease-out;
}

/* ============ NAV/TOOLBAR ============ */
/* v=386 fix: transition transform na .cad-floating psuł collapse (bo transform
   .cad-floating-left ma teraz `translateX`) i psuł .cad-topbar który używa
   `transform: translateX(-50%)` do centrowania — animowanie tego przesuwało
   toolbar w bok. Zostawiam tylko opacity transition. */
.cad-floating {
  transition: opacity 0.2s ease;
}
/* Collapse toggle (rozwiń/zwiń panel) — pokazuj TAKŻE na mobile gdy panel jest zwinięty */
@media (max-width: 768px) {
  .cad-floating-left.collapsed .cad-floating-toggle,
  .cad-floating-right.collapsed .cad-floating-toggle {
    display: flex !important;
    width: 36px !important;
    height: 64px !important;
    background: linear-gradient(135deg, rgba(201, 168, 118, 0.9), rgba(159, 127, 79, 0.9)) !important;
    color: #FFEFD8 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35) !important;
    z-index: 205 !important;
    animation: fp-pulse-gold 2s ease-in-out infinite;
  }
  .cad-floating-left.collapsed .cad-floating-toggle::before {
    font-size: 1.4rem !important;
  }
  .cad-floating-right.collapsed .cad-floating-toggle::before {
    font-size: 1.4rem !important;
  }
}

/* ============ ICONS ============ */
/* Kliknij "refresh" icon → obraca się */
.fp-spin-once {
  animation: fp-spin 0.6s ease-in-out;
}
/* Success checkmark — SVG stroke reveal */
.fp-check-svg path {
  stroke-dasharray: 32;
  animation: fp-check-in 0.45s ease-out both;
}

/* ============ HERO / SPLASH BACKGROUND — subtelny gradient shift ============ */
.fp-animated-bg {
  background: linear-gradient(
    135deg,
    #FAF8F2 0%,
    #FFF8E8 25%,
    #F5EFE2 50%,
    #FFF8E8 75%,
    #FAF8F2 100%
  );
  background-size: 400% 400%;
  animation: fp-gradient-shift 18s ease-in-out infinite;
}
.fp-animated-bg-dark {
  background: linear-gradient(
    135deg,
    #1F1208 0%,
    #2A1810 25%,
    #14090A 50%,
    #2A1810 75%,
    #1F1208 100%
  );
  background-size: 400% 400%;
  animation: fp-gradient-shift 22s ease-in-out infinite;
}

/* ============ COUNTER (numery statystyk) ============ */
/* JS ustawia data-counting → dodaje subtle scale pulse na zmianę */
[data-counting] {
  display: inline-block;
  transition: color 0.15s ease;
}
[data-counting].fp-count-flash {
  animation: fp-pop-in 0.3s ease-out;
}

/* ============ CAD PROPS SECTION — entrance stagger po każdym rebuildzie ============ */
.cad-props-floating > .cad-props-section {
  animation: fp-fade-slide-up 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.cad-props-floating > .cad-props-section:nth-child(1) { animation-delay: 0.02s; }
.cad-props-floating > .cad-props-section:nth-child(2) { animation-delay: 0.07s; }
.cad-props-floating > .cad-props-section:nth-child(3) { animation-delay: 0.12s; }
.cad-props-floating > .cad-props-section:nth-child(4) { animation-delay: 0.17s; }
.cad-props-floating > .cad-props-section:nth-child(5) { animation-delay: 0.22s; }
.cad-props-floating > .cad-props-section:nth-child(6) { animation-delay: 0.27s; }

/* ============ WALL TEXTURE TILES — pop-in ============ */
.wall-tex-tile {
  animation: fp-pop-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: border-color 0.18s ease, box-shadow 0.22s ease, transform 0.14s ease;
}
.wall-tex-tile:nth-child(1) { animation-delay: 0.02s; }
.wall-tex-tile:nth-child(2) { animation-delay: 0.06s; }
.wall-tex-tile:nth-child(3) { animation-delay: 0.10s; }
.wall-tex-tile:nth-child(4) { animation-delay: 0.14s; }
.wall-tex-tile:nth-child(5) { animation-delay: 0.18s; }
.wall-tex-tile:nth-child(6) { animation-delay: 0.22s; }
.wall-tex-tile:nth-child(7) { animation-delay: 0.26s; }
.wall-tex-tile:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 20px rgba(201, 168, 118, 0.35);
}
.wall-tex-tile:active {
  transform: translateY(0) scale(0.98);
}

/* ============ SIDEBAR DRAWER — slide in from right ============ */
.side-drawer,
.turbo-drawer {
  animation: fp-slide-in-right 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============ DROPDOWN MENUS ============ */
.cad-dropdown-menu,
.dropdown-menu,
[role="menu"] {
  animation: fp-fade-slide-down 0.18s ease-out;
  transform-origin: top center;
}

/* ============ INTERIOR WALL START INDICATOR — subtelny pulse ============ */
.fp-interior-wall-active {
  animation: fp-pulse-gold 1.6s ease-in-out infinite;
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* End v=385 ==================================================== */

/* ============================================================
   v=387 — PWA / Native app tweaks
   ============================================================ */
/* Offline indicator — subtelny gold pasek na górze */
body.fp-offline::before {
  content: "📴 Tryb offline — zmiany zapisywane lokalnie";
  position: fixed;
  top: 0; left: 0; right: 0;
  background: linear-gradient(90deg, #B97D43, #8B5A2B);
  color: white;
  text-align: center;
  padding: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  z-index: 10000;
  animation: fp-fade-slide-down 0.3s ease-out;
  letter-spacing: 0.02em;
}
body.fp-offline .app-header,
body.fp-offline > section {
  padding-top: 32px;
}
/* Install button — subtelny fade-in gold */
#fp-install-btn {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#fp-install-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 30px rgba(159, 127, 79, 0.5);
}
/* Standalone mode — brak paska adresowego, więc możemy odzyskać marginesy */
body.fp-standalone .app-header {
  padding-top: max(0.8rem, env(safe-area-inset-top, 0.8rem));
}
/* Window Controls Overlay (Edge/Chrome desktop PWA) */
@media (display-mode: window-controls-overlay) {
  body { padding-top: env(titlebar-area-height, 0); }
}
/* End v=387 ==================================================== */
