/* ==========================================================================
   Kortelo Live Chat Widget
   Pure CSS — no framework. Black/white only. Respects prefers-reduced-motion.
   ========================================================================== */

#kortelo-chat-root,
#kortelo-chat-root * {
    box-sizing: border-box;
}

#kortelo-chat-root {
    --chat-bg: #ffffff;
    --chat-ink-50: #fafafa;
    --chat-ink-100: #f5f5f5;
    --chat-ink-200: #e5e5e5;
    --chat-ink-400: #a3a3a3;
    --chat-ink-500: #737373;
    --chat-ink-700: #404040;
    --chat-ink-900: #171717;
    --chat-ink-950: #0a0a0a;
    --chat-shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.20),
                     0 4px 12px -4px rgba(0, 0, 0, 0.10);
    --chat-radius: 16px;
    font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
    color: var(--chat-ink-950);
    -webkit-font-smoothing: antialiased;
}

/* ===== Floating launcher button ===== */
.kchat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 9999px;
    background: var(--chat-ink-950);
    color: #ffffff;
    border: none;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.35),
                0 4px 12px -4px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(8px) scale(0.92);
    transition: opacity 0.3s ease,
                transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                background-color 0.2s ease;
}
.kchat-launcher.is-ready { opacity: 1; transform: translateY(0) scale(1); }
.kchat-launcher:hover { background: var(--chat-ink-700); transform: translateY(-2px) scale(1.04); }
.kchat-launcher:focus-visible {
    outline: 2px solid var(--chat-ink-950);
    outline-offset: 4px;
}
.kchat-launcher svg { width: 24px; height: 24px; }

.kchat-launcher-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 9999px;
    background: #ffffff;
    color: var(--chat-ink-950);
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--chat-ink-950);
}
.kchat-launcher.has-unread .kchat-launcher-badge { display: inline-flex; }

@media (max-width: 640px) {
    .kchat-launcher { right: 16px; bottom: 16px; width: 52px; height: 52px; }
    .kchat-launcher svg { width: 22px; height: 22px; }
}

/* ===== Panel ===== */
.kchat-panel {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 48px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow-lg);
    border: 1px solid var(--chat-ink-200);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transform-origin: bottom right;
    transform: translateY(8px) scale(0.96);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.kchat-panel.is-open { display: flex; transform: translateY(0) scale(1); opacity: 1; }

@media (max-width: 640px) {
    .kchat-panel {
        right: 0; bottom: 0; left: 0; top: 0;
        width: 100vw; height: 100vh; max-height: 100vh;
        border-radius: 0;
        border: none;
    }
}

/* ===== Header ===== */
.kchat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--chat-ink-200);
    flex-shrink: 0;
}
.kchat-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.kchat-brand-name {
    font-family: 'Space Grotesk', Inter, sans-serif;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
}
.kchat-brand-name .kchat-dot {
    display: inline-block;
    animation: kchat-dot-pulse 2.2s ease-in-out infinite;
    transform-origin: center;
}
@keyframes kchat-dot-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

.kchat-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--chat-ink-500);
}
.kchat-status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--chat-ink-400);
}
.kchat-status.is-online .kchat-status-dot { background: #22c55e; }

.kchat-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--chat-ink-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.kchat-close:hover { background: var(--chat-ink-100); color: var(--chat-ink-950); }
.kchat-close svg { width: 18px; height: 18px; }

/* ===== Messages area ===== */
.kchat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--chat-bg);
}
.kchat-msg {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kchat-msg.role-client { align-self: flex-end; align-items: flex-end; }
.kchat-msg.role-ai,
.kchat-msg.role-human { align-self: flex-start; align-items: flex-start; }

.kchat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.kchat-msg.role-client .kchat-bubble {
    background: var(--chat-ink-950);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}
.kchat-msg.role-ai .kchat-bubble {
    background: var(--chat-ink-100);
    color: var(--chat-ink-950);
    border-bottom-left-radius: 4px;
}
.kchat-msg.role-human .kchat-bubble {
    background: #ffffff;
    color: var(--chat-ink-950);
    border: 1px solid var(--chat-ink-200);
    border-bottom-left-radius: 4px;
}

.kchat-msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10px;
    color: var(--chat-ink-500);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.kchat-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--chat-ink-100);
    color: var(--chat-ink-700);
    font-weight: 600;
    letter-spacing: 0.08em;
}
.kchat-msg.role-human .kchat-badge { background: var(--chat-ink-950); color: #ffffff; }

/* ===== Typing indicator ===== */
.kchat-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--chat-ink-100);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.kchat-typing-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--chat-ink-500);
    animation: kchat-typing 1.4s infinite both;
}
.kchat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.kchat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes kchat-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
}

/* ===== Composer ===== */
.kchat-composer {
    border-top: 1px solid var(--chat-ink-200);
    padding: 12px 16px 14px;
    background: var(--chat-bg);
    flex-shrink: 0;
}
.kchat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.kchat-input {
    flex: 1 1 auto;
    border: 1px solid var(--chat-ink-200);
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
    color: var(--chat-ink-950);
    resize: none;
    outline: none;
    max-height: 110px;
    background: var(--chat-bg);
    transition: border-color 0.15s ease;
}
.kchat-input:focus { border-color: var(--chat-ink-950); }
.kchat-input::placeholder { color: var(--chat-ink-400); }

.kchat-send {
    flex: 0 0 auto;
    width: 38px; height: 38px;
    border-radius: 9999px;
    background: var(--chat-ink-950);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.kchat-send:disabled { background: var(--chat-ink-200); color: var(--chat-ink-400); cursor: not-allowed; }
.kchat-send:not(:disabled):hover { background: var(--chat-ink-700); }
.kchat-send svg { width: 18px; height: 18px; }

.kchat-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    gap: 8px;
}
.kchat-counter {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10px;
    color: var(--chat-ink-400);
}
.kchat-counter.is-near { color: #b45309; }
.kchat-counter.is-over { color: #dc2626; }
.kchat-gdpr {
    font-size: 10px;
    color: var(--chat-ink-500);
    line-height: 1.4;
}
.kchat-gdpr a { color: var(--chat-ink-950); text-decoration: underline; }

/* ===== Consent gate (first-open overlay) ===== */
.kchat-consent {
    flex: 1 1 auto;
    padding: 28px 22px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    text-align: left;
}
.kchat-consent h3 {
    font-family: 'Space Grotesk', Inter, sans-serif;
    font-weight: 700;
    font-size: 22px;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--chat-ink-950);
    margin: 0;
}
.kchat-consent p {
    font-size: 13px;
    line-height: 1.55;
    color: var(--chat-ink-700);
    margin: 0;
}
.kchat-consent label {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 12px;
    color: var(--chat-ink-700);
    line-height: 1.55;
    cursor: pointer;
}
.kchat-consent label input { margin-top: 2px; }
.kchat-consent button {
    margin-top: 4px;
    padding: 11px 18px;
    background: var(--chat-ink-950);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    align-self: flex-start;
}
.kchat-consent button:disabled {
    background: var(--chat-ink-200);
    color: var(--chat-ink-400);
    cursor: not-allowed;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    .kchat-launcher,
    .kchat-panel { transition: none; }
    .kchat-brand-name .kchat-dot { animation: none; }
    .kchat-typing-dot { animation: none; opacity: 0.6; }
}
