/* Damalion AI Chat Widget Styles */

:root {
    --damalion-primary: #FFC107;
    --damalion-secondary: #212121;
    --damalion-accent: #FF6F00;
    --damalion-bg: #FFFFFF;
    --damalion-text: #333333;
    --damalion-border: #e6e6e6;
    --damalion-hover: #FFA000;
}

/* Chat Widget Container */
.damalion-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Toggle Button */
.damalion-chat-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--damalion-primary), var(--damalion-accent));
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.damalion-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.damalion-chat-toggle .chat-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.damalion-chat-toggle .chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #4CAF50;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid white;
}

/* Chat Window */
.damalion-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    z-index: 10000;
}

.damalion-chat-window.open {
    display: flex;
}

/* Chat Header */
.damalion-chat-header {
    background: linear-gradient(135deg, var(--damalion-primary), var(--damalion-accent));
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.damalion-chat-header .header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.damalion-chat-header .header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: white;
    padding: 4px;
}

.damalion-chat-header .header-text {
    display: flex;
    flex-direction: column;
}

.damalion-chat-header .header-title {
    font-size: 16px;
    font-weight: 600;
}

.damalion-chat-header .header-status {
    font-size: 12px;
    opacity: 0.9;
}

.damalion-chat-header .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-selector {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.language-selector option {
    background: var(--damalion-secondary);
    color: white;
}

.minimize-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.minimize-btn .close-icon {
    display: none;
}

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

/* Messages Container */
.damalion-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
}

.damalion-chat-messages::-webkit-scrollbar {
    width: 12px; /* WIDER */
}

.damalion-chat-messages::-webkit-scrollbar-track {
    background: #e0e0e0; /* MORE VISIBLE */
    border-radius: 6px;
}

.damalion-chat-messages::-webkit-scrollbar-thumb {
    background: #FF6F00; /* ORANGE - VERY VISIBLE */
    border-radius: 6px;
    border: 2px solid #f8f9fa;
}

.damalion-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #E65100; /* DARKER ORANGE ON HOVER */
}

/* Chat Message */
.chat-message {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.chat-message.user .message-avatar {
    background: var(--damalion-primary);
    font-size: 18px;
}

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

.chat-message .message-content {
    flex: 1;
    min-width: 0;
}

.chat-message .message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-message .message-sender {
    font-weight: 600;
    font-size: 13px;
    color: var(--damalion-secondary);
}

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

.chat-message .message-text {
    background: white;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--damalion-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* TRULY INFINITE - NO LIMITS */
    max-height: unset !important;
    min-height: unset !important;
    height: auto !important;
    overflow: unset !important;
    overflow-y: unset !important;
    overflow-x: unset !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    display: block !important;
}

/* Force override any conflicting styles */
.chat-message .message-text * {
    max-height: unset !important;
    overflow: unset !important;
}

/* Make sure the message itself can expand */
.chat-message {
    max-height: unset !important;
    overflow: unset !important;
}

.chat-message .message-content {
    flex: 1;
    min-width: 0;
    max-height: unset !important;
    overflow: unset !important;
}
}

.chat-message .message-text::-webkit-scrollbar {
    width: 10px; /* Wider scrollbar */
}

.chat-message .message-text::-webkit-scrollbar-track {
    background: #e0e0e0; /* More visible track */
    border-radius: 5px;
    margin: 4px 0;
}

.chat-message .message-text::-webkit-scrollbar-thumb {
    background: #FF6F00; /* Orange - very visible */
    border-radius: 5px;
    border: 2px solid white;
}

.chat-message .message-text::-webkit-scrollbar-thumb:hover {
    background: #E65100; /* Darker orange on hover */
}

.chat-message.user .message-text {
    background: linear-gradient(135deg, var(--damalion-primary), var(--damalion-hover));
    color: white;
}

.chat-message.error .message-text {
    background: #ffebee;
    color: #c62828;
    border-left: 3px solid #c62828;
}

.chat-message.system .message-text {
    background: #e3f2fd;
    color: #1565c0;
    font-size: 13px;
    text-align: center;
}

/* Damalion Answer Formatting */
.damalion-answer {
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    line-height: 1.55;
    max-height: unset !important;
    overflow: unset !important;
}

.damalion-title {
    margin: 0 0 10px 0;
    font-size: 1.05rem;
}

.damalion-bullets {
    margin: 0;
    padding-left: 1.2rem;
}

.damalion-bullets li {
    margin: 12px 0;
    line-height: 1.6;
    padding: 4px 0;
}

.damalion-sources {
    margin: 12px 0 0 0;
    font-size: 0.95rem;
}

.damalion-sources a {
    text-decoration: underline;
    word-break: break-word;
    color: var(--damalion-accent);
}

.damalion-sources a:hover {
    color: var(--damalion-hover);
}

/* Typing Indicator */
.typing-indicator .typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px;
}

.typing-indicator .typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--damalion-primary);
    animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Container */
.damalion-chat-input-container {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid var(--damalion-border);
}

.damalion-chat-input {
    flex: 1;
    border: 1px solid var(--damalion-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    transition: border-color 0.2s;
}

.damalion-chat-input:focus {
    border-color: var(--damalion-primary);
}

.damalion-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--damalion-primary), var(--damalion-accent));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.damalion-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

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

/* Footer */
.damalion-chat-footer {
    padding: 8px 16px;
    text-align: center;
    font-size: 11px;
    color: #999;
    background: #f8f9fa;
    border-top: 1px solid var(--damalion-border);
}

.footer-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

/* =============================================
   RESPONSIVE: Tablets & small laptops
   ============================================= */
@media (max-width: 768px) {
    .damalion-chat-window {
        width: calc(100vw - 30px);
        right: 15px;
        bottom: 85px;
        height: calc(100vh - 110px);
        max-height: calc(100vh - 110px);
        border-radius: 12px;
    }
}

/* =============================================
   RESPONSIVE: Mobile phones (full screen takeover)
   ============================================= */
@media (max-width: 480px) {
    .damalion-chat-widget {
        bottom: 12px;
        right: 12px;
    }

    .damalion-chat-toggle {
        width: 56px;
        height: 56px;
    }

    .damalion-chat-toggle .chat-logo {
        width: 30px;
        height: 30px;
    }

    .damalion-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* dynamic viewport height — accounts for mobile browser chrome */
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        z-index: 10001;
    }

    .damalion-chat-header {
        border-radius: 0;
        padding: 10px 12px;
        /* Safe area for notch / status bar */
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .header-logo {
        width: 28px;
        height: 28px;
    }

    .header-title {
        font-size: 14px;
    }

    .header-status {
        font-size: 11px;
    }

    .language-selector {
        font-size: 12px;
        padding: 3px 4px;
        max-width: 90px;
    }

    .damalion-chat-messages {
        flex: 1;
        min-height: 0;
        padding: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .chat-message {
        max-width: 90%;
    }

    .message-text {
        font-size: 14px;
        line-height: 1.4;
    }

    .damalion-chat-input-container {
        padding: 8px 10px;
        /* Safe area for bottom home indicator */
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .damalion-chat-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .damalion-send-btn {
        width: 40px;
        height: 40px;
    }

    .damalion-chat-footer {
        padding: 6px;
        font-size: 10px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    /* On mobile: show X instead of minimize dash */
    .minimize-btn .minimize-icon {
        display: none;
    }
    .minimize-btn .close-icon {
        display: inline;
        font-size: 18px;
    }
    .minimize-btn {
        width: 38px;
        height: 38px;
        font-size: 20px;
    }
}

/* =============================================
   RESPONSIVE: Very small phones (iPhone SE, Galaxy S)
   ============================================= */
@media (max-width: 360px) {
    .damalion-chat-widget {
        bottom: 8px;
        right: 8px;
    }

    .damalion-chat-toggle {
        width: 50px;
        height: 50px;
    }

    .damalion-chat-toggle .chat-logo {
        width: 26px;
        height: 26px;
    }

    .header-title {
        font-size: 13px;
    }

    .language-selector {
        max-width: 70px;
        font-size: 11px;
    }

    .message-text {
        font-size: 13px;
    }
}

/* =============================================
   RESPONSIVE: Landscape mobile
   ============================================= */
@media (max-height: 500px) {
    .damalion-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .damalion-chat-header {
        padding: 6px 12px;
    }

    .damalion-chat-footer {
        padding: 4px;
    }
}
