/* ============================================
   GENERATION PROGRESS STYLES
   Phase 1: Wait State & Loading Polish
   ============================================ */

/* =====================================================================
   PROGRESS CONTAINER
   ===================================================================== */
.generation-progress {
    display: none;
    flex-direction: column;
    padding: 20px;
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    margin: 16px;
    animation: progress-fade-in 0.3s ease-out;
}

.generation-progress.active {
    display: flex;
}

@keyframes progress-fade-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.generation-progress-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 600;
    color: #e5e7eb;
}

.generation-progress-header .header-icon {
    font-size: 20px;
}

/* =====================================================================
   PHASE LIST
   ===================================================================== */
.generation-phases {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.generation-phase {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative; /* Required for ::after pseudo-element positioning */
}

/* Phase icon container */
.phase-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* Phase label */
.phase-label {
    flex: 1;
    font-size: 14px;
    color: #9ca3af;
    transition: color 0.3s ease;
}

/* =====================================================================
   PHASE STATES
   ===================================================================== */

/* Pending state */
.generation-phase.pending .phase-icon::before {
    content: "○";
    color: #6b7280;
}

.generation-phase.pending .phase-label {
    color: #6b7280;
}

/* Active state */
.generation-phase.active {
    background: rgba(59, 130, 246, 0.1);
}

.generation-phase.active .phase-icon::before {
    content: "◐";
    color: #3b82f6;
    animation: pulse-spin 1.5s ease-in-out infinite;
}

.generation-phase.active .phase-label {
    color: #60a5fa;
    font-weight: 500;
}

@keyframes pulse-spin {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Active state with pulse animation on the entire phase */
.generation-phase.active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    animation: phase-pulse 2s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes phase-pulse {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

/* Complete state */
.generation-phase.complete .phase-icon::before {
    content: "✓";
    color: #22c55e;
}

.generation-phase.complete .phase-label {
    color: #86efac;
}

/* Error state */
.generation-phase.error {
    background: rgba(239, 68, 68, 0.1);
}

.generation-phase.error .phase-icon::before {
    content: "✗";
    color: #ef4444;
}

.generation-phase.error .phase-label {
    color: #fca5a5;
}

/* Error shake animation */
.generation-phase.error {
    animation: phase-shake 0.5s ease-in-out;
}

@keyframes phase-shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-4px); }
    30% { transform: translateX(4px); }
    45% { transform: translateX(-2px); }
    60% { transform: translateX(2px); }
}

/* =====================================================================
   LONG PHASE INDICATOR (Building/Generating)
   ===================================================================== */

/* Enhanced styling for long-running phases */
.generation-phase.long-phase {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 8px;
}

.generation-phase.long-phase .phase-icon::before {
    content: "🤖";
    animation: robot-pulse 2s ease-in-out infinite;
}

@keyframes robot-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

.generation-phase.long-phase .phase-label {
    color: #a5b4fc;
    font-weight: 600;
}

/* Building status container - shows cycling messages and progress */
.building-status-container {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 10px;
    padding: 16px 20px;
    margin: 16px 0;
    text-align: center;
}

.building-status-container.hidden {
    display: none;
}

.building-status-message {
    font-size: 15px;
    color: #c4b5fd;
    font-weight: 500;
    margin-bottom: 10px;
    min-height: 22px;
}

.building-status-message.fade-in {
    animation: message-fade-in 0.5s ease-out;
}

@keyframes message-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.building-progress-detail {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: #9ca3af;
}

.progress-percent {
    font-weight: 600;
    color: #a5b4fc;
    font-variant-numeric: tabular-nums;
    min-width: 32px;
}

.progress-separator {
    color: #4b5563;
}

.progress-hint {
    font-style: italic;
    color: #6b7280;
}

/* =====================================================================
   RICH DETAILS (SSE Progress)
   ===================================================================== */
.generation-rich-details {
    margin-bottom: 16px;
}

.progress-rich-detail {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    animation: rich-detail-fade-in 0.3s ease-out;
}

@keyframes rich-detail-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.detail-label {
    color: #9ca3af;
    font-size: 13px;
    flex-shrink: 0;
}

.detail-value {
    color: #e5e7eb;
    font-weight: 500;
    font-size: 13px;
}

.detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.detail-chip {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: #a5b4fc;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.detail-chip-more {
    background: rgba(75, 85, 99, 0.3);
    border-color: rgba(75, 85, 99, 0.5);
    color: #9ca3af;
}

/* =====================================================================
   PROGRESS BAR
   ===================================================================== */
.generation-progress-bar {
    height: 4px;
    background: #374151;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 16px;
}

.generation-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    border-radius: 2px;
    transition: width 0.5s ease-out;
    position: relative;
}

/* Animated gradient effect on progress bar */
.generation-progress-bar-fill::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: progress-shine 1.5s infinite;
}

@keyframes progress-shine {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* =====================================================================
   ELAPSED TIME
   ===================================================================== */
.generation-elapsed {
    text-align: center;
    font-size: 13px;
    color: #6b7280;
}

.generation-elapsed .elapsed-label {
    margin-right: 4px;
}

.generation-elapsed .elapsed-time {
    font-weight: 500;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
}

/* =====================================================================
   ERROR STATE
   ===================================================================== */
.generation-progress.error .generation-progress-header {
    color: #ef4444;
}

.generation-progress.error .generation-progress-bar-fill {
    background: #ef4444;
}

.generation-error-message {
    display: none;
    text-align: center;
    padding: 12px;
    margin-top: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #fca5a5;
    font-size: 13px;
}

.generation-progress.error .generation-error-message {
    display: block;
}

/* =====================================================================
   COMPLETION STATE
   ===================================================================== */
.generation-progress.complete .generation-progress-header {
    color: #22c55e;
}

.generation-progress.complete .generation-progress-bar-fill {
    background: linear-gradient(90deg, #22c55e, #4ade80);
}

/* Fade out animation */
.generation-progress.fade-out {
    animation: progress-fade-out 0.5s ease-out forwards;
}

@keyframes progress-fade-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* =====================================================================
   SHIMMER SKELETON ANIMATIONS
   ===================================================================== */
@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Skeleton base */
.skeleton {
    background: #374151;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

/* Shimmer overlay */
.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.08),
        transparent
    );
    animation: shimmer 2s infinite;
}

/* Skeleton variants */
.skeleton-text {
    height: 16px;
    width: 100%;
    margin-bottom: 8px;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.medium {
    width: 80%;
}

.skeleton-node {
    height: 60px;
    width: 200px;
    border-radius: 8px;
    border: 2px solid #4b5563;
}

.skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* =====================================================================
   WORKFLOW CANVAS SKELETON
   ===================================================================== */
.workflow-skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
}

.workflow-skeleton-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.workflow-skeleton-nodes {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Skeleton node with shimmer */
.skeleton-workflow-node {
    width: 160px;
    height: 56px;
    background: #374151;
    border: 2px dashed #4b5563;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.skeleton-workflow-node::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.06),
        transparent
    );
    animation: shimmer 2.5s infinite;
}

/* Stagger animation for multiple nodes */
.skeleton-workflow-node:nth-child(2)::after {
    animation-delay: 0.3s;
}

.skeleton-workflow-node:nth-child(3)::after {
    animation-delay: 0.6s;
}

/* Skeleton connector line (vertical, pointing down) */
.skeleton-connector {
    width: 2px;
    height: 24px;
    background: #4b5563;
    position: relative;
}

.skeleton-connector::after {
    content: "";
    position: absolute;
    left: -3px;
    bottom: -6px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 8px solid #4b5563;
    border-bottom: none;
}

/* Skeleton text label */
.skeleton-label {
    margin-top: 16px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

/* =====================================================================
   EXISTING NODE SHIMMER (modify/rebuild mode)
   Applied to X6 graph nodes when modifying an existing workflow
   ===================================================================== */
@keyframes node-rebuild-shimmer {
    0%, 100% {
        filter: brightness(1) drop-shadow(0 0 0px transparent);
    }
    50% {
        filter: brightness(1.2) drop-shadow(0 0 10px rgba(99, 102, 241, 0.35));
    }
}

.x6-node.rebuilding {
    animation: node-rebuild-shimmer 2s ease-in-out infinite;
}

.x6-node.rebuilding:nth-child(2) {
    animation-delay: 0.3s;
}

.x6-node.rebuilding:nth-child(3) {
    animation-delay: 0.6s;
}

.x6-node.rebuilding:nth-child(4) {
    animation-delay: 0.9s;
}

/* Edge shimmer during rebuild */
.x6-edge.rebuilding path {
    animation: edge-rebuild-shimmer 2s ease-in-out infinite;
}

@keyframes edge-rebuild-shimmer {
    0%, 100% {
        stroke-opacity: 1;
    }
    50% {
        stroke-opacity: 0.4;
    }
}

/* =====================================================================
   BUTTON LOADING STATE
   ===================================================================== */
.button-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: button-spin 0.8s linear infinite;
}

@keyframes button-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Button loading state - clean spinner with stable dimensions */
button.btn-loading {
    cursor: wait;
    pointer-events: none;
    position: relative;
    /* Disable size transitions during loading to prevent jitter */
    transition: background-color 0.15s ease, opacity 0.15s ease !important;
}

/* Hide text and icon but keep them in layout flow (for non-build buttons) */
button.btn-loading:not(.build-btn) .btn-text,
button.btn-loading:not(.build-btn) .btn-icon,
button.btn-loading .kbd-hint {
    opacity: 0;
    transition: opacity 0.1s ease;
}

/* Center spinner in non-build buttons */
button.btn-loading:not(.build-btn)::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: white;
    border-radius: 50%;
    animation: button-spin 0.7s linear infinite;
}

/* Build button loading: replace icon with inline spinner, keep text visible */
.build-btn.btn-loading .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0; /* hide emoji text */
}

.build-btn.btn-loading .btn-icon::after {
    content: "";
    display: block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: button-spin 0.7s linear infinite;
}

.build-btn.btn-loading .btn-text {
    opacity: 1;
}

/* Ensure common buttons have relative positioning for spinner compatibility */
.chat-btn,
.build-btn,
.workflow-btn {
    position: relative;
    /* Ensure dimensions are stable */
    box-sizing: border-box;
}

/* =====================================================================
   REDUCED MOTION SUPPORT
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    .skeleton::after {
        animation: none;
        background: rgba(255, 255, 255, 0.05);
    }

    .generation-progress-bar-fill::after {
        animation: none;
    }

    .generation-phase.active .phase-icon::before {
        animation: none;
    }

    /* Disable the phase background pulse animation */
    .generation-phase.active::after {
        animation: none;
        background: rgba(59, 130, 246, 0.1);
    }

    /* Disable long-phase robot pulse */
    .generation-phase.long-phase .phase-icon::before {
        animation: none;
    }

    /* Simplify message fade-in */
    .building-status-message.fade-in {
        animation: none;
    }

    .button-spinner,
    button.btn-loading::after {
        animation-duration: 1.5s;
    }

    /* Disable pulse glow animation for reduced motion */
    .build-btn.btn-loading {
        animation: none;
    }

    .skeleton-workflow-node::after {
        animation: none;
        background: rgba(255, 255, 255, 0.03);
    }

    /* Disable rebuild shimmer on nodes and edges */
    .x6-node.rebuilding {
        animation: none;
        filter: none;
    }

    .x6-edge.rebuilding path {
        animation: none;
        stroke-opacity: 1;
    }

    @keyframes progress-fade-in {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    @keyframes progress-fade-out {
        from { opacity: 1; }
        to { opacity: 0; }
    }
}

/* =====================================================================
   MOBILE RESPONSIVE
   ===================================================================== */
@media (max-width: 640px) {
    .generation-progress {
        margin: 12px;
        padding: 16px;
    }

    .generation-phases {
        gap: 8px;
    }

    .generation-phase {
        padding: 6px 10px;
    }

    .phase-label {
        font-size: 13px;
    }

    /* Skeleton already vertical; no overrides needed */

    /* Rich details responsive */
    .progress-rich-detail {
        padding: 10px 12px;
        gap: 8px;
    }

    .detail-chips {
        gap: 4px;
    }

    .detail-chip {
        padding: 3px 8px;
        font-size: 11px;
    }

    /* Building status responsive */
    .building-status-container {
        padding: 12px 16px;
        margin: 12px 0;
    }

    .building-status-message {
        font-size: 14px;
    }

    .building-progress-detail {
        flex-wrap: wrap;
        gap: 4px;
    }

    .progress-hint {
        width: 100%;
        margin-top: 4px;
    }
}
