/* SmartChat AI Widget */
#smartchat-widget * {
    box-sizing: border-box;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Floating Button */
#smartchat-btn {
    position: fixed;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#smartchat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

#smartchat-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* Chat Window */
#smartchat-window {
    position: fixed;
    bottom: 96px;
    width: 380px;
    height: 520px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
}

#smartchat-window.sc-open {
    display: flex;
}

/* Position modifiers */
.sc-pos-bottom-right #smartchat-btn,
.sc-pos-bottom-right #smartchat-window {
    right: 24px;
}

.sc-pos-bottom-left #smartchat-btn,
.sc-pos-bottom-left #smartchat-window {
    left: 24px;
}

/* Header */
#smartchat-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#smartchat-header-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sc-header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.sc-status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}

#smartchat-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    font-size: 20px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

#smartchat-close:hover {
    opacity: 1;
}

/* Messages Area */
#smartchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

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

#smartchat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* Message Wrappers */
.sc-msg-wrapper {
    display: flex;
    flex-direction: column;
    animation: sc-fade-in 0.2s ease;
}

.sc-msg-wrapper-user {
    align-items: flex-end;
}

.sc-msg-wrapper-assistant {
    align-items: flex-start;
}

/* Name Labels */
.sc-msg-name {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 4px;
    padding: 0 4px;
}

/* Message Bubbles */
.sc-msg {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.sc-msg-user {
    border-bottom-right-radius: 4px;
}

.sc-msg-assistant {
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

/* Assistant message with avatar */
.sc-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 90%;
}

.sc-msg-col {
    display: flex;
    flex-direction: column;
}

.sc-msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.sc-msg-row .sc-msg {
    max-width: 100%;
}

/* Typing Indicator */
.sc-typing {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: sc-fade-in 0.2s ease;
}

.sc-typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: sc-bounce 1.4s infinite both;
}

.sc-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.sc-typing-dot:nth-child(3) { animation-delay: 0.32s; }

/* Escalation Link */
.sc-escalate-link {
    text-align: center;
    padding: 8px;
    font-size: 13px;
}

.sc-escalate-link a {
    color: #6b7280;
    text-decoration: underline;
    cursor: pointer;
}

.sc-escalate-link .sc-link-sep {
    margin: 0 8px;
    color: #9ca3af;
    font-size: 12px;
}

/* End chat confirmation overlay */
.sc-end-chat-confirm {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}

.sc-end-chat-confirm.sc-end-chat-confirm-visible {
    display: flex;
}

.sc-end-chat-confirm-box {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    max-width: 320px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.sc-end-chat-confirm-msg {
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
}

.sc-end-chat-confirm-btns {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.sc-end-chat-confirm-btns button {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
}

.sc-end-chat-confirm-btns button:hover {
    background: #f3f4f6;
}

.sc-end-chat-confirm-btns #sc-end-chat-confirm-btn {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.sc-end-chat-confirm-btns #sc-end-chat-confirm-btn:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* Input Area */
#smartchat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: center;
    background: #fff;
    flex-shrink: 0;
}

#smartchat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    font-family: inherit;
}

#smartchat-input:focus {
    border-color: #9ca3af;
}

#smartchat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

#smartchat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#smartchat-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Escalation Form */
#smartchat-escalation {
    padding: 20px;
    background: #fff;
    display: none;
    flex-direction: column;
    gap: 12px;
}

#smartchat-escalation.sc-open {
    display: flex;
}

#smartchat-escalation h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

#smartchat-escalation p {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 4px;
}

#smartchat-escalation input,
#smartchat-escalation textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

#smartchat-escalation textarea {
    resize: none;
    height: 60px;
}

#sc-escalation-submit {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

#sc-escalation-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#sc-escalation-back {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    text-align: center;
}

.sc-success-msg {
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
    color: #1f2937;
}

.sc-success-msg .sc-check {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

/* Powered by */
.sc-powered-by {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #9ca3af;
    border-top: 1px solid #f3f4f6;
    background: #fff;
}

.sc-powered-by a {
    color: #6b7280;
    text-decoration: none;
}

/* Quick-Start Options */
.sc-quickstart {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
    animation: sc-fade-in 0.3s ease;
}

.sc-quickstart-btn {
    align-self: flex-start;
    padding: 10px 18px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    background: #fff;
    color: #1f2937;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.sc-quickstart-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    transform: translateX(2px);
}

.sc-quickstart-btn.sc-quickstart-escalate {
    border-style: dashed;
    color: #6b7280;
}

.sc-quickstart-btn.sc-quickstart-escalate:hover {
    color: #1f2937;
}

/* Locked Input */
.sc-input-locked {
    opacity: 0.5;
}

.sc-input-locked #smartchat-input {
    background: #f3f4f6;
    cursor: not-allowed;
}

/* Animations */
@keyframes sc-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes sc-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ── Offline status dot on launcher ─────────────────────────── */
.sc-launcher-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    pointer-events: none;
}

.sc-launcher-dot-offline {
    background: #ef4444;
}

.sc-status-dot-offline {
    background: #ef4444 !important;
}

/* ── Message feedback buttons ────────────────────────────────── */
.sc-feedback {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    padding-left: 2px;
}

.sc-feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.4;
    transition: opacity 0.15s, background 0.15s;
    line-height: 1;
}

.sc-feedback-btn:hover {
    opacity: 0.8;
    background: #f3f4f6;
}

.sc-feedback-btn.sc-feedback-active {
    opacity: 1;
}

.sc-feedback-btn:disabled {
    cursor: default;
    opacity: 0.2;
}

/* ── KB source citations ──────────────────────────────────────── */
.sc-msg-sources {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
    font-style: italic;
}

/* ── Follow-up suggestion chips ──────────────────────────────── */
.sc-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 0 2px;
}

.sc-suggestion-chip {
    padding: 5px 12px;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    background: #fff;
    color: #374151;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.sc-suggestion-chip:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* ── Inline transcript form ────────────────────────────────────── */
.sc-transcript-form {
    display: none;
    padding: 8px 16px;
    border-top: 1px solid #f3f4f6;
    background: #fff;
    flex-shrink: 0;
}

.sc-transcript-form.sc-transcript-form-open {
    display: block;
}

.sc-transcript-form input[type="email"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    margin-bottom: 6px;
    box-sizing: border-box;
}

.sc-transcript-btns {
    display: flex;
    gap: 8px;
}

.sc-transcript-btns button {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid #d1d5db;
}

.sc-transcript-btns #sc-transcript-cancel {
    background: none;
    color: #6b7280;
}

.sc-transcript-btns #sc-transcript-cancel:hover {
    background: #f3f4f6;
}

.sc-transcript-sent {
    font-size: 13px;
    color: #22c55e;
    font-weight: 500;
    margin: 4px 0;
}

/* ── Accessibility: focus-visible outlines ───────────────────── */
#smartchat-widget *:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Mobile */
@media (max-width: 480px) {
    #smartchat-window {
        width: 100% !important;
        height: calc(var(--sc-vh, 1vh) * 100) !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0;
        border: none;
    }

    #smartchat-btn {
        bottom: 16px;
    }

    /* Prevent iOS zoom on input focus (requires font-size >= 16px). */
    #smartchat-input {
        font-size: 16px;
    }

    /* Respect iPhone home-bar safe area. */
    #smartchat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    /* Prevent parent page scroll when at top/bottom of message list. */
    #smartchat-messages {
        overscroll-behavior: contain;
    }

    /* Larger close button touch target on mobile. */
    #smartchat-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sc-pos-bottom-right #smartchat-btn { right: calc(16px + env(safe-area-inset-right, 0px)); }
    .sc-pos-bottom-left #smartchat-btn { left: calc(16px + env(safe-area-inset-left, 0px)); }
}
