/* ═══════════════════════════════════════════════════════════════════════════
   KAI Chat Widget — KARAKTER Realty
   Tokens align with the site's CSS custom properties defined in karakter.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens (mirrored from karakter.css so widget is self-contained) ── */
#kai-root {
    --kai-black: #090909;
    --kai-white: #FAFAF8;
    --kai-gold: #C5973A;
    --kai-gold-lt: #E2C27A;
    --kai-gold-dk: #9A7228;
    --kai-stone: #F0EDE7;
    --kai-muted: #7A7570;
    --kai-border: #E0DAD0;
    --kai-sans: 'Outfit', sans-serif;
    --kai-serif: 'Cormorant Garamond', Georgia, serif;
    --kai-radius: 14px;
    --kai-shadow: 0 8px 48px rgba(9, 9, 9, 0.22), 0 2px 12px rgba(9, 9, 9, 0.12);
    --kai-panel-w: 380px;
    --kai-panel-h: 560px;
    font-family: var(--kai-sans);
}

/* ── Launcher button ── */
#kai-launcher {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--kai-black);
    border: 1.5px solid var(--kai-gold);
    box-shadow: 0 4px 24px rgba(197, 151, 58, 0.30), 0 2px 8px rgba(9, 9, 9, 0.20);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    padding: 0;
}

#kai-launcher:hover {
    transform: scale(1.07);
    box-shadow: 0 6px 32px rgba(197, 151, 58, 0.45), 0 2px 8px rgba(9, 9, 9, 0.25);
}

#kai-launcher:focus-visible {
    outline: 2px solid var(--kai-gold);
    outline-offset: 3px;
}

#kai-launcher svg {
    width: 28px;
    height: 28px;
    fill: var(--kai-gold);
    transition: opacity 0.15s ease;
}

#kai-launcher .kai-icon-close {
    display: none;
}

#kai-launcher.kai-open .kai-icon-chat {
    display: none;
}

#kai-launcher.kai-open .kai-icon-close {
    display: block;
}

/* ── Unread badge ── */
#kai-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 18px;
    height: 18px;
    background: var(--kai-gold);
    border-radius: 50%;
    border: 2px solid var(--kai-black);
    display: none;
}

#kai-badge.kai-visible {
    display: block;
}

/* ── Panel ── */
#kai-panel {
    position: fixed;
    bottom: 104px;
    right: 28px;
    z-index: 9998;
    width: var(--kai-panel-w);
    height: var(--kai-panel-h);
    max-height: calc(100dvh - 120px);
    background: var(--kai-white);
    border-radius: var(--kai-radius);
    box-shadow: var(--kai-shadow);
    border: 1px solid var(--kai-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* hidden by default */
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    transform-origin: bottom right;
}

#kai-panel.kai-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Panel header ── */
#kai-header {
    background: var(--kai-black);
    padding: 14px 16px 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(197, 151, 58, 0.20);
}

#kai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--kai-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#kai-avatar span {
    font-family: var(--kai-serif);
    font-style: italic;
    font-size: 15px;
    font-weight: 600;
    color: var(--kai-black);
    line-height: 1;
}

.kai-header-text {
    flex: 1;
    min-width: 0;
}

.kai-header-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--kai-white);
}

.kai-header-sub {
    font-size: 11px;
    color: var(--kai-gold-lt);
    margin-top: 1px;
}

#kai-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.15s;
    flex-shrink: 0;
}

#kai-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

#kai-close-btn svg {
    width: 16px;
    height: 16px;
    stroke: rgba(250, 250, 248, 0.55);
}

#kai-close-btn:focus-visible {
    outline: 2px solid var(--kai-gold);
}

/* ── Messages area ── */
#kai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#kai-messages::-webkit-scrollbar {
    width: 4px;
}

#kai-messages::-webkit-scrollbar-track {
    background: transparent;
}

#kai-messages::-webkit-scrollbar-thumb {
    background: var(--kai-border);
    border-radius: 2px;
}

/* ── Message bubbles ── */
.kai-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: kaiFadeUp 0.18s ease both;
}

@keyframes kaiFadeUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.kai-msg--ai {
    align-self: flex-start;
}

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

.kai-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.kai-msg--ai .kai-bubble {
    background: var(--kai-stone);
    color: var(--kai-black);
    border-bottom-left-radius: 3px;
}

.kai-msg--user .kai-bubble {
    background: var(--kai-black);
    color: var(--kai-white);
    border-bottom-right-radius: 3px;
}

.kai-msg--ai .kai-bubble a {
    color: var(--kai-gold-dk);
    text-decoration: underline;
}

.kai-msg--ai .kai-bubble a:hover {
    color: var(--kai-gold);
}

.kai-quick-btn {
    border: 1px solid var(--kai-gold-dk);
    background: #fff;
    color: var(--kai-black);
    min-height: 30px;
    padding: 0 10px;
    font-family: var(--kai-sans);
    font-size: 12px;
    border-radius: 999px;
    cursor: pointer;
}

.kai-quick-btn:hover {
    background: var(--kai-gold-lt);
}

.kai-quick-btn:focus-visible {
    outline: 2px solid var(--kai-gold);
    outline-offset: 2px;
}

/* ── Typing indicator ── */
#kai-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--kai-stone);
    border-radius: 12px;
    border-bottom-left-radius: 3px;
}

#kai-typing.kai-visible {
    display: flex;
    align-items: center;
    gap: 4px;
}

.kai-dot {
    width: 6px;
    height: 6px;
    background: var(--kai-muted);
    border-radius: 50%;
    animation: kaiDot 1.2s ease infinite;
}

.kai-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.kai-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes kaiDot {

    0%,
    80%,
    100% {
        transform: scale(0.65);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Input area ── */
#kai-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--kai-border);
    background: var(--kai-white);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

#kai-textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--kai-border);
    border-radius: 10px;
    padding: 9px 12px;
    font-family: var(--kai-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--kai-black);
    background: var(--kai-white);
    min-height: 40px;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.15s;
}

#kai-textarea:focus {
    border-color: var(--kai-gold);
}

#kai-textarea::placeholder {
    color: var(--kai-muted);
}

#kai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--kai-black);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

#kai-send-btn:hover {
    background: #222;
}

#kai-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

#kai-send-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--kai-gold);
}

#kai-send-btn:focus-visible {
    outline: 2px solid var(--kai-gold);
    outline-offset: 2px;
}

/* ── Powered-by footer ── */
#kai-footer {
    padding: 6px 14px 8px;
    text-align: center;
    font-size: 10px;
    color: var(--kai-muted);
    border-top: 1px solid var(--kai-border);
    flex-shrink: 0;
    background: var(--kai-white);
}

#kai-footer a {
    color: var(--kai-gold-dk);
}

/* ── Secondary quick-reply button (e.g. Maybe Later) ── */
.kai-quick-btn--secondary {
    background: transparent;
    border-color: var(--kai-border);
    color: var(--kai-muted);
}

.kai-quick-btn--secondary:hover {
    background: var(--kai-stone);
    color: var(--kai-black);
}

/* ── Inline contact form ── */
.kai-contact-form-bubble {
    min-width: 220px;
}

.kai-form-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.kai-form-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--kai-border);
    border-radius: 8px;
    font-family: var(--kai-sans);
    font-size: 13px;
    color: var(--kai-black);
    background: var(--kai-white);
    outline: none;
    transition: border-color 0.15s;
}

.kai-form-input:focus {
    border-color: var(--kai-gold);
}

.kai-form-select {
    appearance: none;
    cursor: pointer;
}

.kai-input-error {
    border-color: #c0392b;
}

.kai-form-btn {
    padding: 9px 14px;
    background: var(--kai-black);
    color: var(--kai-white);
    border: none;
    border-radius: 8px;
    font-family: var(--kai-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 2px;
}

.kai-form-btn:hover {
    background: #222;
}

/* ── Mobile responsive ── */
@media (max-width: 480px) {
    #kai-root {
        --kai-panel-w: calc(100vw - 20px);
        --kai-panel-h: calc(100dvh - 110px);
    }

    #kai-panel {
        right: 10px;
        left: 10px;
        bottom: 84px;
        width: auto;
    }

    #kai-launcher {
        bottom: 18px;
        right: 18px;
    }
}