/**
 * Frontend-Styles für JetChat Widget
 */

/* CSS-Variablen (werden von PHP überschrieben) */
:root {
    --jetchat-primary: #6366f1;
    --jetchat-primary-hover: #4f46e5;
    --jetchat-primary-light: #e0e7ff;

    --jetchat-white: #ffffff;
    --jetchat-gray-50: #f9fafb;
    --jetchat-gray-100: #f3f4f6;
    --jetchat-gray-200: #e5e7eb;
    --jetchat-gray-300: #d1d5db;
    --jetchat-gray-600: #4b5563;
    --jetchat-gray-800: #1f2937;
    --jetchat-gray-900: #111827;

    --jetchat-widget-width: 380px;
    --jetchat-widget-height: 600px;
    --jetchat-toggle-size: 60px;
    --jetchat-border-radius: 16px;
    --jetchat-spacing: 16px;

    --jetchat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --jetchat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --jetchat-z-index: 999999;

    --jetchat-maximized-width: 90vw;
    --jetchat-maximized-height: 90vh;
    --jetchat-maximized-max-width: 1200px;
    --jetchat-maximized-max-height: 900px;
}

/* Container */
#jetchat-container {
    position: fixed;
    z-index: var(--jetchat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

#jetchat-container * {
    box-sizing: border-box;
}

/* Positionierung */
.jetchat-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.jetchat-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Toggle Button */
.jetchat-toggle {
    width: var(--jetchat-toggle-size);
    height: var(--jetchat-toggle-size);
    border-radius: 50%;
    background: var(--jetchat-primary);
    color: var(--jetchat-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--jetchat-shadow);
    transition: all var(--jetchat-transition);
    position: relative;
}

.jetchat-toggle:hover {
    background: var(--jetchat-primary-hover);
    transform: scale(1.05);
}

.jetchat-toggle:active {
    transform: scale(0.95);
}

.jetchat-toggle .jetchat-icon-chat,
.jetchat-toggle .jetchat-icon-close {
    position: absolute;
    transition: all var(--jetchat-transition);
}

.jetchat-toggle .jetchat-icon-close {
    opacity: 0;
    transform: rotate(90deg);
}

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

.jetchat-toggle.jetchat-open .jetchat-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Chat Window */
.jetchat-window {
    position: fixed;
    width: var(--jetchat-widget-width);
    height: var(--jetchat-widget-height);
    max-height: calc(100vh - 100px);
    background: var(--jetchat-white);
    border-radius: var(--jetchat-border-radius);
    box-shadow: var(--jetchat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.jetchat-window:not(.jetchat-open) {
    display: none;
}

.jetchat-position-bottom-right .jetchat-window {
    bottom: 90px;
    right: 20px;
}

.jetchat-position-bottom-left .jetchat-window {
    bottom: 90px;
    left: 20px;
}

/* Header */
.jetchat-header {
    background: var(--jetchat-primary);
    color: var(--jetchat-white);
    padding: var(--jetchat-spacing);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--jetchat-border-radius) var(--jetchat-border-radius) 0 0;
}

.jetchat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.jetchat-avatar,
.jetchat-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.jetchat-avatar-placeholder {
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.jetchat-bot-name {
    font-weight: 600;
    font-size: 15px;
}

.jetchat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.jetchat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--jetchat-gray-300);
    transition: background var(--jetchat-transition);
}

.jetchat-status.status-online .jetchat-status-dot {
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.jetchat-status.status-offline .jetchat-status-dot {
    background: #ef4444;
}

.jetchat-status.status-checking .jetchat-status-dot {
    background: #f59e0b;
}

/* Header Controls */
.jetchat-header-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.jetchat-new-chat,
.jetchat-maximize,
.jetchat-minimize {
    background: transparent;
    border: none;
    color: var(--jetchat-white);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background var(--jetchat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.jetchat-new-chat:hover,
.jetchat-maximize:hover,
.jetchat-minimize:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Maximized State */
.jetchat-window.jetchat-maximized {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%);
    width: var(--jetchat-maximized-width);
    height: var(--jetchat-maximized-height);
    max-width: var(--jetchat-maximized-max-width);
    max-height: var(--jetchat-maximized-max-height);
    z-index: calc(var(--jetchat-z-index) + 2);
}

.jetchat-window.jetchat-maximized .jetchat-icon-maximize {
    display: none;
}

.jetchat-window.jetchat-maximized .jetchat-icon-restore {
    display: block !important;
}

/* Backdrop */
.jetchat-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--jetchat-z-index) + 1);
    backdrop-filter: blur(4px);
}

/* Confirmation Dialog */
.jetchat-confirm-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--jetchat-white);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: calc(var(--jetchat-z-index) + 10);
    max-width: 400px;
    width: calc(100% - 40px);
}

.jetchat-confirm-content {
    padding: 24px;
}

.jetchat-confirm-content h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    color: var(--jetchat-gray-900);
}

.jetchat-confirm-content p {
    margin: 0 0 20px 0;
    color: var(--jetchat-gray-600);
    line-height: 1.6;
}

.jetchat-confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.jetchat-confirm-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--jetchat-transition);
}

.jetchat-confirm-cancel {
    background: var(--jetchat-gray-200);
    color: var(--jetchat-gray-800);
}

.jetchat-confirm-cancel:hover {
    background: var(--jetchat-gray-300);
}

.jetchat-confirm-ok {
    background: var(--jetchat-primary);
    color: var(--jetchat-white);
}

.jetchat-confirm-ok:hover {
    background: var(--jetchat-primary-hover);
}

/* Messages Container */
.jetchat-messages {
    flex: 1 1 auto;
    min-height: 0;  /* KRITISCH für Flex Overflow! */
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--jetchat-spacing);
    background: var(--jetchat-gray-50);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--jetchat-gray-400) var(--jetchat-gray-100);
}

.jetchat-messages::-webkit-scrollbar {
    width: 8px;
}

.jetchat-messages::-webkit-scrollbar-track {
    background: var(--jetchat-gray-100);
    border-radius: 4px;
}

.jetchat-messages::-webkit-scrollbar-thumb {
    background: var(--jetchat-gray-400);
    border-radius: 4px;
}

.jetchat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--jetchat-gray-600);
}

/* Message */
.jetchat-message {
    display: flex;
    gap: 8px;
    animation: jetchat-message-in 0.3s ease;
}

@keyframes jetchat-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.jetchat-message-user {
    justify-content: flex-end;
}

.jetchat-message-bot {
    justify-content: flex-start;
}

.jetchat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.jetchat-message-avatar.jetchat-avatar-placeholder {
    background: var(--jetchat-gray-300);
}

.jetchat-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 75%;
}

.jetchat-message-user .jetchat-message-content {
    align-items: flex-end;
}

.jetchat-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
}

.jetchat-message-bot .jetchat-message-bubble {
    background: var(--jetchat-white);
    color: var(--jetchat-gray-900);
    border: 1px solid var(--jetchat-gray-200);
}

.jetchat-message-user .jetchat-message-bubble {
    background: var(--jetchat-primary);
    color: var(--jetchat-white);
}

.jetchat-message-time {
    font-size: 11px;
    color: var(--jetchat-gray-600);
    padding: 0 6px;
}

/* Typing Indicator */
.jetchat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.jetchat-typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--jetchat-gray-300);
    flex-shrink: 0;
}

.jetchat-typing-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.jetchat-typing-dots {
    background: var(--jetchat-gray-100);
    border: 1px solid var(--jetchat-gray-200);
    padding: 10px 14px;
    border-radius: 16px;
    display: flex;
    gap: 4px;
}

.jetchat-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--jetchat-gray-600);
    animation: jetchat-typing-bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes jetchat-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.jetchat-input-area {
    flex-shrink: 0;  /* Niemals schrumpfen! */
    padding: var(--jetchat-spacing);
    background: var(--jetchat-white);
    border-top: 1px solid var(--jetchat-gray-200);
    display: flex;
    gap: 8px;
}

.jetchat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--jetchat-gray-300);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--jetchat-transition);
}

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

.jetchat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--jetchat-primary);
    color: var(--jetchat-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--jetchat-transition);
    flex-shrink: 0;
}

.jetchat-send:hover {
    background: var(--jetchat-primary-hover);
    transform: scale(1.05);
}

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

.jetchat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #jetchat-container {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
    }

    .jetchat-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 64px;
        height: 64px;
    }

    .jetchat-window {
        position: fixed;
        width: 100% !important;
        /* dvh passt sich dynamisch an - perfekt für Mobile! */
        height: 100vh !important;  /* Fallback für ältere Browser */
        height: 100dvh !important; /* Dynamic Viewport Height - moderne Browser */
        min-height: 100dvh !important; /* Chrome/Opera fix */
        max-height: 100dvh !important; /* Chrome/Opera fix */
        border-radius: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
    }

    .jetchat-header {
        border-radius: 0 !important;
        padding-top: calc(var(--jetchat-spacing) + env(safe-area-inset-top, 0px));
    }

    .jetchat-header-controls button {
        padding: 12px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Maximize-Button auf Mobile ausblenden */
    .jetchat-maximize {
        display: none !important;
    }

    .jetchat-input {
        font-size: 16px;  /* Verhindert iOS Zoom */
        padding: 12px 16px;
        min-height: 44px;
    }

    .jetchat-send {
        width: 48px;
        height: 48px;
    }

    .jetchat-input-area {
        /* Stelle sicher dass Input immer sichtbar bleibt */
        position: relative;
        z-index: 10;
        flex-shrink: 0; /* Verhindert dass Input schrumpft */
        padding: var(--jetchat-spacing);
        padding-bottom: calc(var(--jetchat-spacing) + env(safe-area-inset-bottom, 0px)); /* iOS Safe Area */
        background: var(--jetchat-white);
        border-top: 1px solid var(--jetchat-gray-200);
    }

    .jetchat-messages {
        padding: 16px;
        /* Stelle sicher dass Messages Area flexibel ist */
        flex: 1 1 auto;
        min-height: 0; /* Wichtig für Flex Shrinking */
        padding-bottom: 8px;
    }

    .jetchat-message-bubble {
        padding: 12px 16px;
        font-size: 15px;
    }

    .jetchat-message-content {
        max-width: 85%;
    }

    /* Maximiert = Normal auf Mobile */
    .jetchat-window.jetchat-maximized {
        width: 100% !important;
        height: 100vh !important;  /* Fallback */
        height: 100dvh !important; /* Dynamic */
        transform: none;
        top: 0 !important;
        left: 0 !important;
    }

    .jetchat-backdrop {
        display: none !important;
    }
}

@media (max-width: 768px) and (min-width: 481px) {
    .jetchat-window {
        width: calc(100vw - 40px);
        max-width: 400px;
    }
}

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

/* Focus Styles */
.jetchat-toggle:focus,
.jetchat-minimize:focus,
.jetchat-send:focus,
.jetchat-input:focus {
    outline: 2px solid var(--jetchat-primary);
    outline-offset: 2px;
}

/* Print */
@media print {
    #jetchat-container {
        display: none !important;
    }
}

/* Font Awesome Icon Sizing */
.jetchat-toggle i {
    font-size: 24px;
}

.jetchat-header-controls i {
    font-size: 18px;
}

.jetchat-avatar-placeholder i {
    font-size: 20px;
    color: var(--jetchat-gray-600);
}

.jetchat-message-avatar.jetchat-avatar-placeholder i {
    font-size: 16px;
}

.jetchat-typing-avatar i {
    font-size: 16px;
    color: var(--jetchat-gray-600);
}

.jetchat-send i {
    font-size: 18px;
}
