/* Author: Tobalt — https://tobalt.lt */

.tcb-root {
    --tcb-accent: #00ab8e;          /* VMB brand green (vmb.lt primary) */
    --tcb-accent-text: #ffffff;
    --tcb-bot-bg: #f1f3f5;
    --tcb-bot-text: #212529;
    --tcb-border: #dee2e6;
    --tcb-radius: 12px;
    --tcb-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #212529;
    box-sizing: border-box;
}
.tcb-root *, .tcb-root *::before, .tcb-root *::after { box-sizing: inherit; }

/* Launcher button */
.tcb-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tcb-accent);
    color: var(--tcb-accent-text);
    border: none;
    box-shadow: var(--tcb-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    z-index: 2147483646;
}
.tcb-launcher:hover  { transform: scale(1.06); }
.tcb-launcher:focus  { outline: 3px solid #ffd54f; outline-offset: 2px; }
.tcb-launcher.is-open { transform: scale(0); }

/* Dialog */
.tcb-dialog {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: #ffffff;
    border-radius: var(--tcb-radius);
    box-shadow: var(--tcb-shadow);
    display: flex;
    flex-direction: column;
    z-index: 2147483647;
    overflow: hidden;
    animation: tcb-slide-in 0.2s ease;
}
@keyframes tcb-slide-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tcb-dialog[hidden] { display: none; }

/* Header */
.tcb-header {
    background: var(--tcb-accent);
    color: var(--tcb-accent-text);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.tcb-title-block { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.tcb-bot-avatar  { display: flex; align-items: center; }
.tcb-header .tcb-title { font-size: 15px; font-weight: 600; margin: 0; color: var(--tcb-accent-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Provider toggle */
.tcb-provider-toggle {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    padding: 2px;
}
.tcb-provider-btn {
    background: transparent;
    color: var(--tcb-accent-text);
    border: none;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}
.tcb-provider-btn:hover            { background: rgba(255, 255, 255, 0.15); }
.tcb-provider-btn.is-active        { background: rgba(255, 255, 255, 0.95); color: var(--tcb-accent); }
.tcb-provider-btn:focus            { outline: 2px solid #ffd54f; outline-offset: 2px; }

/* Close button */
.tcb-close {
    background: transparent;
    border: none;
    color: var(--tcb-accent-text);
    cursor: pointer;
    width: 36px;
    height: 36px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s ease;
}
.tcb-close:hover { background: rgba(255, 255, 255, 0.15); }
.tcb-close:focus { outline: 2px solid #ffd54f; outline-offset: 2px; }

/* Messages area */
.tcb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafbfc;
}

.tcb-msg { display: flex; }
.tcb-msg-user { justify-content: flex-end; }
.tcb-msg-bot  { flex-direction: column; align-items: flex-start; }
.tcb-msg-bot > .tcb-bubble,
.tcb-msg-bot > .tcb-sources,
.tcb-msg-bot > .tcb-msg-meta { max-width: 100%; }

.tcb-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.tcb-msg-user .tcb-bubble {
    background: var(--tcb-accent);
    color: var(--tcb-accent-text);
    border-bottom-right-radius: 4px;
}
.tcb-msg-bot .tcb-bubble {
    background: var(--tcb-bot-bg);
    color: var(--tcb-bot-text);
    border-bottom-left-radius: 4px;
}

.tcb-msg-meta {
    font-size: 11px;
    color: #495057;
    margin-top: 4px;
    padding: 0 8px;
}

/* Inline links rendered from markdown [text](url) inside bot bubbles */
.tcb-msg-bot .tcb-bubble .tcb-inline-link {
    color: var(--tcb-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    word-break: break-word;
}
.tcb-msg-bot .tcb-bubble .tcb-inline-link:hover {
    text-decoration-thickness: 2px;
}
.tcb-msg-bot .tcb-bubble .tcb-inline-link:focus-visible {
    outline: 2px solid var(--tcb-accent);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Sources sit BELOW the bubble as a separate block, not glued to it.
   No top border, no internal padding — let each card breathe on its own. */
.tcb-sources {
    margin-top: 12px;
    padding: 0;
    width: 100%;
}
.tcb-sources-heading {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #495057;
    margin-bottom: 6px;
}
.tcb-sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: tcb-source;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tcb-source-item {
    counter-increment: tcb-source;
    margin: 0;
    padding: 0;
}
/* Each source is a contained, clickable card. The whole row gets the bg —
   wrapped text stays inside, hanging-indented under the title. */
.tcb-source {
    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 8px;
    align-items: baseline;
    background: var(--tcb-bot-bg);
    border: 1px solid var(--tcb-border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--tcb-accent);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.tcb-source::before {
    content: "[" counter(tcb-source) "]";
    color: #495057;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}
.tcb-source-text {
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
}
.tcb-source-arrow {
    color: #495057;
    font-size: 12px;
    opacity: 0.7;
    align-self: center;
}
.tcb-source:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    text-decoration: underline;
    text-decoration-color: var(--tcb-accent);
    text-underline-offset: 2px;
}
.tcb-source:hover .tcb-source-text { text-decoration: underline; }
.tcb-source:focus-visible {
    outline: 2px solid var(--tcb-accent);
    outline-offset: 2px;
}

/* Typing indicator */
.tcb-typing { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.tcb-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #adb5bd;
    animation: tcb-pulse 1.4s infinite ease-in-out;
}
.tcb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.tcb-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tcb-pulse {
    0%, 60%, 100% { opacity: 0.3; }
    30%           { opacity: 1.0; }
}

/* Quick starts */
.tcb-quick-starts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.tcb-chip {
    background: #ffffff;
    color: var(--tcb-accent);
    border: 1px solid var(--tcb-accent);
    border-radius: 999px;
    min-height: 36px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}
.tcb-chip:hover { background: var(--tcb-bot-bg); }
.tcb-chip:focus { outline: 2px solid var(--tcb-accent); outline-offset: 2px; }

/* Error banner */
.tcb-error {
    background: #fff5f5;
    color: #c92a2a;
    border: 1px solid #ffc9c9;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
}

/* Input area */
.tcb-input-area {
    border-top: 1px solid var(--tcb-border);
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #ffffff;
    flex-shrink: 0;
}
.tcb-input {
    flex: 1;
    border: 1px solid var(--tcb-border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    resize: none;
    max-height: 96px;
    overflow-y: auto;
    font-family: inherit;
    color: inherit;
}
.tcb-input:focus { outline: 2px solid var(--tcb-accent); outline-offset: 1px; }
.tcb-input:disabled { background: #f8f9fa; cursor: not-allowed; }
.tcb-send {
    background: var(--tcb-accent);
    color: var(--tcb-accent-text);
    border: none;
    border-radius: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}
.tcb-send:hover    { opacity: 0.9; }
.tcb-send:focus    { outline: 2px solid #ffd54f; outline-offset: 2px; }
.tcb-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile */
@media (max-width: 600px) {
    .tcb-launcher { bottom: 16px; right: 16px; }
    .tcb-dialog {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    /* Tighter spacing — reclaim screen real estate on phones */
    .tcb-header        { padding: 10px 12px; gap: 8px; }
    .tcb-messages      { padding: 12px; gap: 8px; }
    .tcb-bubble        { padding: 9px 12px; max-width: 85%; }
    .tcb-input-area    { padding: 8px 10px; gap: 6px; }
    .tcb-sources       { margin-top: 10px; padding: 0; }
    .tcb-input         { font-size: 16px; }    /* iOS Safari skips zoom-on-focus when ≥16px */
    .tcb-msg-bot .tcb-bubble,
    .tcb-msg-user .tcb-bubble { font-size: 15px; line-height: 1.45; }
    .tcb-quick-starts  { gap: 4px; }
    .tcb-chip          { font-size: 13px; padding: 7px 12px; }
    /* Tighter source cards on mobile */
    .tcb-source        { padding: 7px 9px; font-size: 13px; }
}

/* Theme-override safety net — defeat host-theme `button:hover { color: ... }` rules
   that beat our (0,1,0) base selectors on hover. (0,2,0) here beats (0,1,1). */
.tcb-root .tcb-launcher,
.tcb-root .tcb-launcher:hover,
.tcb-root .tcb-close,
.tcb-root .tcb-close:hover,
.tcb-root .tcb-send,
.tcb-root .tcb-send:hover,
.tcb-root .tcb-provider-btn,
.tcb-root .tcb-provider-btn:hover { color: var(--tcb-accent-text); }
.tcb-root .tcb-provider-btn.is-active,
.tcb-root .tcb-provider-btn.is-active:hover { color: var(--tcb-accent); }
.tcb-root .tcb-chip,
.tcb-root .tcb-chip:hover { color: var(--tcb-accent); }
.tcb-root .tcb-source,
.tcb-root .tcb-source:hover { color: var(--tcb-accent); }

/* Screen reader only */
.tcb-root .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}
