/* Codesala AI Chatbot — frontend styles */

#csac-root {
    --csac-bg: #ffffff;
    --csac-fg: #1f2937;
    --csac-muted: #6b7280;
    --csac-border: rgba(0, 0, 0, 0.08);
    --csac-bubble-user: var(--csac-accent, #4f46e5);
    --csac-bubble-bot: #f3f4f6;
    --csac-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
    position: fixed;
    bottom: 22px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--csac-fg);
}

#csac-root[data-position="right"] { right: 22px; }
#csac-root[data-position="left"]  { left: 22px;  }

#csac-root[data-theme="dark"] {
    --csac-bg: #0f172a;
    --csac-fg: #e5e7eb;
    --csac-muted: #94a3b8;
    --csac-border: rgba(255, 255, 255, 0.08);
    --csac-bubble-bot: #1e293b;
}

@media (prefers-color-scheme: dark) {
    #csac-root[data-theme="auto"] {
        --csac-bg: #0f172a;
        --csac-fg: #e5e7eb;
        --csac-muted: #94a3b8;
        --csac-border: rgba(255, 255, 255, 0.08);
        --csac-bubble-bot: #1e293b;
    }
}

/* Bubble */
#csac-bubble {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    background: var(--csac-accent, #4f46e5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--csac-shadow);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
    overflow: hidden;
    padding: 0;
}
#csac-bubble:hover { transform: scale(1.06); box-shadow: 0 18px 42px rgba(15, 23, 42, 0.28); }
#csac-bubble:focus { outline: 3px solid rgba(79, 70, 229, 0.4); outline-offset: 2px; }

/* Image-mode bubble — face / logo crops to a clean circle */
#csac-bubble.csac-bubble-img { background: #fff; }
#csac-bubble.csac-bubble-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Online indicator dot */
.csac-bubble-dot {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid #fff;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
    animation: csac-pulse 2.2s ease-out infinite;
}
@keyframes csac-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Panel */
#csac-panel {
    position: absolute;
    bottom: 76px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--csac-bg);
    border-radius: 16px;
    box-shadow: var(--csac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--csac-border);
    animation: csac-pop .18s ease-out;
}
/* Force-hide when collapsed — without this, our display:flex above overrides
   the [hidden] user-agent rule and the panel stays visible. */
#csac-panel[hidden] { display: none !important; }
#csac-root[data-position="right"] #csac-panel { right: 0; }
#csac-root[data-position="left"]  #csac-panel { left: 0;  }

@keyframes csac-pop {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.csac-head {
    background: var(--csac-accent, #4f46e5);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}
.csac-head-l { display: flex; align-items: center; gap: 10px; }
.csac-head-r { display: flex; align-items: center; gap: 4px; }
.csac-head strong { font-size: 14px; display: block; }
.csac-status { font-size: 11px; opacity: .85; }

/* Language picker */
.csac-lang-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 4px 10px 4px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background .15s ease;
}
.csac-lang-btn:hover { background: rgba(255, 255, 255, 0.25); }
.csac-lang-btn svg { opacity: .9; }
.csac-lang-menu {
    position: absolute;
    top: 100%;
    right: 12px;
    margin-top: 6px;
    background: var(--csac-bg);
    color: var(--csac-fg);
    border: 1px solid var(--csac-border);
    border-radius: 10px;
    list-style: none;
    margin: 0;
    padding: 6px 0;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    max-height: 320px;
    overflow-y: auto;
    min-width: 180px;
    z-index: 10;
}
.csac-lang-menu[hidden] { display: none !important; }
.csac-lang-menu li {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--csac-fg);
}
.csac-lang-menu li:hover    { background: var(--csac-bubble-bot); }
.csac-lang-menu li.is-active {
    background: var(--csac-bubble-bot);
    font-weight: 700;
    color: var(--csac-accent, #4f46e5);
}
.csac-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px;
    object-fit: cover;
}
.csac-close {
    background: transparent;
    color: #fff;
    border: 0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}

/* Messages */
.csac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.csac-bubble {
    max-width: 80%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.csac-bubble.csac-user {
    align-self: flex-end;
    background: var(--csac-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.csac-bubble.csac-bot {
    align-self: flex-start;
    background: var(--csac-bubble-bot);
    color: var(--csac-fg);
    border-bottom-left-radius: 4px;
}
.csac-bubble.csac-bot a {
    color: var(--csac-accent, #4f46e5);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}
.csac-bubble.csac-bot a:hover { text-decoration: none; }
.csac-bubble.csac-bot strong { font-weight: 700; }
.csac-typing {
    align-self: flex-start;
    color: var(--csac-muted);
    font-size: 12px;
    padding: 4px 12px;
}
.csac-typing span { animation: csac-blink 1.2s infinite; display: inline-block; }
.csac-typing span:nth-child(2) { animation-delay: .2s; }
.csac-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes csac-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Lead capture form */
.csac-lead-card {
    align-self: stretch;
    background: var(--csac-bubble-bot);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.csac-lead-card input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--csac-border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--csac-bg);
    color: var(--csac-fg);
    box-sizing: border-box;
}
.csac-lead-card button {
    background: var(--csac-accent, #4f46e5);
    color: #fff;
    border: 0;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

/* Form */
.csac-form {
    border-top: 1px solid var(--csac-border);
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--csac-bg);
}
.csac-form input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--csac-border);
    border-radius: 999px;
    font-size: 14px;
    outline: none;
    background: var(--csac-bg);
    color: var(--csac-fg);
}
.csac-form input[type="text"]:focus { border-color: var(--csac-accent, #4f46e5); }
.csac-mic, .csac-send {
    background: transparent;
    border: 0;
    color: var(--csac-muted);
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.csac-mic.is-active {
    color: #ef4444;
    background: #fee2e2;
    animation: csac-mic-pulse 1.4s ease-in-out infinite;
}
@keyframes csac-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
    50%      { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.csac-send { color: var(--csac-accent, #4f46e5); }
.csac-send:hover, .csac-mic:hover { background: var(--csac-bubble-bot); }

.csac-gdpr {
    font-size: 11px;
    color: var(--csac-muted);
    text-align: center;
    margin: 0;
    padding: 6px 12px 10px;
    background: var(--csac-bg);
}

@media (max-width: 480px) {
    #csac-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 110px);
    }
}
