/* Soporte Visionwin - Estilos principales */

:root {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-panel: #ffffff;
    --bg-card: #f9fafb;
    --bg-user-msg: #0084ff;
    --bg-assistant-msg: #f0f0f0;
    --text-primary: #1c1e21;
    --text-secondary: #65676b;
    --text-muted: #8a8d91;
    --text-on-primary: #ffffff;
    --border-color: #e4e6eb;
    --border-light: #dadde1;
    --accent-primary: #0084ff;
    --accent-hover: #006bd6;
    --success: #42b72a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, .1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, .15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 1px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    box-sizing: border-box;
}

.wrap {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    height: calc(100vh - 28px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header de la aplicación */
.app-header {
    background: white;
    color: var(--text-primary);
    padding: 6px 16px;
    box-shadow: var(--shadow-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-header .logo {
    padding-top: 4px;
    padding-bottom: 4px;
    height: 42px;
}

/* Tarjeta principal del chat */
.card {
    flex: 1;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

/* Cabecera del chat */
.chat-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(66, 183, 42, .2);
}

.chat-header-info {
    flex: 1;
}

.chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-subtitle {
    margin: 1px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}

/* Banner informativo */
/* Botón de ayuda en header (mismo estilo que .close-btn) */
.help-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.12s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.help-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.help-btn:active {
    transform: scale(0.95);
}

/* Contenedor para los botones de la cabecera (ayuda y cerrar) */
.chat-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto; /* empuja los botones al extremo derecho */
}

/* Botón de cerrar: estilo más neutro pero visible */
.close-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.12s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.close-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.close-btn i { color: #c53030; }

/* Forzar SVGs dentro de los botones del header a usar stroke en lugar de fill
   así evitamos que iconos como 'info' aparezcan como círculos rellenos */
.chat-header-actions button svg {
    fill: none !important;
    stroke: currentColor !important;
}

.chat-header-actions .close-btn svg {
    stroke: #c53030 !important;
}

.help-icon {
    font-size: 16px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Tooltip de ayuda */
.help-tooltip {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fbbf24;
    border-left: 4px solid #f59e0b;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 0 16px 12px 16px;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.3s ease-out;
    position: relative;
}

.help-tooltip.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.help-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.help-tooltip-header strong {
    color: #92400e;
    font-size: 13px;
}

.close-help {
    background: transparent;
    border: none;
    color: #92400e;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.close-help:hover {
    background: rgba(146, 64, 14, 0.1);
    opacity: 1;
}

.help-list {
    margin: 0;
    padding-left: 20px;
    color: #78350f;
}

.help-list li {
    font-size: 12px;
    line-height: 1.6;
    margin-bottom: 6px;
}

.help-list li:last-child {
    margin-bottom: 0;
}

.help-list li strong {
    color: #92400e;
    font-weight: 600;
}

/* Área de mensajes */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--bg-card);
    scroll-behavior: smooth;
}

/* Scrollbar personalizado */
.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mensajes */
.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
    animation: fadeIn .2s ease-in-out;
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    position: relative;
}

.message.user .message-content {
    background: var(--bg-user-msg);
    color: var(--text-on-primary);
    border-radius: 18px 18px 4px 18px;
}

.message.assistant .message-content {
    background: var(--bg-assistant-msg);
    color: var(--text-primary);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid var(--border-color);
}

.message-text {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.4;
    font-size: 14px;
}

.message-time {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
}

.message.user .message-time {
    color: rgba(255, 255, 255, 0.8);
}

.message.assistant .message-time {
    color: var(--text-muted);
    text-align: left;
}

/* Imágenes en mensajes */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    display: block;
    object-fit: contain;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

.image-info {
    font-size: 11px;
    opacity: 0.7;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.image-info svg {
    width: 12px;
    height: 12px;
}

/* Estado de escritura */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
    border: 1px solid #93c5fd;
    border-left: 3px solid #3b82f6;
    border-radius: var(--radius-sm);
    margin: 0 16px 12px 16px;
    box-shadow: var(--shadow-sm);
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator::before {
    content: '⏳';
    font-size: 16px;
}

.typing-indicator::after {
    content: 'Procesando tu consulta, esto puede tomar unos momentos...';
    font-size: 12px;
    color: #1e40af;
    font-weight: 500;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #3b82f6;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: .2s;
}

.typing-dot:nth-child(3) {
    animation-delay: .4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: .4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Formulario de entrada */
.chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, .05);
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    min-height: 38px;
    max-height: 100px;
    resize: none;
    padding: 10px 12px 28px 12px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition: border-color .2s, box-shadow .2s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 132, 255, .1);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.char-counter {
    position: absolute;
    bottom: 6px;
    right: 12px;
    font-size: 11px;
    color: var(--text-muted);
    pointer-events: none;
}

.char-counter.warning {
    color: #f59e0b;
    font-weight: 600;
}

.char-counter.danger {
    color: #dc2626;
    font-weight: 700;
}

.send-button {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-xl);
    background: var(--accent-primary);
    color: white;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background .2s, transform .1s;
    white-space: nowrap;
    align-self: flex-end;
}

.send-button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.send-button:active:not(:disabled) {
    transform: scale(.96);
}

.send-button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Botón de adjuntar imagen */
.attach-btn {
    padding: 10px;
    border: none;
    border-radius: var(--radius-xl);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background .2s, color .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
}

.attach-btn:hover {
    background: var(--bg-hover);
    color: var(--accent-primary);
}

/* Vista previa compacta de imagen */
.image-preview-compact {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin-bottom: 8px;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-secondary);
}

.image-preview-compact i {
    color: var(--accent-primary);
}

.image-preview-compact span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-compact button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    color: var(--text-muted);
    transition: color .2s;
}

.image-preview-compact button:hover {
    color: var(--text-primary);
}

/* Mensaje de bienvenida */
.welcome-message {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary);
}

.welcome-message-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.welcome-message h2 {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.welcome-message p {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Preguntas rápidas */
.quick-replies {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    max-width: 90%;
    margin: 0 auto;
}

.quick-replies-title {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 8px;
    font-weight: 600;
}

.quick-reply-btn {
    padding: 10px 16px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: white;
    color: var(--accent-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all .2s;
    text-align: left;
}

.quick-reply-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: translateX(4px);
}

/* Acciones de mensaje */
.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-left: 0;
    opacity: 0;
    transition: opacity .2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: white;
    font-size: 12px;
    cursor: pointer;
    transition: all .2s;
    min-width: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover:not(:disabled) {
    background: var(--bg-card);
    transform: scale(1.05);
    border-color: var(--accent-primary);
}

.action-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Sección de Feedback Destacada */
.message.assistant .feedback-section {
    margin-top: 12px;
    margin-bottom: 0;
    margin-left: 0;
    padding: 16px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #bae6fd;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: fadeInSlide 0.4s ease-out;
    transition: all 0.3s ease;
    clear: both;
    width: auto;
    max-width: 500px;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-prompt {
    display: flex;
    align-items: center;
    gap: 12px;
}

.feedback-icon {
    font-size: 28px;
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.feedback-text {
    flex: 1;
}

.feedback-text strong {
    display: block;
    font-size: 15px;
    color: #0c4a6e;
    margin-bottom: 2px;
}

.feedback-text p {
    margin: 0;
    font-size: 13px;
    color: #075985;
}

.feedback-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.feedback-btn {
    flex: 1;
    max-width: 180px;
    padding: 12px 20px;
    border: 2px solid transparent;
    border-radius: 10px;
    background: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.feedback-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.feedback-btn:active:not(:disabled) {
    transform: translateY(0);
}

.feedback-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.feedback-btn-positive {
    color: #15803d;
    border-color: #86efac;
}

.feedback-btn-positive:hover:not(:disabled) {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border-color: #4ade80;
}

.feedback-btn-negative {
    color: #b91c1c;
    border-color: #fca5a5;
}

.feedback-btn-negative:hover:not(:disabled) {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: #f87171;
}

.feedback-btn i {
    width: 18px;
    height: 18px;
}

/* Enlaces en mensajes */
.message-link {
    color: var(--accent-primary);
    text-decoration: underline;
}

.message-link:hover {
    color: var(--accent-hover);
}

/* Sección de enlaces colapsable */
.links-section {
    margin-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.toggle-links-btn {
    background: linear-gradient(135deg, #e3f2ff 0%, #dbeafe 100%);
    color: #1e40af;
    border: 1px solid #93c5fd;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    max-height: 40px;
    box-sizing: border-box;
}

.toggle-links-btn:hover {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-color: #60a5fa;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.toggle-links-btn:active {
    transform: translateY(0);
}

.links-content {
    background: rgba(219, 234, 254, 0.3);
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.6;
}

.links-content strong {
    color: #1e40af;
    display: block;
    margin-bottom: 8px;
}

/* Markdown en mensajes */
.message-text strong {
    font-weight: 600;
}

.message-text code {
    background: rgba(0, 0, 0, .05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.message-text ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
}

/* Botón de scroll al fondo */
.scroll-bottom-btn {
    position: absolute;
    bottom: 80px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent-primary);
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: all .3s;
    z-index: 10;
}

.scroll-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-bottom-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

/* Botón limpiar chat */
.clear-btn {
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    background: white;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    transition: all .2s;
}

.clear-btn:hover {
    background: #fee;
    color: #ef4444;
    border-color: #ef4444;
}

/* Posición relativa para el contenedor de la tarjeta */
.card {
    flex: 1;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

/* Responsive - para ventanas muy pequeñas */
@media (max-width: 450px) {
    .app-header {
        padding: 4px 12px;
    }
    
    .app-header .logo {
        height: 22px;
    }

    .chat-container {
        padding: 12px;
    }

    .message-content {
        max-width: 85%;
    }

    .chat-form {
        padding: 10px;
    }

    /* Botón de ayuda en móvil */
    .help-btn {
        width: 32px;
        height: 32px;
    }

    .help-icon {
        font-size: 18px;
    }

    /* Tooltip de ayuda en móvil */
    .help-tooltip {
        padding: 12px;
        font-size: 12px;
        margin: 0 12px 12px 12px;
    }

    .help-tooltip-header strong {
        font-size: 12px;
    }

    .help-list li {
        font-size: 11px;
        margin-bottom: 5px;
    }

    /* Contador de caracteres en móvil */
    .char-counter {
        font-size: 10px;
        bottom: 6px;
        right: 8px;
        padding: 2px 6px;
    }

    .chat-input {
        padding: 10px 10px 24px 10px;
        font-size: 14px;
    }

    /* Feedback en móvil */
    .feedback-section {
        padding: 12px;
    }

    .feedback-prompt {
        gap: 10px;
    }

    .feedback-icon {
        font-size: 24px;
    }

    .feedback-text strong {
        font-size: 14px;
    }

    .feedback-text p {
        font-size: 12px;
    }

    .feedback-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .feedback-btn {
        max-width: 100%;
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* Para escritorio - limitar ancho */
@media (min-width: 768px) {
    .wrap {
        max-width: 500px;
        margin: 0 auto;
        box-shadow: 0 0 30px rgba(0, 0, 0, .1);
    }
}

@media (min-width: 1024px) {
    .wrap {
        max-width: 600px;
    }
}

/* Para modo widget embebido */
@media (max-height: 600px) {
    .chat-container {
        padding: 12px;
    }

    .welcome-message {
        padding: 20px;
    }
}
