:root {
    --chat-primary: #2563eb;
    --chat-primary-dark: #1d4ed8;
    --chat-bg: #ffffff;
    --chat-user-bg: #2563eb;
    --chat-user-color: #ffffff;
    --chat-bot-bg: #f3f4f6;
    --chat-bot-color: #111827;
    --chat-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), 0 8px 20px rgba(0, 0, 0, 0.18);
    --chat-border: 1px solid rgba(0, 0, 0, 0.08);
    --chat-radius: 16px;
}

/* === BUBBLE === */
#chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-primary);
    box-shadow: var(--chat-shadow);
    border: 2px solid rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9998;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#chat-bubble:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.22);
}

#chat-bubble:active {
    transform: translateY(0);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3), 0 6px 16px rgba(0, 0, 0, 0.2);
}

#chat-bubble svg {
    width: 34px;
    height: 34px;
    display: block;
    color: #fff;
}

#chat-bubble img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

#chat-bubble.hidden {
    display: none;
}

/* === TEASER BUBLINA === */
#chat-teaser {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: 9998;
    background: #fff;
    padding: 14px 18px;
    border-radius: 16px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 17px;
    font-weight: 600;
    color: #18433B;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    animation: chat-float 2s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
}

#chat-teaser::after {
    content: "";
    position: absolute;
    right: 22px;
    bottom: -8px;
    width: 16px;
    height: 16px;
    background: #fff;
    transform: rotate(45deg);
}

#chat-teaser.hidden {
    display: none;
}

@keyframes chat-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

#chat-bubble .dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border: 2px solid #fff;
    border-radius: 50%;
    display: none;
}

/* === MOBILE BACKDROP === */
#chat-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9997;
    animation: backdrop-in 0.2s ease-out;
}

#chat-backdrop.open {
    display: block;
}

@keyframes backdrop-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* === CHAT WINDOW === */
#chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 48px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    border: var(--chat-border);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    animation: chat-in 0.25s ease-out;
}

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

@keyframes chat-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === HEADER === */
.chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-header .avatar svg {
    width: 28px;
    height: 28px;
    color: var(--chat-primary);
}

.chat-header .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-header .info {
    flex: 1;
    min-width: 0;
}

.chat-header .name {
    font-weight: 600;
    font-size: 15px;
}

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

.chat-header .status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
}

.chat-header .close {
    background: transparent;
    border: 0;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.chat-header .close:hover,
.chat-header .close:active {
    background: rgba(255, 255, 255, 0.15);
}

/* === MESSAGES === */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

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

.chat-messages::-webkit-scrollbar-button {
    display: none;
    height: 0;
    width: 0;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.msg {
    max-width: 85%;
    line-height: 1.5;
    word-wrap: break-word;
}

.msg .bubble {
    padding: 10px 14px;
    border-radius: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Slovotvorné delenie pre dlhšie jazyky (napr. nemčina) */
#chat-window:lang(de) .msg .bubble,
#chat-window:lang(en) .msg .bubble {
    hyphens: auto;
}

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

.msg.user .bubble {
    background: var(--chat-user-bg);
    color: var(--chat-user-color);
    border-bottom-right-radius: 4px;
}

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

.msg.bot .bubble {
    background: var(--chat-bot-bg);
    color: var(--chat-bot-color);
    border-bottom-left-radius: 4px;
}

.msg .time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

.msg.user .time {
    text-align: right;
}

/* === LINKS V BUBLINE === */
.msg .bubble a {
    color: inherit;
    text-decoration: underline;
    overflow-wrap: anywhere;
    word-break: normal;
}

.msg.bot .bubble a {
    color: var(--chat-primary);
}

/* === MARKDOWN FORMATOVANIE (len v bot bubline) === */
.msg.bot .bubble strong {
    font-weight: 600;
}

.msg.bot .bubble em {
    font-style: italic;
}

.msg.bot .bubble h3,
.msg.bot .bubble h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 8px 0 4px;
    line-height: 1.3;
}

.msg.bot .bubble h4 {
    font-size: 13px;
}

.msg.bot .bubble ul,
.msg.bot .bubble ol {
    margin: 6px 0;
    padding-left: 22px;
}

.msg.bot .bubble li {
    margin: 2px 0;
    line-height: 1.4;
}

.msg.bot .bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 12px;
}

.msg.bot .bubble pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
}

.msg.bot .bubble pre code {
    background: transparent;
    padding: 0;
    font-size: 12px;
    line-height: 1.4;
}

.msg.bot .bubble .md-table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}

.msg.bot .bubble .md-table th,
.msg.bot .bubble .md-table td {
    border: 1px solid #e5e7eb;
    padding: 5px 8px;
    text-align: left;
    vertical-align: top;
}

.msg.bot .bubble .md-table th {
    background: rgba(0, 0, 0, 0.04);
    font-weight: 600;
}

.msg.bot .bubble > *:first-child {
    margin-top: 0;
}

.msg.bot .bubble > *:last-child {
    margin-bottom: 0;
}

/* === TYPING INDICATOR === */
.typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.typing span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.3s infinite ease-in-out;
}

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

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

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

/* === INPUT === */
.chat-input {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    min-width: 0;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    height: 44px;
    min-height: 44px;
    max-height: 100px;
    outline: none;
    overflow-y: auto;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-input textarea::-webkit-scrollbar {
    display: none;
}

.chat-input textarea::-webkit-resizer {
    display: none;
}

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

.chat-input button {
    border: 0;
    background: var(--chat-primary);
    color: #fff;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s ease;
}

.chat-input button:hover:not(:disabled) {
    background: var(--chat-primary-dark);
}

.chat-input button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.chat-input button svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

/* === FOOTER & ERRORS === */
.chat-footer {
    padding: 8px 12px;
    background: #f9fafb;
    border-top: 1px solid #f3f4f6;
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    flex-shrink: 0;
}

.chat-error {
    margin: 0 16px 8px;
    padding: 8px 12px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
    font-size: 13px;
}

/* === MOBILE === */
@media (max-width: 640px) {
    body.chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    #chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    #chat-bubble svg {
        width: 30px;
        height: 30px;
    }

    #chat-teaser {
        right: 16px;
        bottom: 84px;
        padding: 12px 16px;
        font-size: 15px;
    }

    #chat-teaser::after {
        right: 20px;
    }

    #chat-window {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        border: 0;
        animation: chat-in-mobile 0.25s ease-out;
    }

    #chat-window.has-vv-height {
        height: var(--chat-vv-height, 100dvh);
        max-height: var(--chat-vv-height, 100dvh);
    }

    @keyframes chat-in-mobile {
        from {
            opacity: 0;
            transform: translateY(30px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .chat-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-input {
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chat-footer {
        display: none;
    }

    .msg {
        max-width: 90%;
    }

    .msg.bot .bubble .md-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@supports not (height: 100dvh) {
    @media (max-width: 640px) {
        #chat-window {
            height: 100vh;
            max-height: 100vh;
        }
    }
}