@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
    :root {
        --background: 0 0% 98%;
        --foreground: 0 0% 7%;
        --card: 0 0% 100%;
        --card-foreground: 0 0% 7%;
        --popover: 0 0% 100%;
        --popover-foreground: 0 0% 7%;
        --primary: 0 0% 7%;
        --primary-foreground: 0 0% 98%;
        --secondary: 0 0% 95%;
        --secondary-foreground: 0 0% 20%;
        --muted: 0 0% 94%;
        --muted-foreground: 0 0% 45%;
        --accent: 24 95% 53%;
        --accent-foreground: 0 0% 100%;
        --success: 142 71% 45%;
        --success-foreground: 0 0% 100%;
        --warning: 38 92% 50%;
        --warning-foreground: 0 0% 7%;
        --destructive: 0 84% 60%;
        --destructive-foreground: 0 0% 98%;
        --border: 0 0% 91%;
        --input: 0 0% 91%;
        --ring: 0 0% 7%;
        --radius: 0.875rem;
    }

    * {
        @apply border-border;
    }

    body {
        @apply bg-background text-foreground antialiased;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    body.mobile-floating-nav-pad {
        padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        letter-spacing: -0.025em;
    }
}

@layer utilities {
    /** Fixed dialog max height: dvh avoids mobile browser chrome clipping; vh fallback for older engines. */
    .collab-modal-panel {
        max-height: calc(100vh - 2rem);
    }

    @supports (height: 100dvh) {
        .collab-modal-panel {
            max-height: calc(100dvh - 1.5rem);
        }
    }

    /** Scroll region inside fixed-height dialogs (flex child needs min-h-0 + overflow). */
    .dialog-body-scroll {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    /** Collab / board cards — aligned with settings & profile surfaces. */
    .glass-card {
        @apply border border-border/60 bg-card/95 text-card-foreground shadow-sm ring-1 ring-black/[0.04] backdrop-blur-sm transition-[box-shadow,border-color,background-color] duration-200 dark:bg-card/90 dark:ring-white/[0.06];
    }

    /** Kanban column shell behind stacked cards. */
    .board-column-surface {
        @apply rounded-2xl border border-border/60 bg-secondary/25 shadow-sm ring-1 ring-black/[0.03] backdrop-blur-sm dark:bg-secondary/15 dark:ring-white/[0.05];
    }

    .status-dot {
        @apply h-2 w-2 shrink-0 rounded-full ring-2 ring-background;
    }

    .drag-over-highlight {
        @apply bg-accent/5 ring-2 ring-accent/35;
    }
}

.card-stagger > *:nth-child(1) {
    animation-delay: 0ms;
}
.card-stagger > *:nth-child(2) {
    animation-delay: 40ms;
}
.card-stagger > *:nth-child(3) {
    animation-delay: 80ms;
}
.card-stagger > *:nth-child(4) {
    animation-delay: 120ms;
}
.card-stagger > *:nth-child(5) {
    animation-delay: 160ms;
}
.card-stagger > *:nth-child(6) {
    animation-delay: 200ms;
}
.card-stagger > *:nth-child(7) {
    animation-delay: 240ms;
}
.card-stagger > *:nth-child(8) {
    animation-delay: 280ms;
}
.card-stagger > *:nth-child(9) {
    animation-delay: 320ms;
}
.card-stagger > *:nth-child(10) {
    animation-delay: 360ms;
}

/**
 * System-style toast: glass surface, springy motion, SF-like glyphs.
 * Pair with resources/js/app.js (app-toast CustomEvent).
 */
.app-toast-host {
    pointer-events: none;
    position: fixed;
    z-index: 300;
    left: 50%;
    bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    display: flex;
    width: min(100% - 1.75rem, 22rem);
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    transform: translateX(-50%);
}

@media (min-width: 640px) {
    .app-toast-host {
        bottom: 2.5rem;
    }
}

.app-toast {
    position: relative;
    overflow: hidden;
    border-radius: 1.25rem;
    padding: 0.8125rem 1rem 0.8125rem 0.875rem;
    background: hsl(var(--card) / 0.78);
    border: 1px solid hsl(var(--border) / 0.55);
    box-shadow:
        0 0 0 0.5px hsl(var(--foreground) / 0.05) inset,
        0 1px 0 hsl(0 0% 100% / 0.14) inset,
        0 18px 48px -12px rgb(0 0 0 / 0.28),
        0 8px 20px -8px rgb(0 0 0 / 0.14);
    backdrop-filter: blur(28px) saturate(1.75);
    -webkit-backdrop-filter: blur(28px) saturate(1.75);
    transform: translate3d(0, 0, 0);
    will-change: transform, opacity, filter;
}

.app-toast-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-toast-text {
    margin: 0;
    flex: 1;
    min-width: 0;
    text-align: left;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.35;
    color: hsl(var(--foreground));
}

.app-toast-glyph {
    flex-shrink: 0;
}

.app-toast-glyph-disk {
    fill: hsl(var(--success));
}

.app-toast-glyph-mark {
    stroke: hsl(var(--success-foreground));
}

.app-toast--destructive .app-toast-glyph-disk {
    fill: hsl(var(--destructive));
}

.app-toast--destructive .app-toast-glyph-mark {
    stroke: hsl(var(--destructive-foreground));
}

.app-toast--success::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 0%,
        transparent 40%,
        hsl(var(--success) / 0.12) 50%,
        transparent 60%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: app-toast-sheen 1.15s cubic-bezier(0.32, 0.72, 0, 1) 0.15s both;
    pointer-events: none;
}

.app-toast--destructive::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 0%,
        transparent 40%,
        hsl(var(--destructive) / 0.1) 50%,
        transparent 60%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: app-toast-sheen 1.05s cubic-bezier(0.32, 0.72, 0, 1) 0.12s both;
    pointer-events: none;
}

@keyframes app-toast-sheen {
    0% {
        background-position: 130% 0;
        opacity: 0;
    }
    12% {
        opacity: 1;
    }
    100% {
        background-position: -30% 0;
        opacity: 0;
    }
}

@keyframes app-toast-enter {
    0% {
        opacity: 0;
        transform: translate3d(0, 22px, 0) scale(0.86);
        filter: blur(10px);
    }
    58% {
        opacity: 1;
        filter: blur(0);
        transform: translate3d(0, -3px, 0) scale(1.028);
    }
    78% {
        transform: translate3d(0, 1px, 0) scale(0.994);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
        filter: blur(0);
    }
}

@keyframes app-toast-exit {
    0% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
        filter: blur(0);
    }
    100% {
        opacity: 0;
        transform: translate3d(0, 14px, 0) scale(0.93);
        filter: blur(6px);
    }
}

@keyframes app-toast-enter-reduced {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes app-toast-exit-reduced {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.app-toast--in {
    animation: app-toast-enter 0.58s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.app-toast--out {
    animation: app-toast-exit 0.42s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@media (prefers-reduced-motion: reduce) {
    .app-toast {
        will-change: auto;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .app-toast--success::after,
    .app-toast--destructive::after {
        animation: none;
        opacity: 0;
    }

    .app-toast--in {
        animation: app-toast-enter-reduced 0.2s ease-out both;
    }

    .app-toast--out {
        animation: app-toast-exit-reduced 0.2s ease-in forwards;
    }

    .app-livewire-syncing {
        opacity: 0.9;
        transform: none;
        filter: none;
    }
}

/** Livewire request: subtle “system sync” feel on full-page shells */
.app-livewire-syncing {
    opacity: 0.82;
    transform: scale(0.997);
    filter: saturate(0.94);
    transition:
        opacity 0.34s cubic-bezier(0.32, 0.72, 0, 1),
        transform 0.34s cubic-bezier(0.32, 0.72, 0, 1),
        filter 0.34s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes saved-ring {
    0% {
        box-shadow: 0 0 0 0 hsl(var(--accent) / 0.45);
    }
    100% {
        box-shadow: 0 0 0 14px hsl(var(--accent) / 0);
    }
}

.animate-saved-ring {
    animation: saved-ring 1.15s ease-out both;
}

.pwa-pull-indicator {
    transform: translate3d(0, -44px, 0) scale(0.88);
    will-change: transform, opacity;
}

.pwa-pull-chevron {
    transform-origin: center;
    transition: color 0.2s ease;
}

.pwa-pull-progress-ring {
    transition: stroke-dashoffset 0.04s linear;
}

.pwa-pull-indicator--active .pwa-pull-progress {
    @apply text-accent;
}

.pwa-pull-indicator--active .pwa-pull-chevron {
    @apply text-accent;
}

.pwa-pull-indicator--refreshing .pwa-pull-spinner {
    display: block;
    transform-origin: center;
    animation: pwa-refresh-spin 0.72s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .pwa-pull-progress-ring {
        transition: none;
    }

    .pwa-pull-indicator--refreshing .pwa-pull-spinner {
        animation: none;
    }
}

.touch-manipulation {
    touch-action: manipulation;
}

/**
 * System-style tap feedback. Scoped to :active only so existing
 * component transitions (e.g. primary-button) stay in control of timing.
 */
@media (prefers-reduced-motion: no-preference) {
    :where(
            button:not(:disabled),
            [type='submit']:not(:disabled),
            [type='button']:not(:disabled),
            [type='reset']:not(:disabled),
            [role='button']:not([aria-disabled='true'])
        ):active {
        transform: scale(0.97);
    }

    :where(a[href]):active {
        transform: scale(0.98);
    }
}
