/**
 * AI Assistant - Frontend Styles
 * Modern, premium AI Assistant UI design
 */

/* ========================================
   Variables & Reset
   ======================================== */
:root {
    --dd-primary: #2563eb;
    --dd-secondary: #1e293b;
    --dd-font-size: 14px;
    --dd-success: #10b981;
    --dd-danger: #ef4444;
    --dd-bg-light: #f8fafc;
    --dd-bg-dark: #1e293b;
    --dd-text-dark: #0f172a;
    --dd-text-light: #64748b;
    --dd-border: #e2e8f0;
    --dd-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    --dd-shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
    --dd-radius: 16px;
    --dd-radius-sm: 12px;
    --dd-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Container & Positioning
   ======================================== */
.dd-chatbot-container {
    position: fixed;
    z-index: 999999;
    font-family: var(--dd-font, inherit);
    font-size: var(--dd-font-size, 14px);
    line-height: 1.5;
    box-sizing: border-box;
}

.dd-chatbot-container *,
.dd-chatbot-container *::before,
.dd-chatbot-container *::after {
    box-sizing: border-box;
}

.dd-chatbot-container.bottom-right {
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(24px + env(safe-area-inset-right));
}

.dd-chatbot-container.bottom-left {
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: calc(24px + env(safe-area-inset-left));
}

.dd-chatbot-container.bottom-left .dd-chat-window {
    right: auto;
    left: 0;
}

/* ========================================
   Chat Button
   ======================================== */
.dd-chat-button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--dd-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--dd-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--dd-transition);
    position: relative;
    overflow: hidden;
    color: #fff;
}

.dd-chat-button.dd-chat-button-pill {
    width: auto;
    min-width: 60px;
    height: 56px;
    padding: 0 20px;
    border-radius: 999px;
    gap: 10px;
}

.dd-chat-button.dd-chat-button-pill.open {
    width: 56px;
    padding: 0;
}

.dd-chatbot-container .dd-chat-label {
    font-size: var(--dd-font-size, 14px) !important;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    line-height: 1.2 !important;
}

.dd-chat-button.open .dd-chat-label {
    display: none;
}

.dd-chat-button:hover {
    transform: scale(1.06);
    box-shadow: var(--dd-shadow-lg);
}

.dd-chat-button:active {
    transform: scale(0.95);
}

.dd-chat-button svg {
    width: 26px;
    height: 26px;
    color: white;
    flex-shrink: 0;
    transition: var(--dd-transition);
}

.dd-chat-button .dd-close-icon {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.dd-chat-button.open .dd-chat-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.dd-chat-button.open .dd-close-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* Pulse animation */
@keyframes dd-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 var(--dd-primary);
    }

    50% {
        box-shadow: 0 0 0 12px transparent;
    }
}

.dd-chat-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    animation: dd-pulse 2s infinite;
    pointer-events: none;
}

/* ========================================
   Chat Window
   ======================================== */
.dd-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 600px;
    max-height: calc(100dvh - 104px);
    background: white;
    border-radius: var(--dd-radius);
    box-shadow: var(--dd-shadow-lg);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--dd-transition);
    overflow: hidden;
}

.dd-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ========================================
   Chat Header
   ======================================== */
.dd-chat-header {
    background: var(--dd-primary);
    color: white;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-radius: var(--dd-radius) var(--dd-radius) 0 0;
}

.dd-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.dd-bot-avatar {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    backdrop-filter: blur(10px);
}

.dd-bot-avatar img,
.dd-message-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 50%;
}

.dd-chat-icon-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.dd-chatbot-container .dd-header-text h3 {
    margin: 0;
    font-size: calc(var(--dd-font-size, 14px) + 2px) !important;
    line-height: 1.25 !important;
    letter-spacing: normal !important;
    font-weight: 600;
    color: #fff;
}

.dd-chatbot-container .dd-status {
    font-size: calc(var(--dd-font-size, 14px) - 2px) !important;
    line-height: 1.2 !important;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dd-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--dd-success);
    border-radius: 50%;
    display: inline-block;
    animation: dd-pulse-status 2s infinite;
}

@keyframes dd-pulse-status {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.dd-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.dd-lang-switch {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}

.dd-chatbot-container .dd-lang-btn {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px !important;
    font-weight: 600;
    line-height: 1 !important;
    padding: 5px 8px;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--dd-transition);
}

.dd-lang-btn.active {
    background: #fff;
    color: var(--dd-primary);
}

.dd-lang-btn:hover:not(.active) {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
}

.dd-minimize-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--dd-transition);
}

.dd-minimize-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.dd-minimize-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.dd-chatbot-container .dd-preview-banner {
    background: #fef3c7;
    color: #92400e;
    border-bottom: 1px solid #fcd34d;
    padding: 6px 12px;
    font-size: 11px !important;
    font-weight: 600;
    text-align: center;
    line-height: 1.35 !important;
}

/* ========================================
   Messages Area
   ======================================== */
.dd-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--dd-bg-light);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

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

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

.dd-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--dd-secondary);
}

/* ========================================
   Message Bubbles
   ======================================== */
.dd-message {
    display: flex;
    gap: 12px;
    opacity: 0;
    transform: translateY(10px);
    transition: var(--dd-transition);
}

.dd-message.visible {
    opacity: 1;
    transform: translateY(0);
}

.dd-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.dd-chatbot-container .dd-message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--dd-radius-sm);
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.55 !important;
    word-wrap: break-word;
}

/* Bot messages */
.dd-message-bot .dd-message-avatar {
    background: var(--dd-primary);
}

.dd-message-bot .dd-message-content {
    background: white;
    color: var(--dd-text-dark);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.dd-chatbot-container .dd-message-bot .dd-message-content p,
.dd-chatbot-container .dd-message-bot .dd-message-content ul,
.dd-chatbot-container .dd-message-bot .dd-message-content ol,
.dd-chatbot-container .dd-message-bot .dd-message-content li,
.dd-chatbot-container .dd-message-bot .dd-message-content a,
.dd-chatbot-container .dd-message-bot .dd-message-content strong,
.dd-chatbot-container .dd-message-bot .dd-message-content b,
.dd-chatbot-container .dd-message-bot .dd-message-content em,
.dd-chatbot-container .dd-message-bot .dd-message-content i,
.dd-chatbot-container .dd-message-bot .dd-message-content blockquote,
.dd-chatbot-container .dd-message-bot .dd-message-content span {
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.55 !important;
}

.dd-chatbot-container .dd-message-content p {
    margin: 0 0 8px 0 !important;
}

.dd-chatbot-container .dd-message-content p:last-child {
    margin-bottom: 0 !important;
}

.dd-chatbot-container .dd-message-content ul,
.dd-chatbot-container .dd-message-content ol {
    margin: 6px 0 !important;
    padding-left: 18px !important;
}

.dd-chatbot-container .dd-message-content ul:last-child,
.dd-chatbot-container .dd-message-content ol:last-child {
    margin-bottom: 0 !important;
}

.dd-chatbot-container .dd-message-content code {
    font-size: calc(var(--dd-font-size, 14px) - 1px) !important;
}

/* User messages */
.dd-message-user {
    flex-direction: row-reverse;
}

.dd-message-user .dd-message-avatar {
    background: var(--dd-secondary);
}

.dd-message-user .dd-message-content {
    background: var(--dd-primary);
    color: white;
    margin-left: auto;
}

/* ========================================
   Typing Indicator
   ======================================== */
.dd-typing-indicator .dd-message-content {
    display: flex;
    gap: 6px;
    padding: 16px;
}

.dd-typing-indicator .dd-message-content span {
    width: 8px;
    height: 8px;
    background: var(--dd-secondary);
    border-radius: 50%;
    animation: dd-typing 1.4s infinite;
}

.dd-typing-indicator .dd-message-content span:nth-child(2) {
    animation-delay: 0.2s;
}

.dd-typing-indicator .dd-message-content span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dd-typing {

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

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========================================
   Input Area
   ======================================== */
.dd-chat-input-area {
    background: white;
    border-top: 1px solid var(--dd-border);
    padding: 16px;
}

.dd-input-wrapper {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.dd-chatbot-container .dd-chat-input {
    flex: 1;
    border: 2px solid var(--dd-border);
    border-radius: var(--dd-radius-sm);
    padding: 12px 16px;
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.4 !important;
    font-family: inherit;
    outline: none;
    transition: var(--dd-transition);
}

.dd-chat-input:focus {
    border-color: var(--dd-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.dd-send-btn {
    width: 44px;
    height: 44px;
    background: var(--dd-primary);
    border: none;
    border-radius: var(--dd-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--dd-transition);
    flex-shrink: 0;
}

.dd-send-btn:hover {
    filter: brightness(0.9);
    transform: scale(1.05);
}

.dd-send-btn:active {
    transform: scale(0.95);
}

.dd-send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.dd-chat-footer {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
}

.dd-chatbot-container .dd-privacy-note {
    text-align: center;
    font-size: 10.5px !important;
    line-height: 1.35 !important;
    color: var(--dd-text-light);
}

.dd-chatbot-container .dd-powered-by {
    text-align: center;
    font-size: 11px !important;
    line-height: 1.3 !important;
    color: var(--dd-text-light);
    margin-top: 2px;
}

.dd-starter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 48px;
}

.dd-chatbot-container .dd-starter-chip {
    background: #fff;
    color: var(--dd-primary);
    border: 1px solid var(--dd-border);
    border-radius: 999px;
    padding: 7px 13px;
    font-size: calc(var(--dd-font-size, 14px) - 1.5px) !important;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    line-height: 1.35 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: var(--dd-transition);
}

.dd-starter-chip:hover {
    border-color: var(--dd-primary);
    background: rgba(37, 99, 235, 0.06);
    transform: translateY(-1px);
}

.dd-debug-detail {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-word;
    margin-left: 48px;
}

/* ========================================
   Lead Form
   ======================================== */
.dd-lead-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.dd-chatbot-container .dd-form-input {
    border: 2px solid var(--dd-border);
    border-radius: var(--dd-radius-sm);
    padding: 12px 16px;
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.4 !important;
    font-family: inherit;
    outline: none;
    transition: var(--dd-transition);
    width: auto !important;
}

textarea.dd-form-input {
    height: 60px !important;
}

.dd-form-input:focus {
    border-color: var(--dd-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.dd-form-buttons {
    display: flex;
    gap: 8px;
}

.dd-chatbot-container .dd-form-skip {
    flex: 1;
    background: var(--dd-bg-light);
    color: var(--dd-text-dark);
    border: 2px solid var(--dd-border);
    border-radius: var(--dd-radius-sm);
    padding: 8px 12px;
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.4 !important;
    font-weight: 600;
    cursor: pointer;
    transition: var(--dd-transition);
}

.dd-form-skip:hover {
    background: var(--dd-border);
    border-color: var(--dd-secondary);
}

.dd-form-skip:active {
    transform: scale(0.98);
}

.dd-chatbot-container .dd-form-submit {
    flex: 1;
    background: var(--dd-primary);
    color: white;
    border: none;
    border-radius: var(--dd-radius-sm);
    padding: 12px 24px;
    font-size: var(--dd-font-size, 14px) !important;
    line-height: 1.4 !important;
    font-weight: 600;
    cursor: pointer;
    transition: var(--dd-transition);
}

.dd-form-submit:hover {
    filter: brightness(0.9);
    transform: translateY(-2px);
    box-shadow: var(--dd-shadow);
}

.dd-form-submit:active {
    transform: translateY(0);
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 480px) {
    .dd-chatbot-container {
        bottom: 0;
        right: 0;
        left: 0;
    }

    .dd-chat-button {
        position: fixed;
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
    }

    .dd-chatbot-container.bottom-left .dd-chat-button {
        right: auto;
        left: calc(16px + env(safe-area-inset-left));
    }

    .dd-chat-window {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
    }

    .dd-chat-window.open {
        transform: translateY(0);
    }

    .dd-chat-header {
        border-radius: 0;
    }

    .dd-chat-input-area {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* ========================================
   Human Takeover Contact Buttons
   ======================================== */
.dd-contact-options {
    padding: 12px !important;
    background: transparent !important;
    box-shadow: none !important;
}

.dd-contact-buttons {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 4px;
}

.dd-contact-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--dd-transition);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    text-decoration: none;
    border: none;
}

.dd-contact-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

.dd-contact-btn svg {
    width: 22px;
    height: 22px;
    color: white;
}

/* Tooltip implementation */
.dd-contact-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: var(--dd-secondary);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--dd-transition);
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.dd-contact-btn[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Specific button styles */
.dd-phone-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.dd-messenger-btn {
    background: linear-gradient(135deg, #0084ff 0%, #0066cc 100%);
}

.dd-viber-btn {
    background: linear-gradient(135deg, #7360f2 0%, #5929a1 100%);
}

.dd-resume-btn {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
}

/* Streaming Caret */
.dd-chatbot-container .dd-message-bot.dd-streaming .dd-message-content > *:last-child::after,
.dd-chatbot-container .dd-message-bot.dd-streaming .dd-message-content:empty::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 1.05em;
    margin-left: 3px;
    vertical-align: text-bottom;
    background: var(--dd-primary);
    border-radius: 1px;
    animation: ddStreamBlink 0.9s steps(2, start) infinite;
}

@keyframes ddStreamBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.15; }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .dd-chatbot-container,
    .dd-chatbot-container * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
.dd-chat-button:focus-visible,
.dd-send-btn:focus-visible,
.dd-minimize-btn:focus-visible,
.dd-lang-btn:focus-visible,
.dd-starter-chip:focus-visible {
    outline: 3px solid var(--dd-primary);
    outline-offset: 2px;
}