/* ============================================================
   Florence Chatbot Widget
   ============================================================ */

/* Launcher button */
#sherlock-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2147483646;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--sherlock-header-color, #1e3a5f);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    transition: background 0.2s, transform 0.2s;
}
#sherlock-launcher:hover,
#sherlock-launcher.sherlock-active {
    background: #2a5298;
    transform: scale(1.05);
}

/* Chat panel */
#sherlock-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 2147483647;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}
#sherlock-panel.sherlock-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}
#sherlock-panel.sherlock-expanded {
    width: min(680px, calc(100vw - 48px));
    height: min(820px, calc(100vh - 64px));
    max-height: calc(100vh - 64px);
}

/* Header */
#sherlock-header {
    background: var(--sherlock-header-color, #1e3a5f);
    color: #fff;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    letter-spacing: 0.01em;
}
#sherlock-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
#sherlock-expand,
#sherlock-close {
    background: transparent;
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex: 0 0 auto;
}
#sherlock-expand {
    font-size: 0;
    opacity: 0.9;
}
#sherlock-close {
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
}
#sherlock-expand:hover,
#sherlock-close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.12);
}

.sherlock-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#sherlock-close:focus-visible,
#sherlock-expand:focus-visible,
#sherlock-send:focus-visible,
#sherlock-gate-agree:focus-visible,
#sherlock-gate-disagree:focus-visible,
#sherlock-launcher:focus-visible,
#sherlock-input:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

/* Disclaimer banner */
#sherlock-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 7px 12px;
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    color: #92400e;
    font-size: 11.5px;
    line-height: 1.45;
    flex-shrink: 0;
}
#sherlock-disclaimer span {
    flex: 1;
}
#sherlock-disclaimer-dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #b45309;
    font-size: 16px;
    line-height: 1;
    padding: 0 0 0 4px;
    cursor: pointer;
    opacity: 0.6;
    margin-top: -1px;
}
#sherlock-disclaimer-dismiss:hover {
    opacity: 1;
}

#sherlock-gate,
#sherlock-chat-shell {
    flex: 1;
    min-height: 0;
}
#sherlock-gate[hidden],
#sherlock-chat-shell[hidden] {
    display: none !important;
}
#sherlock-chat-shell {
    display: flex;
    flex-direction: column;
}
#sherlock-gate {
    display: flex;
    flex-direction: column;
    background: #fff;
}
#sherlock-gate-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 18px 18px 14px;
}
#sherlock-gate-image {
    width: auto;
    max-width: 100%;
    max-height: 120px;
    height: auto;
    display: block;
    margin: 0 auto 18px;
    border-radius: 12px;
    object-fit: contain;
    background: #fff;
}
#sherlock-gate-content {
    color: #111827;
    font-size: 14px;
    line-height: 1.65;
}
#sherlock-gate-content p {
    margin: 0 0 16px;
}
#sherlock-gate-content p:last-child {
    margin-bottom: 0;
}
#sherlock-gate-content strong,
#sherlock-gate-content b {
    font-weight: 700;
}
#sherlock-gate-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 0 16px;
    border-radius: 12px;
}
#sherlock-gate-actions {
    display: flex;
    gap: 12px;
    padding: 16px 18px 18px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}
#sherlock-gate-agree,
#sherlock-gate-disagree {
    flex: 1;
    min-height: 44px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#sherlock-gate-agree {
    background: #4356b7;
    color: #fff;
    border: 1px solid #4356b7;
}
#sherlock-gate-agree:hover {
    background: #394aa1;
    border-color: #394aa1;
}
#sherlock-gate-disagree {
    background: #fff;
    color: #4356b7;
    border: 1px solid #4356b7;
}
#sherlock-gate-disagree:hover {
    background: #eef2ff;
}

/* Messages area */
#sherlock-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

/* Individual message wrapper */
.sherlock-msg {
    display: flex;
    max-width: 86%;
}
.sherlock-msg-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.sherlock-msg--user {
    align-self: flex-end;
    justify-content: flex-end;
}
.sherlock-msg--assistant,
.sherlock-msg--error {
    align-self: flex-start;
}
.sherlock-msg--assistant {
    align-items: flex-end;
    gap: 8px;
}

.sherlock-avatar {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 8px;
    overflow: hidden;
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
}
.sherlock-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* Bubble */
.sherlock-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}
.sherlock-msg--user .sherlock-bubble {
    background: var(--sherlock-user-bubble-color, #1e3a5f);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.sherlock-msg--assistant .sherlock-bubble {
    background: #fff;
    color: #1a1a1a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}
/* Link pill buttons */
.sherlock-link-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 9px 2px 7px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    color: #1e3a5f;
    text-decoration: none;
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    margin: 2px 1px;
    transition: background 0.15s, border-color 0.15s;
}
.sherlock-link-pill:hover {
    background: #f0f4f8;
    border-color: #94a3b8;
    color: #1e3a5f;
    text-decoration: none;
}

/* Message text layout */
.sherlock-line {
    line-height: 1.55;
}
.sherlock-line + .sherlock-line {
    margin-top: 2px;
}
.sherlock-gap {
    height: 8px;
}
.sherlock-list {
    margin: 4px 0;
    padding-left: 16px;
    list-style: disc;
}
.sherlock-list li {
    line-height: 1.5;
    margin-bottom: 3px;
}
.sherlock-list li:last-child {
    margin-bottom: 0;
}

.sherlock-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    align-self: flex-end;
    margin-top: 6px;
}
.sherlock-feedback-btn {
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.sherlock-feedback-btn:hover {
    background: #f1f5f9;
    color: #64748b;
}
.sherlock-feedback-btn.active {
    color: #2563eb;
}
.sherlock-feedback[hidden] {
    display: none;
}
.sherlock-feedback-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
.sherlock-msg--error .sherlock-bubble {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-bottom-left-radius: 4px;
}
.sherlock-msg--limit .sherlock-bubble {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
    border-bottom-left-radius: 4px;
    font-style: italic;
}
#sherlock-input.sherlock-ended {
    background: #f8f9fa;
    color: #94a3b8;
    cursor: not-allowed;
}

/* Links inside bubbles */
.sherlock-bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.sherlock-msg--user .sherlock-bubble a { color: #bfdbfe; }

/* Typing indicator */
.sherlock-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    min-width: 52px;
}
.sherlock-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    display: inline-block;
    animation: sherlock-bounce 1.2s infinite ease-in-out;
}
.sherlock-typing span:nth-child(2) { animation-delay: 0.2s; }
.sherlock-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sherlock-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* Footer / input */
#sherlock-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}
#sherlock-input {
    flex: 1;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13.5px;
    line-height: 1.4;
    font-family: inherit;
    color: #1a1a1a;
    outline: none;
    transition: border-color 0.15s;
    max-height: 120px;
    overflow-y: auto;
}
#sherlock-input:focus {
    border-color: #2a5298;
    box-shadow: 0 0 0 2px rgba(42,82,152,0.15);
}
#sherlock-send {
    background: var(--sherlock-header-color, #1e3a5f);
    border: none;
    border-radius: 8px;
    color: #fff;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
#sherlock-send:hover  { background: #2a5298; }
#sherlock-send:disabled,
#sherlock-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* Scrollbar styling */
#sherlock-messages::-webkit-scrollbar { width: 5px; }
#sherlock-messages::-webkit-scrollbar-track { background: transparent; }
#sherlock-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

/* Mobile */
@media (max-width: 480px) {
    #sherlock-launcher {
        right: 12px;
        bottom: 16px;
    }
}

@media (max-width: 640px), (max-height: 720px) {
    #sherlock-panel {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-width: none;
        height: min(calc(100dvh - 16px), 680px);
        max-height: calc(100dvh - 16px);
        border-radius: 16px;
    }
    #sherlock-panel.sherlock-expanded {
        width: auto;
        height: min(calc(100dvh - 16px), 680px);
        max-height: calc(100dvh - 16px);
    }
    #sherlock-header {
        padding: 12px 14px;
    }
    #sherlock-expand {
        display: none;
    }
    #sherlock-messages {
        padding: 12px 10px;
    }
    .sherlock-msg {
        max-width: 94%;
    }
    .sherlock-bubble {
        font-size: 14px;
        line-height: 1.6;
        padding: 11px 13px;
    }
    #sherlock-footer {
        gap: 10px;
        padding: 10px;
        align-items: center;
    }
    #sherlock-input {
        min-height: 44px;
        max-height: 132px;
        font-size: 16px;
        border-radius: 12px;
        padding: 11px 13px;
    }
    #sherlock-send {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }
    #sherlock-gate-scroll {
        padding: 16px 16px 12px;
    }
    #sherlock-gate-actions {
        padding: 14px 16px 16px;
    }
}
