/**
 * OpenAI ChatKit Widget Styles v2.3
 * Mit Login-Pflicht und Tageslimit-Anzeige
 */

:root {
    --chatkit-primary: #0073aa;
    --chatkit-primary-hover: #005a87;
    --chatkit-bg: #ffffff;
    --chatkit-text: #333333;
    --chatkit-text-light: #666666;
    --chatkit-border: #e0e0e0;
    --chatkit-user-bg: var(--chatkit-primary);
    --chatkit-assistant-bg: #f5f5f5;
    --chatkit-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chatkit-radius: 12px;
}

/* ================== CHAT BUTTON ================== */
.chatkit-trigger-btn {
    background: var(--chatkit-primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 115, 170, 0.3);
}

.chatkit-trigger-btn:hover {
    background: var(--chatkit-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 115, 170, 0.4);
}

/* Bubble Mode */
.chatkit-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99998;
}

.chatkit-bubble .chatkit-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    padding: 0;
    font-size: 24px;
    justify-content: center;
}

/* ================== CHAT CONTAINER ================== */
.chatkit-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--chatkit-bg);
    border-radius: var(--chatkit-radius);
    box-shadow: var(--chatkit-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Popup Mode */
.chatkit-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chatkit-popup-overlay.active {
    display: flex;
    opacity: 1;
}

.chatkit-popup-overlay .chatkit-container {
    width: 100%;
    max-width: 500px;
    height: 80vh;
    max-height: 700px;
    animation: chatkit-slide-up 0.3s ease;
}

/* Inline Mode - 100% Breite */
.chatkit-inline {
    width: 100%;
    max-width: 100%;
}

.chatkit-inline .chatkit-container {
    width: 100%;
    max-width: 100%;
    min-height: 500px;
    height: auto;
    border: 1px solid var(--chatkit-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.chatkit-inline .chatkit-messages {
    min-height: 400px;
    max-height: none;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Standalone Mode */
.chatkit-standalone .chatkit-container {
    width: 100%;
    max-width: 900px;
    height: calc(100vh - 60px);
    margin: 20px auto;
}

@keyframes chatkit-slide-up {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ================== CHAT HEADER ================== */
.chatkit-header {
    background: var(--chatkit-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chatkit-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}

.chatkit-header-title::before {
    content: "🤖";
    font-size: 20px;
}

.chatkit-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chatkit-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ================== MESSAGES AREA ================== */
.chatkit-messages {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    min-height: 300px;
}

.chatkit-popup-overlay .chatkit-messages,
.chatkit-bubble-chat .chatkit-messages {
    max-height: calc(80vh - 200px);
    overflow-y: auto;
}

.chatkit-standalone .chatkit-messages {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Custom Scrollbar */
.chatkit-messages::-webkit-scrollbar {
    width: 8px;
}

.chatkit-messages::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.chatkit-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.chatkit-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.chatkit-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* ================== ACCESS MESSAGES (Login/Limit) ================== */
.chatkit-access-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    min-height: 300px;
}

.chatkit-access-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: chatkit-bounce 2s infinite;
}

@keyframes chatkit-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.chatkit-access-message h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    color: var(--chatkit-text);
}

.chatkit-access-message p {
    margin: 0 0 20px 0;
    color: var(--chatkit-text-light);
    font-size: 14px;
    line-height: 1.6;
}

.chatkit-login-btn {
    display: inline-block;
    background: var(--chatkit-primary);
    color: white;
    padding: 12px 30px;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
}

.chatkit-login-btn:hover {
    background: var(--chatkit-primary-hover);
    transform: translateY(-2px);
    color: white;
    text-decoration: none;
}

/* Limit Info Box */
.chatkit-limit-info {
    background: #f5f5f5;
    border-radius: 10px;
    padding: 15px 25px;
    margin-top: 10px;
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
}

.chatkit-limit-used {
    font-size: 32px;
    font-weight: 700;
    color: #e74c3c;
}

.chatkit-limit-separator {
    font-size: 24px;
    color: var(--chatkit-text-light);
}

.chatkit-limit-total {
    font-size: 32px;
    font-weight: 700;
    color: var(--chatkit-text);
}

.chatkit-limit-label {
    width: 100%;
    font-size: 12px;
    color: var(--chatkit-text-light);
    margin-top: 5px;
}

/* ================== LIMIT DISPLAY (im Chat) ================== */
.chatkit-limit-display {
    padding: 8px 20px;
    background: #f9f9f9;
    border-top: 1px solid var(--chatkit-border);
    font-size: 12px;
    color: var(--chatkit-text-light);
    text-align: center;
}

.chatkit-limit-display .chatkit-limit-warning {
    color: #e74c3c;
    font-weight: 500;
}

.chatkit-limit-display .chatkit-limit-unlimited {
    color: #27ae60;
}

/* ================== MESSAGE BUBBLES ================== */
.chatkit-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: chatkit-message-appear 0.3s ease;
}

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

.chatkit-message.user {
    align-self: flex-end;
}

.chatkit-message.assistant {
    align-self: flex-start;
}

.chatkit-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
}

.chatkit-message.user .chatkit-message-content {
    background: var(--chatkit-user-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatkit-message.assistant .chatkit-message-content {
    background: var(--chatkit-assistant-bg);
    color: var(--chatkit-text);
    border-bottom-left-radius: 4px;
}

/* Markdown Styling */
.chatkit-message-content p {
    margin: 0 0 10px 0;
}

.chatkit-message-content p:last-child {
    margin-bottom: 0;
}

.chatkit-message-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SF Mono", Monaco, "Consolas", monospace;
    font-size: 13px;
}

.chatkit-message.user .chatkit-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.chatkit-message-content pre {
    background: #1e1e1e;
    color: #f8f8f2;
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
}

.chatkit-message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.chatkit-message-content a {
    color: var(--chatkit-primary);
    text-decoration: underline;
}

.chatkit-message.user .chatkit-message-content a {
    color: #fff;
}

/* Citations */
.chatkit-citations {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
}

.chatkit-citation {
    display: inline-block;
    background: rgba(0, 115, 170, 0.1);
    color: var(--chatkit-primary);
    padding: 3px 10px;
    border-radius: 4px;
    margin: 3px 4px 3px 0;
    text-decoration: none;
    font-size: 11px;
}

.chatkit-citation:hover {
    background: rgba(0, 115, 170, 0.2);
    text-decoration: none;
}

/* Timestamp */
.chatkit-message-time {
    font-size: 11px;
    color: var(--chatkit-text-light);
    margin-top: 4px;
    padding: 0 4px;
    opacity: 0.7;
}

.chatkit-message.user .chatkit-message-time {
    text-align: right;
}

/* ================== TYPING INDICATOR ================== */
.chatkit-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--chatkit-assistant-bg);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 80px;
    align-self: flex-start;
}

.chatkit-typing-dots {
    display: flex;
    gap: 4px;
}

.chatkit-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chatkit-text-light);
    border-radius: 50%;
    animation: chatkit-typing-bounce 1.4s infinite ease-in-out;
}

.chatkit-typing-dot:nth-child(1) { animation-delay: 0s; }
.chatkit-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chatkit-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatkit-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ================== INPUT AREA ================== */
.chatkit-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--chatkit-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--chatkit-bg);
    flex-shrink: 0;
}

.chatkit-input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: #f5f5f5;
    border-radius: 24px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.chatkit-input-wrapper:focus-within {
    border-color: var(--chatkit-primary);
    background: white;
}

.chatkit-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 18px;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    color: var(--chatkit-text);
}

.chatkit-input:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.chatkit-input::placeholder {
    color: #999;
    font-size: 14px;
}

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

.chatkit-send-btn:hover:not(:disabled) {
    background: var(--chatkit-primary-hover);
    transform: scale(1.05);
}

.chatkit-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.chatkit-send-btn svg {
    width: 20px;
    height: 20px;
    transform: rotate(-45deg);
}

/* ================== ERROR MESSAGE ================== */
.chatkit-error {
    background: #fff3f3;
    border: 1px solid #ffcdd2;
    color: #c62828;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 14px;
}

/* ================== RESPONSIVE ================== */
@media (max-width: 768px) {
    .chatkit-inline .chatkit-container {
        border-radius: 8px;
    }
    
    .chatkit-message {
        max-width: 92%;
    }
}

@media (max-width: 480px) {
    .chatkit-popup-overlay .chatkit-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }
    
    .chatkit-bubble {
        bottom: 16px;
        right: 16px;
    }
    
    .chatkit-message {
        max-width: 95%;
    }
    
    .chatkit-access-icon {
        font-size: 48px;
    }
}

/* ================== DARK MODE ================== */
@media (prefers-color-scheme: dark) {
    .chatkit-container {
        --chatkit-bg: #1e1e1e;
        --chatkit-text: #e0e0e0;
        --chatkit-text-light: #999999;
        --chatkit-border: #333333;
        --chatkit-assistant-bg: #2d2d2d;
    }
    
    .chatkit-input-wrapper {
        background: #2d2d2d;
    }
    
    .chatkit-input-wrapper:focus-within {
        background: #333333;
    }
    
    .chatkit-limit-display {
        background: #252525;
    }
    
    .chatkit-limit-info {
        background: #2d2d2d;
    }
    
    .chatkit-error {
        background: #3d1515;
        border-color: #5c2020;
        color: #ff8a80;
    }
}
