/* Chat Widget Styles */

/* Soporte para viewport dinámico en móviles */
@supports (height: 100dvh) {
    @media (max-width: 480px) {
        .k3bone-chat-container {
            height: 100dvh !important;
        }
    }
}

.k3bone-chat-widget {
    --primary-color: #02538d;
    --primary-dark: #02538d;
    --surface: rgba(15, 23, 42, 0.95);
    --surface-light: rgba(15, 23, 42, 0.8);
    --border: rgba(148, 163, 184, 0.25);
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --bg: #0f172a;
    --success: #10b981;
    --error: #ef4444;
    --shadow: 0 25px 50px -12px rgba(74, 115, 133, 0.35);
    --border-radius: 16px;
    --font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.k3bone-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 24px;
    color: white;
}

.k3bone-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 30px 60px -12px rgba(74, 115, 133, 0.5);
}

.k3bone-chat-toggle.active {
    background: var(--error);
}

.k3bone-chat-toggle svg {
    width: 28px;
    height: 28px;
}

.k3bone-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 650px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 100px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 9999;
    display: none;
    flex-direction: column;
    backdrop-filter: blur(16px);
    font-family: var(--font-family);
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: all 0.3s ease;
}

.k3bone-chat-container.fullscreen {
    top: 20px;
    bottom: 20px;
    left: 20px;
    right: 20px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: var(--border-radius);
}

.k3bone-chat-container.open {
    display: flex;
    animation: chatOpen 0.3s ease forwards;
}

.k3bone-chat-container.closing {
    animation: chatClose 0.3s ease forwards;
}

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

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

.k3bone-chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    position: relative;
    z-index: 10000;
}

.k3bone-chat-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.k3bone-chat-header-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.k3bone-chat-close,
.k3bone-chat-fullscreen {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.k3bone-chat-close:hover,
.k3bone-chat-fullscreen:hover {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text);
}

.k3bone-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

.k3bone-chat-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 1rem;
}

.k3bone-chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

.k3bone-chat-bubble.assistant {
    align-self: flex-start;
    background: rgba(159, 159, 159, 0.2);
    border: 1px solid rgba(212, 212, 212, 0.3);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.k3bone-chat-form {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.k3bone-chat-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.k3bone-chat-input-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.k3bone-chat-message-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.k3bone-chat-input,
.k3bone-chat-textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-light);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.k3bone-chat-input {
    padding: 0.6rem 0.8rem;
}

.k3bone-chat-input:focus,
.k3bone-chat-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 115, 133, 0.2);
}

.k3bone-chat-textarea {
    resize: none;
    min-height: 44px;
    height: 44px;
    max-height: 120px;
    flex: 1;
    overflow-y: hidden;
    line-height: 1.4;
    box-sizing: border-box;
    padding: 0.6rem 0.8rem;
}

.k3bone-chat-button {
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
}

.k3bone-chat-button svg {
    width: 20px;
    height: 20px;
}

.k3bone-chat-button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 115, 133, 0.096);
}

.k3bone-chat-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.k3bone-chat-status {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    min-height: 1rem;
}

.k3bone-chat-typing {
    display: none;
    align-self: flex-start;
    padding: 0.75rem 1rem;
    background: rgba(159, 159, 159, 0.2);
    border: 1px solid rgba(212, 212, 212, 0.3);
    border-radius: 18px;
    color: var(--text);
    font-size: 1rem;
    margin: 0 1rem 0.75rem 1rem;
    max-width: calc(80% - 2rem);
    line-height: 1.5;
    border-bottom-left-radius: 4px;
}

.k3bone-chat-typing.show {
    display: block;
}

.k3bone-chat-typing::after {
    content: '';
    animation: typing 1.5s infinite;
}

@keyframes typing {
    0%, 60%, 100% {
        content: '';
    }
    30% {
        content: '.';
    }
}

/* Mobile responsive */
@media (max-width: 480px) {
    .k3bone-chat-container {
        width: 100vw;
        width: 100dvw;
        height: 100vh;
        height: 100dvh;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: none;
        max-height: none;
        border-radius: 0;
        border: none;
        z-index: 9999;
        position: fixed;
    }

    .k3bone-chat-container.fullscreen {
        top: 0;
        left: 0;
        border-radius: 0;
    }

    .k3bone-chat-toggle {
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
        z-index: 9998;
    }

    .k3bone-chat-fullscreen {
        display: none;
    }

    /* Ajuste para cuando aparece el teclado virtual */
    .k3bone-chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .k3bone-chat-form {
        flex-shrink: 0;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: light) {
    .k3bone-chat-widget {
        --bg: #ffffff;
        --surface: rgba(255, 255, 255, 0.95);
        --surface-light: rgba(255, 255, 255, 0.9);
        --border: rgba(0, 0, 0, 0.1);
        --text: #1f2937;
        --text-secondary: #6b7280;
    }
}