/* ======================================
   ADVANCED MODERN CHAT INTERFACE
   Professional, sleek, and highly responsive
   ====================================== */

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --user-bubble: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --ai-bubble: #f8f9fa;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* ===== FLOATING TOGGLE BUTTON ===== */
#ddb-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--primary-gradient);
    color: #fff;
    padding: 14px 24px;
    border-radius: var(--radius-xl);
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
}

#ddb-chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.4);
}

#ddb-chat-toggle:active {
    transform: translateY(0);
}

/* ===== MAIN CHAT CONTAINER ===== */
#ddb-chat-container {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 420px;
    max-width: 420px;
    height: 600px;
    max-height: 600px;
    background: #ffffff;
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== EMBEDDED MODE ===== */
#ddb-chat-container.ddb-embedded {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    max-width: 900px;
    height: auto;
    min-height: 600px;
    max-height: 700px;
    border-radius: var(--radius-md);
    margin: 24px auto;
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== HEADER ===== */
#ddb-chat-header {
    padding: 20px 24px;
    background: var(--primary-gradient);
    color: #fff;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 18px;
    box-shadow: 0 2px 12px rgba(102, 126, 234, 0.2);
}

#ddb-chat-header::before {
    content: '💬';
    font-size: 24px;
    margin-right: 8px;
}

.ddb-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

#ddb-chat-clear {
    cursor: pointer;
    font-size: 20px;
    opacity: 0.9;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

#ddb-chat-clear:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(15deg);
}

#ddb-chat-close {
    cursor: pointer;
    font-size: 28px;
    font-weight: 300;
    opacity: 0.9;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

#ddb-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* ===== MESSAGES AREA ===== */
#ddb-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    background: linear-gradient(to bottom, #fafbfc 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

#ddb-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ddb-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#ddb-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

#ddb-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ===== MESSAGE BUBBLES ===== */
.ddb-message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ddb-message-wrapper.user {
    flex-direction: row-reverse;
}

.ddb-message-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.ddb-message-wrapper.ai .ddb-message-icon {
    background: var(--primary-gradient);
    color: white;
}

.ddb-message-wrapper.user .ddb-message-icon {
    background: var(--secondary-gradient);
    color: white;
}

.user-message, .bot-message {
    max-width: 75%;
    width: fit-content;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.bot-message {
    background: var(--ai-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.user-message {
    background: var(--user-bubble);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

/* ===== OPTIONS AREA ===== */
#ddb-chat-options {
    padding: 16px 20px;
    background: #fafbfc;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
}

.ddb-answer-btn {
    display: inline-block;
    width: auto;
    min-width: fit-content;
    max-width: 100%;
    padding: 10px 18px;
    background: #ffffff;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    cursor: pointer;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 13px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    position: relative;
    overflow: hidden;
    white-space: normal;
    line-height: 1.4;
}

.ddb-answer-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: var(--primary-gradient);
    transition: width 0.3s ease;
    z-index: 0;
}

.ddb-answer-btn:hover::before {
    width: 100%;
}

.ddb-answer-btn:hover {
    color: #ffffff;
    border-color: transparent;
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-md);
}

.ddb-answer-btn span {
    position: relative;
    z-index: 1;
}

.ddb-answer-btn.ddb-action-btn {
    background: var(--success-gradient);
    color: #ffffff;
    border-color: transparent;
    font-weight: 600;
    padding: 11px 20px;
    font-size: 13px;
}

.ddb-answer-btn.ddb-action-btn::before {
    background: linear-gradient(135deg, #00c6ff 0%, #0072ff 100%);
}

.ddb-answer-btn.ddb-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(79, 172, 254, 0.35);
}

/* ===== IMAGES AREA ===== */
#ddb-chat-images {
    padding: 16px 20px;
    background: #fafbfc;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: flex-start;
}

.ddb-image-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #ffffff;
    border: 2px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 120px;
    min-width: 100px;
}

.ddb-image-option:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.ddb-image-option img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
}

.ddb-image-label {
    padding: 8px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    color: var(--text-primary);
    background: #f8f9fa;
    width: 100%;
    border-top: 1px solid var(--border-color);
}

/* ===== INPUT ROW ===== */
#ddb-chat-input-row {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
}

#ddb-chat-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    transition: all 0.2s ease;
    background: #fafbfc;
}

#ddb-chat-input:focus {
    outline: none;
    border-color: #667eea;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#ddb-chat-send {
    padding: 14px 24px;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

#ddb-chat-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35);
}

#ddb-chat-send:active {
    transform: translateY(0);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet landscape */
    #ddb-chat-container {
        width: 400px;
        max-width: 400px;
    }

    #ddb-chat-container.ddb-embedded {
        max-width: 800px;
    }
}

@media (max-width: 768px) {
    #ddb-chat-toggle {
        bottom: 16px;
        right: 16px;
        padding: 12px 20px;
        font-size: 14px;
    }

    #ddb-chat-container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    #ddb-chat-header {
        border-radius: 0;
        padding: 18px 20px;
    }

    .user-message, .bot-message {
        max-width: 85%;
        font-size: 14px;
    }

    #ddb-chat-options {
        padding: 12px 16px;
        flex-direction: column;
        align-items: stretch;
    }

    .ddb-answer-btn {
        width: 100%;
        padding: 10px 16px;
        font-size: 13px;
    }

    .ddb-answer-btn.ddb-action-btn {
        padding: 11px 18px;
    }

    #ddb-chat-input-row {
        padding: 16px;
    }

    #ddb-chat-input, #ddb-chat-send {
        font-size: 14px;
    }

    /* Summary responsive adjustments */
    .ddb-summary-item {
        flex-direction: column;
        gap: 6px;
    }

    .ddb-summary-label {
        min-width: auto;
        font-size: 12px;
    }

    .ddb-summary-value {
        font-size: 13px;
    }

    /* Structured summary responsive */
    .ddb-summary-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px 14px;
    }

    .bot-message.ddb-structured-summary {
        max-width: 95%;
    }

    .ddb-summary-card .ddb-summary-header {
        padding: 14px 16px;
    }

    .ddb-summary-title {
        font-size: 15px;
    }

    .ddb-summary-items {
        padding: 16px;
        gap: 10px;
    }
}

@media (max-width: 480px) {
    .ddb-message-icon {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .user-message, .bot-message {
        padding: 10px 14px;
        font-size: 13px;
    }

    #ddb-chat-container.ddb-embedded {
        min-height: 500px;
        max-height: 600px;
        margin: 16px;
    }

    #ddb-chat-messages {
        padding: 16px;
        gap: 12px;
    }

    #ddb-chat-options {
        padding: 10px 12px;
        gap: 8px;
    }

    .ddb-answer-btn {
        padding: 9px 14px;
        font-size: 12px;
    }

    .ddb-answer-btn.ddb-action-btn {
        padding: 10px 16px;
        font-size: 12px;
    }

    .bot-message.ddb-summary {
        padding: 16px;
    }

    .ddb-summary-header::before {
        font-size: 20px;
    }

    .ddb-summary-header h4 {
        font-size: 14px;
    }

    /* Structured summary mobile */
    .ddb-summary-icon {
        font-size: 24px;
    }

    .ddb-summary-row {
        padding: 10px 12px;
    }

    .ddb-summary-row .ddb-summary-label {
        font-size: 11px;
    }

    .ddb-summary-row .ddb-summary-value {
        font-size: 13px;
    }

    .ddb-summary-items {
        padding: 12px;
        gap: 8px;
    }
}

/* ===== EMBEDDED SPECIFIC ===== */
#ddb-chat-container.ddb-embedded #ddb-chat-header {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

#ddb-chat-container.ddb-embedded {
    box-shadow: var(--shadow-md);
}

/* ===== TYPING INDICATOR ===== */
.ddb-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    background: var(--ai-bubble);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    width: fit-content;
    border: 1px solid var(--border-color);
}

.ddb-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #a0aec0;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.ddb-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.ddb-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ddb-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* ===== SUMMARY SECTION STYLING ===== */
.bot-message.ddb-summary {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border: 2px solid var(--border-color);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.ddb-summary-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.ddb-summary-header::before {
    content: '📋';
    font-size: 24px;
}

.ddb-summary-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.ddb-summary-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    padding: 10px;
    background: #ffffff;
    border-radius: var(--radius-sm);
    border-left: 3px solid #667eea;
}

.ddb-summary-item:last-child {
    margin-bottom: 0;
}

.ddb-summary-label {
    font-weight: 600;
    color: #667eea;
    min-width: 120px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ddb-summary-value {
    flex: 1;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

.ddb-summary-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

/* Enhanced bot message for multi-line content */
.bot-message br {
    margin: 4px 0;
    display: block;
    content: "";
}

.bot-message strong {
    color: #667eea;
    font-weight: 600;
    display: block;
    margin-top: 8px;
    margin-bottom: 4px;
}

.bot-message ul,
.bot-message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bot-message li {
    margin: 4px 0;
    line-height: 1.6;
}

/* ===== STRUCTURED SUMMARY CARD ===== */
.bot-message.ddb-structured-summary {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    max-width: 90%;
}

.ddb-summary-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafb 100%);
    border: 2px solid #e8eef3;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.08);
    transition: all 0.3s ease;
}

.ddb-summary-card:hover {
    box-shadow: 0 6px 28px rgba(102, 126, 234, 0.12);
    transform: translateY(-2px);
}

.ddb-summary-card .ddb-summary-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    margin: 0;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ddb-summary-card .ddb-summary-header::before {
    content: none;
}

.ddb-summary-icon {
    font-size: 28px;
    line-height: 1;
    animation: bounceIn 0.6s ease;
}

@keyframes bounceIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.ddb-summary-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: white;
    flex: 1;
}

.ddb-summary-items {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ddb-summary-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    padding: 14px 16px;
    background: white;
    border-radius: var(--radius-sm);
    border-left: 4px solid #667eea;
    transition: all 0.2s ease;
    animation: slideInRow 0.4s ease;
}

@keyframes slideInRow {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.ddb-summary-row:hover {
    background: #fafbfc;
    border-left-color: #764ba2;
    transform: translateX(4px);
}

.ddb-summary-row .ddb-summary-label {
    font-weight: 700;
    color: #667eea;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    line-height: 1.4;
    min-width: 0;
}

.ddb-summary-row .ddb-summary-value {
    color: #2d3748;
    font-size: 14px;
    line-height: 1.6;
    font-weight: 500;
    word-break: break-word;
}

/* Summary wrapper specific styles */
.ddb-message-wrapper.ddb-summary-wrapper {
    align-items: flex-start;
}

.ddb-summary-wrapper .ddb-message-icon {
    margin-top: 4px;
}

/* ===== SUMMARY FOOTER / CONFIRMATION NOTE ===== */
.ddb-summary-footer {
    padding: 14px 20px 18px 20px;
    background: transparent;
    border-top: 1px solid #eef3f6;
}

.ddb-summary-note {
    color: #4a5568; /* text-secondary */
    font-size: 13px;
    line-height: 1.5;
    background: #ffffff;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #eef3f6;
    box-shadow: 0 2px 8px rgba(16,24,40,0.04);
}

@media (max-width: 768px) {
    .ddb-summary-note {
        font-size: 13px;
        padding: 10px 12px;
    }
    .ddb-summary-row {
        grid-template-columns: 1fr;
    }
}