/**
 * Thermokoch Support Bot - Frontend Widget Styles
 * Modern, responsive culinary theme for thermokoch.de
 */

:root {
    --tk-primary: #2d7a46;
    --tk-primary-dark: #225f36;
    --tk-primary-light: #eaf5ed;
    --tk-accent: #f39c12;
    --tk-surface: #ffffff;
    --tk-surface-alt: #f8faf9;
    --tk-text-main: #1f2937;
    --tk-text-muted: #6b7280;
    --tk-border: #e5e7eb;
    --tk-shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, 0.18), 0 8px 16px -4px rgba(0, 0, 0, 0.08);
    --tk-radius: 16px;
    --tk-font: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.thermokoch-bot-container {
    position: fixed;
    z-index: 9999999 !important;
    font-family: var(--tk-font);
    box-sizing: border-box;
}

.thermokoch-bot-container * {
    box-sizing: border-box;
    font-family: inherit;
}

/* Positions Desktop */
.thermokoch-bot-container.position-middle-right {
    top: 50%;
    transform: translateY(-50%);
    right: 20px;
    bottom: auto;
    left: auto;
}

.thermokoch-bot-container.position-middle-left {
    top: 50%;
    transform: translateY(-50%);
    left: 20px;
    bottom: auto;
    right: auto;
}

.thermokoch-bot-container.position-bottom-left {
    bottom: var(--tk-desktop-bottom-offset, 100px);
    left: 24px;
    right: auto;
    top: auto;
    transform: none;
}

.thermokoch-bot-container.position-bottom-right {
    bottom: var(--tk-desktop-bottom-offset, 220px);
    right: 24px;
    left: auto;
    top: auto;
    transform: none;
}

/* Trigger Button */
.thermokoch-bot-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-primary-dark));
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(45, 122, 70, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    outline: none;
}

.thermokoch-bot-trigger-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 25px rgba(45, 122, 70, 0.45);
}

.thermokoch-bot-trigger-btn:active {
    transform: scale(0.96);
}

.thermokoch-bot-trigger-btn .tk-trigger-icon-chat,
.thermokoch-bot-trigger-btn .tk-trigger-icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.thermokoch-bot-trigger-btn .tk-trigger-icon-close {
    display: none;
}

.thermokoch-bot-container.is-open .thermokoch-bot-trigger-btn .tk-trigger-icon-chat {
    display: none;
}

.thermokoch-bot-container.is-open .thermokoch-bot-trigger-btn .tk-trigger-icon-close {
    display: flex;
}

.tk-trigger-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e67e22;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Chat Window Modal / Drawer */
.thermokoch-bot-window {
    display: none;
    position: absolute;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    background: var(--tk-surface);
    border-radius: var(--tk-radius);
    box-shadow: var(--tk-shadow-lg);
    border: 1px solid var(--tk-border);
    flex-direction: column;
    overflow: hidden;
    z-index: 10000000;
}

.thermokoch-bot-container.position-middle-right .thermokoch-bot-window {
    position: fixed;
    right: 24px;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    height: min(560px, calc(100vh - 80px));
    max-height: calc(100vh - 80px);
    transform-origin: center right;
    animation: tkFadeInMiddleRight 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.thermokoch-bot-container.position-middle-left .thermokoch-bot-window {
    position: fixed;
    left: 24px;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    height: min(560px, calc(100vh - 80px));
    max-height: calc(100vh - 80px);
    transform-origin: center left;
    animation: tkFadeInMiddleLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.thermokoch-bot-container.position-bottom-right .thermokoch-bot-window {
    position: absolute;
    right: 0;
    bottom: 74px;
    top: auto;
    height: min(560px, calc(100vh - 120px));
    max-height: calc(100vh - 120px);
    transform-origin: bottom right;
    animation: tkFadeInUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.thermokoch-bot-container.position-bottom-left .thermokoch-bot-window {
    position: absolute;
    left: 0;
    bottom: 74px;
    top: auto;
    height: min(560px, calc(100vh - 120px));
    max-height: calc(100vh - 120px);
    transform-origin: bottom left;
    animation: tkFadeInUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.thermokoch-bot-container.is-open .thermokoch-bot-window {
    display: flex;
}

@keyframes tkFadeInMiddleRight {
    from {
        opacity: 0;
        transform: translateY(calc(-50% + 14px)) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

@keyframes tkFadeInMiddleLeft {
    from {
        opacity: 0;
        transform: translateY(calc(-50% + 14px)) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

@keyframes tkFadeInUp {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.tk-bot-header {
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-primary-dark));
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.tk-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.tk-avatar {
    width: 46px;
    height: 46px;
    background: rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(4px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.tk-avatar-emoji {
    font-size: 28px;
    line-height: 1;
    display: inline-block;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.tk-avatar-img {
    width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: block !important;
}

.tk-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #2ecc71;
    border-radius: 50%;
    border: 2px solid #ffffff;
}

.tk-title-wrap {
    min-width: 0;
    overflow: hidden;
}

.tk-title-wrap h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tk-brand-tag {
    font-size: 10px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.25);
    padding: 1px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.tk-subtitle {
    margin: 2px 0 0 0;
    font-size: 11px;
    opacity: 0.88;
    color: #e5f2e8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tk-header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-shrink: 0 !important;
    margin-left: 8px;
}

.tk-header-btn {
    background: rgba(255, 255, 255, 0.22) !important;
    border: 1px solid rgba(255, 255, 255, 0.35) !important;
    color: #ffffff !important;
    cursor: pointer !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 1 !important;
    transition: background 0.15s, transform 0.15s, border-color 0.15s !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12) !important;
}

.tk-header-btn svg {
    stroke: #ffffff !important;
    display: block !important;
}

.tk-header-btn:hover {
    background: rgba(255, 255, 255, 0.38) !important;
    border-color: rgba(255, 255, 255, 0.6) !important;
    transform: scale(1.05) !important;
}

.tk-btn-close {
    background: rgba(0, 0, 0, 0.28) !important;
    border-color: rgba(255, 255, 255, 0.45) !important;
}

.tk-btn-close:hover {
    background: rgba(220, 38, 38, 0.85) !important;
    border-color: rgba(220, 38, 38, 1) !important;
}

/* Messages Area */
.tk-bot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--tk-surface-alt);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.tk-bot-messages::-webkit-scrollbar {
    width: 6px;
}

.tk-bot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Message Bubble */
.tk-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: tkMsgSlide 0.2s ease-out;
}

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

.tk-msg-user {
    align-self: flex-end;
}

.tk-msg-bot {
    align-self: flex-start;
}

.tk-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

.tk-msg-user .tk-msg-bubble {
    background: var(--tk-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.tk-msg-bot .tk-msg-bubble {
    background: #ffffff;
    color: var(--tk-text-main);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--tk-border);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.tk-msg-time {
    font-size: 10px;
    color: var(--tk-text-muted);
    margin-top: 4px;
    align-self: flex-end;
}

.tk-msg-bot .tk-msg-time {
    align-self: flex-start;
}

/* Markdown formatting inside bubbles */
.tk-msg-bubble p {
    margin: 0 0 8px 0;
}
.tk-msg-bubble p:last-child {
    margin-bottom: 0;
}
.tk-msg-bubble ul, .tk-msg-bubble ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}
.tk-msg-bubble li {
    margin-bottom: 4px;
}
.tk-msg-bubble strong {
    font-weight: 600;
}
.tk-msg-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
}
.tk-msg-bubble a {
    color: var(--tk-primary);
    text-decoration: underline;
}

/* Grounding Citations Section in bot message */
.tk-grounding-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--tk-border);
    font-size: 11.5px;
}

.tk-sources-title {
    font-weight: 600;
    color: var(--tk-text-muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tk-source-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.tk-source-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--tk-primary-light);
    color: var(--tk-primary-dark);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    text-decoration: none;
    font-weight: 500;
    transition: background 0.15s, transform 0.15s;
}

.tk-source-chip:hover {
    background: #d5eedd;
    transform: translateY(-1px);
    text-decoration: underline;
}

/* Quick Prompts */
.tk-bot-quick-prompts {
    padding: 8px 14px;
    background: var(--tk-surface-alt);
    border-top: 1px solid var(--tk-border);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
}

.tk-bot-quick-prompts::-webkit-scrollbar {
    height: 4px;
}

.tk-bot-quick-prompts::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.tk-quick-prompt-btn {
    background: #ffffff;
    border: 1px solid var(--tk-border);
    color: var(--tk-text-main);
    padding: 5px 10px;
    border-radius: 14px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.tk-quick-prompt-btn:hover {
    border-color: var(--tk-primary);
    color: var(--tk-primary);
    background: var(--tk-primary-light);
}

/* Typing Indicator */
.tk-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #ffffff;
    border-radius: 14px;
    width: fit-content;
    border: 1px solid var(--tk-border);
}

.tk-dot-pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--tk-primary);
    animation: tkPulse 1.4s infinite ease-in-out both;
}

.tk-dot-pulse:nth-child(1) { animation-delay: -0.32s; }
.tk-dot-pulse:nth-child(2) { animation-delay: -0.16s; }

@keyframes tkPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Footer & Input */
.tk-bot-footer {
    padding: 10px 14px 8px;
    background: #ffffff;
    border-top: 1px solid var(--tk-border);
}

.tk-bot-form {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    background: var(--tk-surface-alt) !important;
    border: 1px solid var(--tk-border) !important;
    border-radius: 24px !important;
    padding: 4px 6px 4px 14px !important;
    transition: border-color 0.2s, box-shadow 0.2s !important;
    min-height: 44px !important;
    box-sizing: border-box !important;
}

.tk-bot-form:focus-within {
    border-color: var(--tk-primary) !important;
    box-shadow: 0 0 0 2px rgba(45, 122, 70, 0.18) !important;
    background: #ffffff !important;
}

.tk-bot-textarea {
    flex: 1 !important;
    border: none !important;
    background: transparent !important;
    outline: none !important;
    box-shadow: none !important;
    resize: none !important;
    overflow-y: hidden !important;
    font-size: 13.5px !important;
    color: var(--tk-text-main) !important;
    line-height: 1.4 !important;
    max-height: 90px !important;
    padding: 6px 0 !important;
    margin: 0 !important;
    font-family: inherit !important;
}

.tk-bot-send-btn {
    width: 36px !important;
    min-width: 36px !important;
    max-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    border-radius: 50% !important;
    background: var(--tk-primary, #2d7a46) !important;
    color: #ffffff !important;
    border: none !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
    flex-shrink: 0 !important;
    box-shadow: 0 2px 6px rgba(45, 122, 70, 0.3) !important;
    transition: background 0.15s, transform 0.15s, opacity 0.15s !important;
}

.tk-bot-send-btn svg {
    width: 17px !important;
    height: 17px !important;
    stroke: #ffffff !important;
    fill: none !important;
    display: block !important;
    pointer-events: none !important;
    transform: translate(-1px, 1px);
}

.tk-bot-send-btn:disabled {
    background: var(--tk-primary, #2d7a46) !important;
    opacity: 0.45 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
}

.tk-bot-send-btn:not(:disabled):hover {
    background: var(--tk-primary-dark, #1e5932) !important;
    transform: scale(1.06) !important;
    opacity: 1 !important;
}

.tk-bot-disclaimer {
    text-align: center;
    font-size: 9.5px;
    color: var(--tk-text-muted);
    margin-top: 5px;
}

/* Responsive Mobile View (<= 640px) - Sits cleanly above Grow heart & bottom ads */
@media (max-width: 640px) {
    .thermokoch-bot-container.position-middle-right,
    .thermokoch-bot-container.position-middle-left,
    .thermokoch-bot-container.position-bottom-right,
    .thermokoch-bot-container.position-bottom-left {
        top: auto !important;
        transform: none !important;
        bottom: max(var(--tk-mobile-bottom-offset, 150px), calc(env(safe-area-inset-bottom, 0px) + var(--tk-mobile-bottom-offset, 150px))) !important;
        right: 16px !important;
        left: auto !important;
    }

    .thermokoch-bot-trigger-btn {
        width: 56px;
        height: 56px;
    }

    .thermokoch-bot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: max(85px, calc(env(safe-area-inset-bottom, 0px) + 80px));
        width: 100vw;
        height: calc(100dvh - max(85px, calc(env(safe-area-inset-bottom, 0px) + 80px)));
        max-width: 100vw;
        max-height: calc(100dvh - max(85px, calc(env(safe-area-inset-bottom, 0px) + 80px)));
        border-radius: 0 0 16px 16px;
        border: none;
        border-bottom: 2px solid var(--tk-border);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
        z-index: 10000000;
    }

    .tk-bot-footer {
        padding: 8px 12px;
        background: #ffffff;
    }
}
