/**
 * KokoAI - Diagrams Styles
 * Beautiful styles for diagram containers with API-generated images
 */

/* ============================================
   DIAGRAM WRAPPER & CONTAINER
   ============================================ */

.diagram-wrapper {
    margin: 1rem 0;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.2s ease;
    position: relative;
    max-width: 100%;
}

.diagram-wrapper:hover {
    border-color: var(--accent-primary);
}

/* Header - More subtle, integrated */
.diagram-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border-bottom: 1px solid var(--border-color);
}

.diagram-type-badge {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.6rem;
    background: #f1f5f9; /* Slate 100 */
    color: #475569;      /* Slate 600 */
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    text-transform: uppercase;
}

.diagram-controls {
    display: flex;
    gap: 0.35rem;
}

.diagram-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.diagram-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border-color: var(--border-color);
}

.diagram-btn.diagram-edit {
    color: var(--accent-secondary);
}

.diagram-btn.diagram-edit:hover {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.2);
}

.diagram-btn svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   DIAGRAM CONTENT
   ============================================ */

.diagram-content {
    padding: 0.75rem 1rem;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
}

/* ============================================
   DIAGRAM IMAGE (from API)
   ============================================ */

.diagram-image {
    max-width: 100%;
    max-height: 450px;
    width: auto;
    height: auto;
    border-radius: 4px;
    background: #ffffff;
}

.diagram-image:hover {
    transform: scale(1.02);
}

.diagram-wrapper:fullscreen .diagram-image {
    max-height: 80vh;
}

/* ============================================
   MERMAID CONTAINER (client-side rendering)
   ============================================ */

.mermaid-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.mermaid-container svg {
    max-width: 90%;
    max-height: 50vh;
    height: auto;
    border-radius: 4px;
}

/* Override Mermaid default colors for dark theme */
.mermaid-container .node rect,
.mermaid-container .node circle,
.mermaid-container .node polygon {
    stroke-width: 2px;
}

.mermaid-container .edgePath path {
    stroke-width: 2px;
}

.mermaid-container text {
    font-family: 'Inter', sans-serif !important;
}

/* ============================================
   LOADING STATE
   ============================================ */

.diagram-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: #94a3b8;
    font-size: 0.9rem;
}

.diagram-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: diagram-spin 0.8s linear infinite;
}

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

/* ============================================
   ERROR STATE
   ============================================ */

.diagram-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem;
    text-align: center;
    color: #94a3b8;
}

.diagram-error svg {
    width: 40px;
    height: 40px;
    color: #f59e0b;
}

.diagram-error span {
    font-size: 0.9rem;
}

.diagram-code {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: #94a3b8;
    max-width: 100%;
    overflow-x: auto;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ============================================
   DIAGRAM IN MESSAGE CONTEXT
   ============================================ */

.message-body .diagram-wrapper {
    margin: 1.25rem 0;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes diagram-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.diagram-wrapper {
    animation: diagram-fade-in 0.4s ease-out;
}

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

@media (max-width: 768px) {
    .diagram-header {
        padding: 0.6rem 0.75rem;
    }

    .diagram-type-badge {
        font-size: 0.6rem;
        padding: 0.3rem 0.6rem;
    }

    .diagram-btn {
        width: 30px;
        height: 30px;
    }

    .diagram-btn svg {
        width: 16px;
        height: 16px;
    }

    .diagram-content {
        padding: 1rem;
        min-height: 150px;
    }

    .diagram-image {
        max-height: 300px;
    }

    .diagram-wrapper {
        margin: 1rem 0;
    }
}

/* ============================================
   DARK MODE ENHANCEMENTS
   ============================================ */

@media (prefers-color-scheme: dark) {
    .diagram-wrapper {
        background: linear-gradient(135deg, rgba(15, 23, 42, 0.98) 0%, rgba(10, 15, 30, 0.99) 100%);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .diagram-wrapper {
        break-inside: avoid;
        border: 1px solid #ccc;
        box-shadow: none;
        background: #fff;
    }

    .diagram-header {
        background: #f5f5f5;
    }

    .diagram-controls {
        display: none;
    }

    .diagram-content {
        max-height: none;
        background: #fff;
    }

    .diagram-image {
        max-height: none;
        box-shadow: none;
    }
}