/**
 * AI Chat Widget Styles
 * Compatible with PrestaShop 1.6
 * @author EnfoquesTIC
 */

/* Widget Container */
#aichat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}


/* Toggle Button Container (título + botón) */
.aichat-toggle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aichat-toggle-container.aichat-loaded {
    opacity: 1;
}

/* Chat Toggle Button */
.aichat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #051D5B 0%, #041650 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 124, 186, 0.3);
    transition: all 0.3s ease;
    border: none;
    outline: none;
}

.aichat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 124, 186, 0.4);
}

.aichat-toggle:active {
    transform: translateY(0);
}

/* Badge */
.aichat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

/* Toggle Title */
.aichat-toggle-title {
    background: linear-gradient(135deg, #051D5B 0%, #041650 100%);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 124, 186, 0.3);
    transition: all 0.3s ease;
    pointer-events: none;
    /* display: none; Eliminado para que ocupe espacio */
    text-align: center;
    max-width: calc(100vw - 4em);
    opacity: 1;
    visibility: visible;
}

.aichat-toggle-title.aichat-title-hidden {
    opacity: 0;
    visibility: hidden;
    /* Mantiene espacio pero no es interactivo ni visible */
}

.aichat-toggle:hover~.aichat-toggle-title {
    box-shadow: 0 6px 25px rgba(0, 124, 186, 0.4);
}

/* Chat Window */
.aichat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 500px;
    max-width: calc(100vw - 40px);
    height: 600px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

/* Chat Header */
.aichat-header {
    background: linear-gradient(135deg, #051D5B 0%, #041650 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.aichat-header-content {
    display: flex;
    align-items: center;
    flex: 1;
}

.aichat-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.aichat-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}

.aichat-title h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    transition: opacity 0.2s ease;
}

.aichat-title {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.aichat-title:hover {
    opacity: 0.8;
}

.aichat-status {
    font-size: 12px;
    opacity: 0.8;
    display: block;
    margin-top: 2px;
}

/* Beta Badge */
.aichat-beta-badge {
    display: inline-block;
    background: #ffd93d;
    color: #2c2c2c;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    line-height: 1;
    animation: subtle-pulse 2s ease-in-out infinite;
}

@keyframes subtle-pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.85;
        transform: scale(1.02);
    }
}

.aichat-close,
.aichat-fullscreen,
.aichat-back-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.aichat-close:hover,
.aichat-fullscreen:hover,
.aichat-back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Messages Container */
.aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

.aichat-messages::-webkit-scrollbar {
    width: 4px;
}

.aichat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aichat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

.aichat-messages::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* Message */
.aichat-message {
    display: flex;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.aichat-message-user {
    flex-direction: row-reverse;
}

.aichat-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aichat-message-bot .aichat-message-avatar {
    background: #e3f2fd;
    margin-right: 8px;
}

.aichat-message-user .aichat-message-avatar {
    background: #051D5B;
    margin-left: 8px;
}

.aichat-message-user .aichat-message-avatar svg {
    fill: white;
}

.aichat-message-content {
    flex: 1;
    max-width: 80%;
}

.aichat-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.aichat-message-bot .aichat-message-bubble {
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.aichat-message-user .aichat-message-bubble {
    background: #051D5B;
    color: white;
    border-bottom-right-radius: 4px;
}

.aichat-message-time {
    margin-top: 4px;
    text-align: right;
}

.aichat-message-bot .aichat-message-time {
    text-align: left;
}

.aichat-time {
    font-size: 11px;
    color: #999;
}

/* Typing Indicator Container */
#aichat-typing {
    background: #f8f9fa;
    /* Mismo fondo que el chat */
    padding: 0 16px 16px 16px;
    /* Padding que conecta con el área de mensajes */
    margin: 0;
}

/* Typing Indicator */
.aichat-typing-bubble {
    background: #ffffff !important;
    border: 1px solid #e0e0e0 !important;
    padding: 16px !important;
}

/* Typing Message - Sin burbuja, integrado naturalmente */
.aichat-typing-message {
    background: #f8f9fa;
    /* Mismo fondo que el chat */
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
    width: calc(100% + 32px);
    box-sizing: border-box;
}

.aichat-typing-message .aichat-message-content {
    max-width: 100%;
    display: flex;
    align-items: center;
    padding: 8px 0;
    background: transparent;
}

.aichat-typing-message .aichat-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: transparent;
    border: none;
}

.aichat-typing-dots span {
    width: 6px;
    height: 6px;
    background: #051D5B;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.aichat-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.aichat-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.aichat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.aichat-form {
    margin: 0;
}

.aichat-input-wrapper {
    display: flex;
    align-items: center;
    background: #f5f5f5;
    border-radius: 24px;
    padding: 4px;
    transition: background-color 0.2s ease;
}

.aichat-input-wrapper:focus-within {
    background: #eeeeee;
}

.aichat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
}

.aichat-input::placeholder {
    color: #999;
}

.aichat-send {
    width: 40px;
    height: 40px;
    border: none;
    background: #051D5B;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.aichat-send:hover:not(:disabled) {
    background: #005a87;
    transform: scale(1.05);
}

.aichat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Footer */
.aichat-footer {
    padding: 8px 16px;
    background: #f8f9fa;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

.aichat-footer small {
    color: #999;
    font-size: 11px;
}

/* Responsive Design */
@media (max-width: 480px) {
    #aichat-widget {
        bottom: 10px;
        right: 10px;
    }

    .aichat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: -10px;
    }

    .aichat-toggle {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 320px) {
    .aichat-window {
        width: calc(100vw - 10px);
        right: -5px;
    }
}

/* Animation for window show/hide */
.aichat-window.aichat-show {
    display: flex !important;
    animation: slideUp 0.3s ease-out;
}

.aichat-window.aichat-hide {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* Focus states for accessibility */
.aichat-toggle:focus,
.aichat-close:focus,
.aichat-send:focus,
.aichat-back-btn:focus {
    outline: 2px solid #051D5B;
    outline-offset: 2px;
}

/* Input focus - sin outline visible */
.aichat-input:focus {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .aichat-message-bot .aichat-message-bubble {
        border: 2px solid #000;
    }

    .aichat-input-wrapper {
        border: 1px solid #000;
    }
}

/* Markdown Content Styles */
.aichat-message-bot .aichat-message-bubble h1,
.aichat-message-bot .aichat-message-bubble h2,
.aichat-message-bot .aichat-message-bubble h3 {
    margin: 0.5em 0 0.3em 0;
    font-weight: bold;
    line-height: 1.2;
}

.aichat-message-bot .aichat-message-bubble h1 {
    font-size: 1.2em;
    color: #051D5B;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.2em;
}

.aichat-message-bot .aichat-message-bubble h2 {
    font-size: 1.1em;
    color: #005a87;
}

.aichat-message-bot .aichat-message-bubble h3 {
    font-size: 1.05em;
    color: #333;
}

.aichat-message-bot .aichat-message-bubble p {
    margin: 0.5em 0;
    line-height: 1.4;
}

.aichat-message-bot .aichat-message-bubble ul {
    margin: 0.5em 0;
    padding-left: 1.2em;
}

.aichat-message-bot .aichat-message-bubble li {
    margin: 0.2em 0;
    line-height: 1.3;
}

.aichat-message-bot .aichat-message-bubble strong {
    font-weight: bold;
    color: #333;
}

.aichat-message-bot .aichat-message-bubble em {
    font-style: italic;
}

.aichat-message-bot .aichat-message-bubble hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 1em 0;
}

.aichat-message-bot .aichat-message-bubble br {
    line-height: 1.4;
}

/* Mejorar espaciado para listas anidadas */
.aichat-message-bot .aichat-message-bubble ul ul {
    margin: 0.2em 0;
    padding-left: 1em;
}

/* Estilo especial para códigos de productos */
.aichat-message-bot .aichat-message-bubble li:contains("Cód:") {
    font-family: monospace;
    background-color: #f8f9fa;
    padding: 0.1em 0.3em;
    border-radius: 3px;
}

/* Resize Handle */
.aichat-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: ne-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    transform: scaleX(-1);
    /* Voltear el triángulo horizontalmente */
}

.aichat-resize-handle:hover {
    opacity: 1;
}

/* Fullscreen Mode */
.aichat-window.aichat-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    z-index: 10000 !important;
}

.aichat-window.aichat-fullscreen .aichat-messages {
    max-height: calc(100vh - 140px) !important;
    height: calc(100vh - 140px) !important;
}

.aichat-window.aichat-fullscreen .aichat-input-area {
    position: relative !important;
    bottom: auto !important;
    background: white !important;
    border-top: 1px solid #e0e0e0 !important;
}

.aichat-window.aichat-fullscreen .aichat-message-user .aichat-message-bubble {
    background: #051D5B !important;
    color: white !important;
}

.aichat-window.aichat-fullscreen .aichat-message-bot .aichat-message-bubble {
    background: #ffffff !important;
    color: #333 !important;
    border: 1px solid #e0e0e0 !important;
}

/* Resizable Window */
.aichat-window.aichat-resizable {
    resize: none;
    min-width: 300px;
    min-height: 400px;
    max-width: 90vw;
    max-height: 90vh;
}

/* Progress Indicator */
.aichat-progress-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 10px 0;
    border-left: 4px solid #051D5B;
}

.aichat-progress-text {
    color: #051D5B;
    font-weight: 500;
    margin-right: 10px;
}

.aichat-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e3e3e3;
    border-top: 2px solid #051D5B;
    border-radius: 50%;
    animation: aichat-spin 1s linear infinite;
}

@keyframes aichat-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Timeout Warning */
.aichat-timeout-warning {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    color: #856404;
    padding: 10px 15px;
    margin: 10px 0;
    border-radius: 4px;
    font-size: 13px;
}

.aichat-timeout-warning .aichat-warning-icon {
    margin-right: 8px;
    font-weight: bold;
}

/* Category Selection Menu */
.aichat-categories {
    padding: 16px;
    background: #f8f9fa;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.aichat-categories-header {
    text-align: center;
    margin-bottom: 12px;
}

.aichat-categories-header h5 {
    margin: 0 0 6px 0;
    font-size: 16px;
    font-weight: 600;
    color: #051D5B;
}

.aichat-categories-header p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.aichat-categories-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.aichat-category-btn {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    text-align: left;
    width: 100%;
    font-family: inherit;
}

.aichat-category-btn:hover {
    border-color: #051D5B;
    background: #f0f7ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(5, 29, 91, 0.1);
}

.aichat-category-btn:active {
    transform: translateY(0);
}

.category-emoji {
    font-size: 22px;
    margin-right: 10px;
    line-height: 1;
}

.category-name {
    flex: 1;
    font-weight: 500;
    color: #333;
}

/* Toggle Bounce Animation */
.aichat-toggle-container.bounce {
    animation: bounce 0.75s ease;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    25%,
    75% {
        transform: translateY(-10px);
    }

    50% {
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 480px) {
    .aichat-categories {
        padding: 15px;
    }

    .aichat-category-btn {
        padding: 14px 16px;
    }

    .category-emoji {
        font-size: 24px;
    }
}