/* ============================================
   DASHBOARD ANIMATIONS
   A: Staggered entrance
   D: Counter animation (via JS)
   E: Breathing AI pulse
   J: Pulse Grid background
   ============================================ */

/* J: Pulse Grid background */
@keyframes pulseGridRoam {
    0%   { transform: translate(-30%, -20%) scale(1); }
    14%  { transform: translate(25%, -35%) scale(1.05); }
    28%  { transform: translate(35%, 10%) scale(0.95); }
    42%  { transform: translate(10%, 30%) scale(1.08); }
    57%  { transform: translate(-25%, 25%) scale(0.97); }
    71%  { transform: translate(-35%, -5%) scale(1.03); }
    85%  { transform: translate(5%, -30%) scale(1); }
    100% { transform: translate(-30%, -20%) scale(1); }
}

/* A: Staggered entrance fade-in */
@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* E: Breathing AI pulse - larger, more visible */
@keyframes breathingPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
    }
    50% {
        box-shadow: 0 0 35px 12px rgba(59, 130, 246, 0.4);
    }
}

/* J: Sticky canvas wrapper — keeps canvas viewport-locked inside scrollable parent */
.synapse-sticky-wrap {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;           /* takes no space in flow */
    z-index: 0;
    pointer-events: none;
    overflow: visible;
}

/* J: Synapse canvas */
#synapse-canvas {
    display: block;
    pointer-events: none;
}

/* J: Pulse Grid wrapper */
.dashboard-wrapper {
    position: relative;
    overflow-x: hidden; /* prevent ::after glow from triggering horizontal scrollbar */
}

/* J: Dot grid layer — drawn by canvas, ::before reserved for future use */

/* J: Roaming glow layer — uses random color */
.dashboard-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 400px;
    height: 400px;
    margin-top: -200px;
    margin-left: -200px;
    background: radial-gradient(circle, rgba(var(--synapse-main, 59, 130, 246), 0.14) 0%, rgba(var(--synapse-accent, 139, 92, 246), 0.09) 40%, transparent 70%);
    border-radius: 50%;
    filter: blur(20px);
    pointer-events: none;
    z-index: 0;
    animation: pulseGridRoam 28s ease-in-out infinite;
    will-change: transform;
    box-shadow: 200px -150px 60px 0 rgba(var(--synapse-secondary, 236, 72, 153), 0.04);
}

[data-theme="dark"] .dashboard-wrapper::after {
    background: radial-gradient(circle, rgba(var(--synapse-main, 59, 130, 246), 0.28) 0%, rgba(var(--synapse-accent, 139, 92, 246), 0.16) 40%, transparent 70%);
    filter: blur(25px);
    box-shadow: 200px -150px 60px 0 rgba(var(--synapse-secondary, 236, 72, 153), 0.10);
}

/* J: Mobile - smaller glow */
@media (max-width: 640px) {
    .dashboard-wrapper::after {
        width: 300px;
        height: 300px;
        margin-top: -150px;
        margin-left: -150px;
    }
}

/* J: Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .dashboard-wrapper::after {
        animation: none;
        transform: translate(0, 0) scale(1);
        opacity: 0.5;
    }
}

/* Dashboard minimal styles */
.dashboard-minimal {
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px 24px;
    position: relative;
    z-index: 1;
}

/* Welcome section */
.welcome-section {
    margin-bottom: 48px;

    /* A: Staggered entrance - first element */
    opacity: 0;
    animation: fadeSlideUp 0.6s ease forwards;
    animation-delay: 0.1s;
}

.greeting {
    font-size: 32px;
    font-weight: 600;
    color: var(--foreground);
    margin: 0 0 8px 0;
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 16px;
    color: var(--foreground-secondary);
    margin: 0;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 48px;
    /* Parallax tilt: perspective for 3D effect */
    perspective: 1000px;
}

@media (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* A: Stat card entrance - opacity only (no transform to avoid tilt conflict) */
@keyframes statCardEntrance {
    from {
        opacity: 0;
        margin-top: 20px;
    }
    to {
        opacity: 1;
        margin-top: 0;
    }
}

/* Stat card */
.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);

    /* A: Staggered entrance - uses margin instead of transform */
    opacity: 0;
    animation: statCardEntrance 0.5s ease forwards;

    /* Parallax tilt: 3D transform support */
    transform-style: preserve-3d;
    transition: transform 0.15s ease-out, box-shadow 0.15s ease, border-color 0.15s ease;
    will-change: transform;
}

/* A: Stagger delays for each stat card */
.stat-card:nth-child(1) { animation-delay: 0.2s; }
.stat-card:nth-child(2) { animation-delay: 0.3s; }
.stat-card:nth-child(3) { animation-delay: 0.4s; }
.stat-card:nth-child(4) { animation-delay: 0.5s; }

.stat-card:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    border-color: var(--primary);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.stat-icon-blue {
    background: rgba(59, 130, 246, 0.12);
    color: #3B82F6;
    border: 1px solid rgba(59, 130, 246, 0.15);
}

.stat-icon-purple {
    background: rgba(139, 92, 246, 0.12);
    color: #8B5CF6;
    border: 1px solid rgba(139, 92, 246, 0.15);
}

.stat-icon-pink {
    background: rgba(236, 72, 153, 0.12);
    color: #EC4899;
    border: 1px solid rgba(236, 72, 153, 0.15);
}

.stat-icon-orange {
    background: rgba(249, 115, 22, 0.12);
    color: #F97316;
    border: 1px solid rgba(249, 115, 22, 0.15);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 600;
    color: var(--foreground);
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 13px;
    color: var(--foreground-secondary);
    margin-top: 2px;
}

.stat-yours {
    display: block;
    font-size: 12px;
    color: var(--foreground-secondary);
    opacity: 0.8;
    margin-top: 2px;
}

.stat-arrow {
    width: 16px;
    height: 16px;
    color: var(--foreground-secondary);
    opacity: 0;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

.stat-card:hover .stat-arrow {
    opacity: 1;
}

/* Loading indicator */
.loading-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--foreground-secondary);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Recent Activity section */
.activity-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 48px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);

    /* A: Staggered entrance */
    opacity: 0;
    animation: fadeSlideUp 0.5s ease forwards;
    animation-delay: 0.55s;
}

.activity-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 16px 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--foreground);
    transition: background 0.15s ease;
}

.activity-toggle:hover {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .activity-toggle:hover {
    background: rgba(255, 255, 255, 0.03);
}

.activity-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.activity-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.activity-count-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-light, rgba(59, 130, 246, 0.1));
    color: var(--primary);
}

.activity-chevron {
    color: var(--foreground-secondary);
    transition: transform 0.25s ease;
}

.activity-toggle[aria-expanded="false"] .activity-chevron {
    transform: rotate(-90deg);
}

.activity-body {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.activity-list {
    border-top: 1px solid var(--border);
    max-height: 420px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    text-decoration: none;
    color: var(--foreground);
    transition: background 0.2s ease, box-shadow 0.2s ease;
    border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
    position: relative;

    /* A: Staggered entrance */
    opacity: 0;
    animation: fadeSlideUp 0.35s ease forwards;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-item:hover {
    background: var(--primary-light, rgba(59, 130, 246, 0.04));
}

[data-theme="dark"] .activity-item:hover {
    background: rgba(59, 130, 246, 0.06);
}

/* Subtle left accent on hover */
.activity-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 25%;
    bottom: 25%;
    width: 2px;
    border-radius: 0 2px 2px 0;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.activity-item:hover::before {
    opacity: 1;
}

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.activity-item:hover .activity-icon {
    transform: scale(1.08);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.activity-icon svg {
    width: 18px;
    height: 18px;
}

.activity-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.activity-row-top {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.activity-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease;
}

.activity-item:hover .activity-name {
    color: var(--primary);
}

.activity-type-label {
    font-size: 11px;
    color: var(--foreground-secondary);
    opacity: 0.7;
    white-space: nowrap;
    flex-shrink: 0;
}

.activity-row-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--foreground-secondary);
}

.activity-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.activity-badge-created {
    background: rgba(16, 185, 129, 0.1);
    color: #10B981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.activity-badge-updated {
    background: rgba(59, 130, 246, 0.1);
    color: #3B82F6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.activity-detail {
    font-size: 12px;
    color: var(--foreground-secondary);
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.activity-time {
    font-size: 12px;
    color: var(--foreground-secondary);
    white-space: nowrap;
}

.activity-arrow {
    width: 14px;
    height: 14px;
    color: var(--primary);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.activity-item:hover .activity-arrow {
    opacity: 0.6;
    transform: translateX(0);
}

.activity-loading,
.activity-empty {
    padding: 32px 20px;
    text-align: center;
    color: var(--foreground-secondary);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Quick action button */
.quick-action {
    text-align: center;

    /* A: Staggered entrance - last element */
    opacity: 0;
    animation: fadeSlideUp 0.5s ease forwards;
    animation-delay: 0.8s;
}

.btn-primary-lg {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    background: var(--primary);
    color: white;
    font-size: 15px;
    font-weight: 500;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.15s ease;

    /* E: Breathing AI pulse */
    animation: breathingPulse 3s ease-in-out infinite;
}

.btn-primary-lg:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);

    /* E: Stop pulse on hover for clean interaction */
    animation: none;
}

.btn-primary-lg svg {
    width: 20px;
    height: 20px;
}

/* Dark mode adjustments */
[data-theme="dark"] .stat-card {
    background: var(--card);
    border-color: var(--border);
}

[data-theme="dark"] .stat-card:hover {
    border-color: var(--primary);
}