/* Label Vier AI Chat Widget */

#labelvier-ai-chat-widget {
    --labelvier-chat-color: #0073aa;
    --labelvier-chat-color-dark: color-mix(in srgb, var(--labelvier-chat-color, #0073aa) 80%, #000);
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
}

/* Isolate icons from theme svg/button rules (max-width:100%, flex-shrink,
   fill overrides) that can shrink them to zero or strip their stroke. */
#labelvier-ai-chat-widget svg {
    display: block;
    width: auto;
    height: auto;
    max-width: none;
    flex: none;
    fill: none;
    stroke: currentColor;
}

/* Neutralise theme button bleed (min-height ~5.3rem, min-width, gradients,
   uppercase) that otherwise blows up e.g. the header via the close button. */
#labelvier-ai-chat-widget button {
    min-height: 0;
    min-width: 0;
    padding: 0;
    text-transform: none;
    background-image: none;
    box-sizing: border-box;
}

/* Theme buttons inject icon fonts (e.g. FontAwesome) via ::before/::after —
   strip that on every widget button so no stray icon/content leaks in. */
#labelvier-ai-chat-widget button::before,
#labelvier-ai-chat-widget button::after {
    content: none;
    font-family: inherit;
}

#labelvier-ai-chat-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--labelvier-chat-color, #0073aa);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    transition: background 0.2s, transform 0.2s;
    margin-left: auto;
}

#labelvier-ai-chat-toggle:hover {
    background: var(--labelvier-chat-color-dark, #005c88);
    transform: scale(1.05);
}

#labelvier-ai-chat-panel {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 48px);
    max-height: 520px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#labelvier-ai-chat-panel[hidden] {
    display: none;
}

#labelvier-ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--labelvier-chat-color, #0073aa);
    color: #fff;
}

#labelvier-ai-chat-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
}

#labelvier-ai-chat-new {
    margin-top: auto;         /* pin to the bottom of the messages area */
    align-self: center;
    flex: none;
    background: none;
    border: none;
    cursor: pointer;
    color: #6b7280;
    font-size: 12px;
    text-decoration: underline;
    padding: 4px;
}

#labelvier-ai-chat-new:hover {
    color: var(--labelvier-chat-color, #0073aa);
}

#labelvier-ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    opacity: 0.85;
    transition: opacity 0.15s;
}

#labelvier-ai-chat-close:hover {
    opacity: 1;
}

#labelvier-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
}

.labelvier-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    word-break: break-word;
}

.labelvier-chat-msg.user {
    align-self: flex-end;
    background: var(--labelvier-chat-color, #0073aa);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.labelvier-chat-msg.bot {
    align-self: flex-start;
    background: #f0f0f0;
    color: #1d2327;
    border-bottom-left-radius: 4px;
}

.labelvier-chat-msg.bot.thinking {
    color: #6b7280;
    font-style: italic;
}

/* The theme's global `a { color: inherit; }` reset otherwise makes links
   inside a bot reply (e.g. handout/pdf links) inherit the bubble's text
   color, so they look like plain, unclickable text instead of a link. */
.labelvier-chat-msg a {
    color: var(--labelvier-chat-color, #0073aa);
    text-decoration: underline;
}

/* Normalise the AI's HTML so theme heading/list styles don't blow up sizes
   or spacing inside the bubble. Font family is intentionally inherited. */
.labelvier-chat-msg h1,
.labelvier-chat-msg h2,
.labelvier-chat-msg h3,
.labelvier-chat-msg h4,
.labelvier-chat-msg h5,
.labelvier-chat-msg h6 {
    font-size: 1.05em;
    line-height: 1.3;
    font-weight: 700;
    letter-spacing: normal;
    text-transform: none;
    margin: 0.8em 0 0.3em;
}

.labelvier-chat-msg h1 { font-size: 1.25em; }
.labelvier-chat-msg h2 { font-size: 1.15em; }
.labelvier-chat-msg h3 { font-size: 1.05em; }

.labelvier-chat-msg p {
    margin: 0.5em 0;
}

.labelvier-chat-msg ul,
.labelvier-chat-msg ol {
    margin: 0.5em 0;
    padding-left: 1.4em;
}

.labelvier-chat-msg li {
    margin: 0.2em 0;
}

.labelvier-chat-msg > :first-child {
    margin-top: 0;
}

.labelvier-chat-msg > :last-child {
    margin-bottom: 0;
}

/* Reused by the wp-admin "Chats" log tab: same bubble classes, own
   scrollable container instead of the fixed widget panel. */
.labelvier-chatlog-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    max-width: 640px;
    max-height: 640px;
    overflow-y: auto;
}

.labelvier-chat-sources {
    margin-top: 8px;
    font-size: 12px;
    opacity: 0.75;
}

.labelvier-chat-sources a {
    display: block;
    color: inherit;
    text-decoration: underline;
}

#labelvier-ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #e0e0e0;
    background: #fafafa;
}

#labelvier-ai-chat-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

#labelvier-ai-chat-input:focus {
    border-color: var(--labelvier-chat-color, #0073aa);
}

#labelvier-ai-chat-form button[type="submit"] {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--labelvier-chat-color, #0073aa);
    color: #fff;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

#labelvier-ai-chat-form button[type="submit"]:hover {
    background: var(--labelvier-chat-color-dark, #005c88);
}

/* Left-hand placement (default is bottom-right). */
#labelvier-ai-chat-widget.labelvier-pos-left {
    right: auto;
    left: 24px;
}

#labelvier-ai-chat-widget.labelvier-pos-left #labelvier-ai-chat-toggle {
    margin-left: 0;
    margin-right: auto;
}

#labelvier-ai-chat-widget.labelvier-pos-left #labelvier-ai-chat-panel {
    right: auto;
    left: 0;
}

@media (max-width: 480px) {
    #labelvier-ai-chat-panel {
        width: calc(100vw - 32px);
        right: -12px;
    }

    #labelvier-ai-chat-widget.labelvier-pos-left #labelvier-ai-chat-panel {
        right: auto;
        left: -12px;
    }
}
