/* ============================================================
   AI Execution Dialog — Generic reusable component
   Used across the project for any AI/LLM operation.
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
    --aid-bg: linear-gradient(135deg, #1e1e2e 0%, #2a2a3e 100%);
    --aid-border: rgba(255, 255, 255, 0.1);
    --aid-text: #e0e0e0;
    --aid-text-muted: rgba(255, 255, 255, 0.45);
    --aid-accent: #00d4ff;
    --aid-accent-purple: #a855f7;
    --aid-code-bg: rgba(0, 0, 0, 0.35);
    --aid-success: #34d399;
    --aid-error: #f87171;
    --aid-warning: #fbbf24;
}

/* ========================================
   MODAL SHELL
   ======================================== */

.aid-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
}

.aid-modal.active {
    display: flex;
}

.aid-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
}

.aid-modal-container {
    position: relative;
    background: var(--aid-bg);
    border: 1px solid var(--aid-border);
    border-radius: 16px;
    width: 92%;
    max-width: 800px;
    max-height: 88vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ========================================
   HEADER
   ======================================== */

.aid-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--aid-border);
    flex-shrink: 0;
}

.aid-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.aid-title {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.aid-model-badge {
    display: none; /* hidden for now — model shown here was a guessed client-side literal, not the model actually used. Re-enable once the real model is reported back from execution. */
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--aid-accent);
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.25);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.aid-timer {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--aid-text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
    min-width: 3.5rem;
    text-align: right;
}

.aid-timer.running {
    color: var(--aid-accent);
}

.aid-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.4rem;
    margin-left: 0.75rem;
    transition: color 0.2s;
    line-height: 1;
}

.aid-close-btn:hover {
    color: #fff;
}

/* ========================================
   BODY — scrollable area for steps
   ======================================== */

.aid-body {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* ========================================
   PRODUCTION MODE (showPromptsAndAnswer = false)
   Simple centered spinner + status
   ======================================== */

.aid-simple-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1rem;
    gap: 1.25rem;
    text-align: center;
}

.aid-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--aid-accent);
    border-radius: 50%;
    animation: aid-spin 0.8s linear infinite;
}

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

.aid-simple-status {
    font-size: 0.95rem;
    color: var(--aid-text);
}

.aid-simple-substatus {
    font-size: 0.8rem;
    color: var(--aid-text-muted);
    margin-top: -0.5rem;
}

/* ========================================
   DEBUG MODE (showPromptsAndAnswer = true)
   Step-by-step prompt/response view
   ======================================== */

.aid-steps {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.aid-step {
    border: 1px solid var(--aid-border);
    border-radius: 10px;
    overflow: hidden;
}

.aid-step.active {
    border-color: rgba(0, 212, 255, 0.3);
}

.aid-step.done {
    border-color: rgba(52, 211, 153, 0.3);
}

.aid-step.error {
    border-color: rgba(248, 113, 113, 0.3);
}

/* Step header */
.aid-step-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--aid-border);
    cursor: pointer;
    user-select: none;
}

.aid-step-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.aid-step-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--aid-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.aid-step-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    flex-shrink: 0;
}

.aid-step.active .aid-step-icon {
    background: rgba(0, 212, 255, 0.15);
    border: 2px solid var(--aid-accent);
    animation: aid-pulse 1.5s ease infinite;
}

.aid-step.done .aid-step-icon {
    background: rgba(52, 211, 153, 0.2);
    color: var(--aid-success);
}

.aid-step.done .aid-step-icon::after {
    content: '✓';
}

.aid-step.error .aid-step-icon {
    background: rgba(248, 113, 113, 0.2);
    color: var(--aid-error);
}

.aid-step.error .aid-step-icon::after {
    content: '✗';
}

@keyframes aid-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(0, 212, 255, 0); }
}

.aid-step-time {
    font-size: 0.7rem;
    color: var(--aid-text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Step body — collapsible */
.aid-step-body {
    display: none;
    padding: 0.75rem 1rem;
}

.aid-step.active .aid-step-body,
.aid-step.done .aid-step-body,
.aid-step.error .aid-step-body {
    display: block;
}

/* Code blocks for prompt / response */
.aid-code-section {
    margin-bottom: 0.75rem;
}

.aid-code-section:last-child {
    margin-bottom: 0;
}

.aid-code-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}

.aid-code-label span {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--aid-text-muted);
}

.aid-copy-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--aid-text-muted);
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.aid-copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--aid-text);
}

.aid-copy-btn.copied {
    color: var(--aid-success);
    border-color: rgba(52, 211, 153, 0.3);
}

.aid-btn-copy-all {
    background: rgba(0, 212, 255, 0.08);
    border: 1px solid rgba(0, 212, 255, 0.2);
    color: var(--aid-accent);
}

.aid-btn-copy-all:hover {
    background: rgba(0, 212, 255, 0.15);
    border-color: rgba(0, 212, 255, 0.4);
}

.aid-btn-copy-all.copied {
    color: var(--aid-success);
    border-color: rgba(52, 211, 153, 0.3);
    background: rgba(52, 211, 153, 0.08);
}

.aid-code-block {
        background: var(--aid-code-bg);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--aid-text);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 250px;
    overflow-y: auto;
}

.aid-code-block.prompt {
    border-left: 3px solid rgba(0, 212, 255, 0.4);
}

.aid-code-block.response {
    border-left: 3px solid rgba(52, 211, 153, 0.4);
}

.aid-code-block.error-text {
    border-left: 3px solid rgba(248, 113, 113, 0.4);
    color: var(--aid-error);
}

/* Waiting indicator inside step */
.aid-step-waiting {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--aid-text-muted);
    font-size: 0.8rem;
    padding: 0.25rem 0;
}

.aid-step-waiting .aid-mini-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--aid-accent);
    border-radius: 50%;
    animation: aid-spin 0.8s linear infinite;
}

/* ========================================
   FOOTER
   ======================================== */

.aid-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--aid-border);
    flex-shrink: 0;
}

.aid-footer-status {
    font-size: 0.75rem;
    color: var(--aid-text-muted);
}

.aid-footer-status.success {
    color: var(--aid-success);
}

.aid-footer-status.error {
    color: var(--aid-error);
}

.aid-footer-actions {
    display: flex;
    gap: 0.5rem;
}

.aid-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.aid-btn-primary {
    background: linear-gradient(135deg, var(--aid-accent), var(--aid-accent-purple));
    color: #fff;
}

.aid-btn-primary:hover {
    filter: brightness(1.1);
}

.aid-btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--aid-text);
}

.aid-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.aid-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .aid-modal-container {
        width: 97%;
        max-height: 92vh;
        border-radius: 12px;
    }

    .aid-header {
        padding: 0.75rem 1rem;
    }

    .aid-body {
        padding: 0.75rem 1rem;
    }

    .aid-code-block {
        max-height: 180px;
        font-size: 0.65rem;
    }

    .aid-model-badge {
        display: none;
    }
}
