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

:root {
    --primary-red: #b8333a;
    --primary-red-hover: #972a30;
    --primary-red-light: rgba(184, 51, 58, 0.1);
    --primary-red-glow: rgba(184, 51, 58, 0.2);
    --background-primary: #0a0a0a;
    --background-secondary: #1a1a1a;
    --surface-primary: rgba(255, 255, 255, 0.05);
    --surface-secondary: rgba(255, 255, 255, 0.08);
    --surface-tertiary: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-tertiary: #a0a0a0;
    --border-subtle: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.2);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 8px 40px rgba(0, 0, 0, 0.4);
    --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.5);
    --gradient-primary: linear-gradient(135deg, var(--primary-red), #d4414a);
    --gradient-surface: linear-gradient(135deg, var(--surface-primary), var(--surface-secondary));
    --gradient-bg: linear-gradient(135deg, var(--background-primary), var(--background-secondary));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--gradient-bg);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 20%, rgba(184, 51, 58, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(184, 51, 58, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    background: var(--surface-primary);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-strong);
    overflow: hidden;
    position: relative;
    animation: slideIn 0.6s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-subtle);
    background: var(--gradient-surface);
    position: relative;
}

.chat-container h1 {
    background: var(--gradient-primary);
    color: var(--text-primary);
    padding: 24px;
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.3px;
    position: relative;
    box-shadow: 0 2px 20px var(--primary-red-glow);
}

.chat-history {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background: var(--surface-primary);
}

.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

.message {
    padding: 18px 24px;
    border-radius: 20px;
    max-width: 85%;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    animation: messageSlide 0.4s ease-out;
    backdrop-filter: blur(10px);
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bot-message {
    background: var(--surface-secondary);
    border: 1px solid var(--border-subtle);
    align-self: flex-start;
    color: var(--text-secondary);
}

.bot-message:hover {
    background: var(--surface-tertiary);
    border-color: var(--border-medium);
    transform: translateY(-2px);
}

.user-message {
    background: var(--gradient-primary);
    color: var(--text-primary);
    align-self: flex-end;
    box-shadow: 0 4px 20px var(--primary-red-glow);
}

.user-message:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--primary-red-glow);
}

/* Animaciones de carga */
.loading-message {
    background: var(--surface-secondary);
    border: 1px solid var(--border-subtle);
    align-self: flex-start;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.loading-message::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(184, 51, 58, 0.1), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-subtle);
    border-top: 2px solid var(--primary-red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
.dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.progress-bar {
    width: 100%;
    height: 3px;
    background: var(--surface-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 2px;
    animation: progressLoad 3s ease-out;
}

@keyframes progressLoad {
    0% {
        width: 0%;
    }
    20% {
        width: 15%;
    }
    40% {
        width: 30%;
    }
    60% {
        width: 60%;
    }
    80% {
        width: 85%;
    }
    100% {
        width: 100%;
    }
}

.loading-text {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-tertiary);
}

.loading-stages {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: 8px;
}

.stage {
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.stage.active {
    opacity: 1;
    color: var(--primary-red);
}

.stage.complete {
    opacity: 0.7;
    color: var(--text-secondary);
}

.chat-input-container {
    display: flex;
    padding: 24px;
    gap: 16px;
    background: var(--surface-secondary);
    border-top: 1px solid var(--border-subtle);
    position: relative;
}

#chat-input {
    flex: 1;
    padding: 16px 20px;
    background: var(--surface-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    backdrop-filter: blur(10px);
}

#chat-input::placeholder {
    color: var(--text-tertiary);
}

#chat-input:focus {
    border-color: var(--primary-red);
    box-shadow: 0 0 0 3px var(--primary-red-light);
    background: var(--surface-secondary);
}

#send-button {
    padding: 16px 24px;
    background: var(--gradient-primary);
    color: var(--text-primary);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px var(--primary-red-glow);
}

#send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--primary-red-glow);
}

.output-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-primary);
}

.output-container h2 {
    padding: 24px;
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

#json-output {
    flex: 1;
    background: var(--background-secondary);
    color: var(--text-secondary);
    padding: 32px;
    margin: 0;
    white-space: pre-wrap;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    border-radius: 0 0 24px 0;
    position: relative;
}

#json-output::-webkit-scrollbar {
    width: 6px;
}

#json-output::-webkit-scrollbar-track {
    background: transparent;
}

#json-output::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

.json-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex-direction: column;
    gap: 16px;
}

.json-loading .loading-spinner {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

.pulse-animation {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 var(--primary-red-glow);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(184, 51, 58, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(184, 51, 58, 0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        width: 98%;
        height: 98vh;
    }
    
    .chat-container {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }
    
    .message {
        max-width: 95%;
    }
    
    .chat-history {
        padding: 16px;
    }
    
    .chat-input-container {
        padding: 16px;
    }
}

/* ============================================= */
/* == NUEVOS ESTILOS PARA LA VISTA VISUAL == */
/* ============================================= */

/* Contenedores y Controles de la Salida */
.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.output-header h2 {
    border-bottom: none;
    padding: 24px 0;
    font-size: 20px; /* Ajustado para coincidir con el h2 original */
    font-weight: 600;
    color: var(--text-secondary);
}

.output-controls button {
    background: var(--surface-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 14px;
}

.output-controls button:hover {
    background: var(--primary-red);
    color: var(--text-primary);
    border-color: var(--primary-red);
}

.filters-container {
    display: flex;
    gap: 16px;
    padding: 16px 24px;
    background: var(--background-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.filters-container input,
.filters-container select {
    flex: 1;
    background: var(--surface-primary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
}

#fullscreen-diagram-btn {
    background: var(--gradient-primary);
    color: var(--text-primary);
    border: none;
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--primary-red-glow);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 8px;
    display: none;
}

#fullscreen-diagram-btn:hover {
    background: var(--primary-red-hover);
    color: #fff;
    box-shadow: 0 4px 20px var(--primary-red-glow);
    transform: translateY(-2px);
}

.filters-container input:focus,
.filters-container select:focus {
    border-color: var(--primary-red);
    box-shadow: 0 0 0 3px var(--primary-red-light);
}

#step-count {
    color: var(--text-tertiary);
    white-space: nowrap;
    align-self: center;
    font-family: 'JetBrains Mono', monospace;
}

/* Utilidad para ocultar vistas */
.hidden {
    display: none !important;
}

/* Contenedor principal de la vista de tarjetas */
#step-by-step-view {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    background: var(--background-secondary);
    /* Se ajusta al espacio restante en el contenedor */
    height: calc(100% - 134px); 
}

/* Estilos para el diagrama de flujo */
#diagram-view {
    background: var(--background-secondary);
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fullscreen-diagram {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999;
    background: var(--background-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

#diagram-view.fullscreen-diagram #diagram-svg {
    width: 100vw !important;
    height: 100vh !important;
    min-width: 100vw;
    min-height: 100vh;
    background: var(--background-secondary);
}


#diagram-svg {
    width: 100%;
    height: 100%;
    background: var(--background-secondary);
}

.node-diagram rect {
    fill: #222 !important;
    stroke: var(--primary-red) !important;
    stroke-width: 2px;
}
.node-diagram text {
    fill: #fff !important;
    font-family: 'Inter', 'JetBrains Mono', monospace;
    font-size: 15px;
}
.edgePath path {
    stroke: var(--primary-red) !important;
    stroke-width: 2px;
}
.edgeLabel text {
    fill: #fff !important;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
}

#step-by-step-view::-webkit-scrollbar {
    width: 6px;
}
#step-by-step-view::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

/* Estilo de la Tarjeta de Nodo */
.node-card {
    background: var(--surface-secondary);
    border: 1px solid var(--border-subtle);
    border-left-width: 4px;
    border-radius: 12px;
    margin-bottom: 24px;
    padding: 20px;
    transition: all 0.3s ease;
    animation: messageSlide 0.4s ease-out; /* Reutilizamos tu animaciÃ³n */
}

.node-card:hover {
    border-color: var(--primary-red-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
}

.node-type-badge {
    font-family: 'JetBrains Mono', monospace;
    font-weight: bold;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #fff;
    text-transform: uppercase;
}

/* Colores por tipo de nodo (puedes aÃ±adir mÃ¡s) */
[data-nodetype="greeting"] { border-left-color: #2ecc71; }
[data-nodetype="greeting"] .node-type-badge { background-color: #2ecc71; }

[data-nodetype="question"] { border-left-color: #f1c40f; }
[data-nodetype="question"] .node-type-badge { background-color: #f1c40f; color: #333; }

[data-nodetype="response"] { border-left-color: #3498db; }
[data-nodetype="response"] .node-type-badge { background-color: #3498db; }

[data-nodetype="transfer"] { border-left-color: #9b59b6; }
[data-nodetype="transfer"] .node-type-badge { background-color: #9b59b6; }

[data-nodetype="farewell"] { border-left-color: #e74c3c; }
[data-nodetype="farewell"] .node-type-badge { background-color: #e74c3c; }

/* Contenido de la tarjeta */
.card-body > div:not(:last-child) {
    margin-bottom: 15px;
}

.message-box {
    font-style: italic;
    color: var(--text-secondary);
    background: var(--surface-primary);
    padding: 15px;
    border-radius: 8px;
    line-height: 1.6;
}

.details-box {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-subtle);
    padding: 15px;
    border-radius: 8px;
}

.box-title {
    margin: 0 0 10px 0;
    font-weight: 500;
    color: var(--text-tertiary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--primary-red-light);
    color: var(--primary-red);
    padding: 3px 6px;
    border-radius: 5px;
    font-size: 0.9rem;
}

.connections-list {
    list-style: none;
    padding-left: 0;
}

.connection-line {
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
}

/* Mini etiquetas para razonamiento y tipo de operación en el chat */
.bot-badges {
    margin-bottom: 6px;
}
.badge {
    display: inline-block;
    padding: 18px 24px;
    margin-bottom: 10px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    backdrop-filter: blur(10px);
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

}
.razon-badge {
    background: #222;
    color: #fff;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    margin-right: 8px;

}

.badge.badge-op {
    background: var(--primary-red);
    color: #fff;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;

}

.ai-warning {
    width: 100%;
    text-align: center;
    font-size: 14px;
    color: var(--text-tertiary);
    background: var(--primary-red-light);
    border-radius: 8px;
    padding: 8px 0;
    font-weight: 500;
    letter-spacing: 0.1px;
}