/* ==========================================================================
   TonPulse AI Chatbot — Frontend Widget Styles
   ========================================================================== */

#tonpulse-ai-root * {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* --------------------------------------------------------------------------
   CSS custom properties (overridden by JS for primary color)
-------------------------------------------------------------------------- */
#tonpulse-ai-root {
    --tc-primary:      #4F46E5;
    --tc-primary-dark: #4338CA;
    --tc-primary-rgb:  79, 70, 229;
    --tc-white:        #FFFFFF;
    --tc-gray-50:      #F9FAFB;
    --tc-gray-100:     #F3F4F6;
    --tc-gray-200:     #E5E7EB;
    --tc-gray-400:     #9CA3AF;
    --tc-gray-600:     #4B5563;
    --tc-gray-800:     #1F2937;
    --tc-text:         #1F2937;
    --tc-user-text:    #FFFFFF;
    --tc-header-text:  #FFFFFF;
    --tc-radius-lg:    16px;
    --tc-shadow-xl:    0 20px 60px rgba(0,0,0,.18), 0 8px 20px rgba(0,0,0,.12);
}

/* --------------------------------------------------------------------------
   Floating launcher button
-------------------------------------------------------------------------- */
.tc-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 58px;
    height: 58px;
    background: var(--tc-primary);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(var(--tc-primary-rgb), 0.45);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
    outline: none;
}

.tc-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(var(--tc-primary-rgb), 0.55);
}

.tc-launcher:focus-visible {
    outline: 3px solid rgba(var(--tc-primary-rgb), .4);
    outline-offset: 3px;
}

.tc-launcher--left { right: auto; left: 24px; }

.tc-launcher__icon,
.tc-launcher__close {
    position: absolute;
    top: 50%;
    left: 50%;
    transition: opacity .2s, transform .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tc-launcher__icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

.tc-launcher__close {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6) rotate(-30deg);
}

.tc-launcher.is-open .tc-launcher__icon {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6) rotate(30deg);
}

.tc-launcher.is-open .tc-launcher__close {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

.tc-launcher svg {
    width: 26px;
    height: 26px;
    fill: var(--tc-white);
    display: block;
}

/* Unread badge */
.tc-unread-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 18px;
    height: 18px;
    background: #EF4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    line-height: 1;
    opacity: 0;
    transform: scale(0);
    transition: opacity .2s, transform .2s;
}

.tc-unread-badge.is-visible {
    opacity: 1;
    transform: scale(1);
}

/* --------------------------------------------------------------------------
   Chat window
-------------------------------------------------------------------------- */
.tc-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 9998;
    width: 380px;
    max-height: 580px;
    background: var(--tc-white);
    border-radius: var(--tc-radius-lg);
    box-shadow: var(--tc-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    opacity: 0;
    transform: translateY(16px) scale(.97);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.4,.64,1);
}

.tc-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.tc-window--left { right: auto; left: 24px; }

/* Full-screen on mobile */
@media (max-width: 480px) {
    .tc-window {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    .tc-window--left { left: 0; }
    .tc-launcher { bottom: 20px; right: 20px; }
}

/* --------------------------------------------------------------------------
   Window header
-------------------------------------------------------------------------- */
.tc-header {
    background: var(--tc-primary);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.tc-header__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.tc-header__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.tc-header__avatar svg {
    width: 20px;
    height: 20px;
    fill: rgba(255,255,255,.85);
}

.tc-header__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.tc-header__name {
    font-size: 14px;
    font-weight: 700;
    color: var(--tc-header-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.tc-header__status {
    font-size: 11px;
    color: var(--tc-header-text);
    opacity: .78;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 0;
}

.tc-header__status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #4ADE80;
    border-radius: 50%;
    flex-shrink: 0;
}

.tc-header__close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tc-header-text);
    opacity: .82;
    padding: 4px;
    border-radius: 4px;
    transition: color .15s, background .15s;
    line-height: 1;
    flex-shrink: 0;
}

.tc-header__close:hover {
    color: var(--tc-white);
    background: rgba(255,255,255,.15);
}

.tc-header__close svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

/* --------------------------------------------------------------------------
   Messages area
-------------------------------------------------------------------------- */
.tc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.tc-messages::-webkit-scrollbar { width: 4px; }
.tc-messages::-webkit-scrollbar-track { background: transparent; }
.tc-messages::-webkit-scrollbar-thumb { background: var(--tc-gray-200); border-radius: 2px; }

/* --------------------------------------------------------------------------
   Individual messages
-------------------------------------------------------------------------- */
.tc-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: tc-msg-in .2s ease;
}

@keyframes tc-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tc-msg--bot { flex-direction: row; }
.tc-msg--user { flex-direction: row-reverse; }

.tc-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tc-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.tc-msg__avatar svg {
    width: 14px;
    height: 14px;
    fill: var(--tc-white);
}

.tc-msg__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tc-msg--user .tc-msg__avatar { display: none; }

.tc-msg__bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

#tonpulse-ai-root .tc-msg--bot .tc-msg__bubble {
    background: var(--tc-gray-100);
    color: var(--tc-text) !important;
    border-bottom-left-radius: 4px;
}

#tonpulse-ai-root .tc-msg--user .tc-msg__bubble {
    background: var(--tc-primary);
    color: var(--tc-user-text) !important;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

/* Square bubble variant */
.tc-bubble-square .tc-msg__bubble { border-radius: 10px; }

/* Circle / pill bubble variant — fully rounded, no sharp tail corner */
.tc-bubble-circle .tc-msg__bubble { border-radius: 20px; }

/* Links inside bot messages */
.tc-msg__bubble a {
    color: var(--tc-primary);
    text-decoration: underline;
    font-weight: 500;
}

.tc-msg--user .tc-msg__bubble a { color: rgba(255,255,255,.9); }

/* --------------------------------------------------------------------------
   Source links chips
-------------------------------------------------------------------------- */
.tc-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.tc-source-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(var(--tc-primary-rgb), .1);
    color: var(--tc-primary);
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s;
    border: 1px solid rgba(var(--tc-primary-rgb), .2);
}

.tc-source-chip:hover {
    background: rgba(var(--tc-primary-rgb), .18);
    text-decoration: none;
}

.tc-source-chip svg {
    width: 11px;
    height: 11px;
    fill: currentColor;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Typing indicator
-------------------------------------------------------------------------- */
.tc-typing {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tc-typing__dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--tc-gray-100);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.tc-typing__dot {
    width: 7px;
    height: 7px;
    background: var(--tc-gray-400);
    border-radius: 50%;
    animation: tc-bounce 1.2s ease infinite;
}

.tc-typing__dot:nth-child(2) { animation-delay: .15s; }
.tc-typing__dot:nth-child(3) { animation-delay: .3s; }

@keyframes tc-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-5px); }
}

/* --------------------------------------------------------------------------
   Welcome + suggested questions
-------------------------------------------------------------------------- */
.tc-welcome {
    text-align: center;
    padding: 8px 0 4px;
}

.tc-welcome p {
    font-size: 13.5px;
    color: var(--tc-gray-600);
    margin: 0;
    line-height: 1.5;
}

.tc-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.tc-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    border: 1.5px solid var(--tc-gray-200);
    border-radius: 10px;
    background: var(--tc-white);
    cursor: pointer;
    font-size: 13px;
    color: var(--tc-gray-700);
    transition: border-color .15s, background .15s;
    line-height: 1.4;
}

.tc-suggestion:hover {
    border-color: var(--tc-primary);
    background: rgba(var(--tc-primary-rgb), .04);
    color: var(--tc-primary);
}

/* --------------------------------------------------------------------------
   Input area
-------------------------------------------------------------------------- */
.tc-input-area {
    padding: 12px;
    border-top: 1px solid var(--tc-gray-200);
    background: var(--tc-white);
    flex-shrink: 0;
}

.tc-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--tc-gray-50);
    border: 1.5px solid var(--tc-gray-200);
    border-radius: 12px;
    padding: 8px 8px 8px 14px;
    transition: border-color .15s, box-shadow .15s;
}

.tc-input-row:focus-within {
    border-color: var(--tc-primary);
    box-shadow: 0 0 0 3px rgba(var(--tc-primary-rgb), .12);
}

.tc-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13.5px;
    color: var(--tc-gray-800);
    outline: none;
    resize: none;
    min-height: 22px;
    max-height: 120px;
    line-height: 1.5;
    font-family: inherit;
    padding: 0;
}

.tc-input::placeholder { color: var(--tc-gray-400); }

.tc-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--tc-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
    color: var(--tc-white);
}

.tc-send-btn:hover  { background: var(--tc-primary-dark); }
.tc-send-btn:active { transform: scale(.93); }

.tc-send-btn:disabled {
    background: var(--tc-gray-200);
    cursor: not-allowed;
    transform: none;
}

.tc-send-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: var(--tc-white);
    display: block;
}

.tc-send-btn:disabled svg { stroke: var(--tc-gray-400); }

/* --------------------------------------------------------------------------
   Footer branding
-------------------------------------------------------------------------- */
.tc-footer {
    padding: 4px 12px 6px;
    text-align: center;
    flex-shrink: 0;
    font-size: 9px;
    color: var(--tc-gray-400);
}

.tc-footer a {
    font-size: 9px;
    color: var(--tc-gray-400);
    text-decoration: none;
}

.tc-footer a:hover { color: var(--tc-gray-600); }

/* --------------------------------------------------------------------------
   Error state
-------------------------------------------------------------------------- */
.tc-error-msg {
    font-size: 12.5px;
    color: #B91C1C;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 8px;
    padding: 8px 12px;
    text-align: center;
    margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Pre-chat contact form
-------------------------------------------------------------------------- */
#tonpulse-ai-root .tc-prechat {
    padding: 20px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
}

#tonpulse-ai-root .tc-prechat__title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--tc-gray-800);
}

#tonpulse-ai-root .tc-prechat__subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--tc-gray-600);
    line-height: 1.5;
}

#tonpulse-ai-root .tc-prechat__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#tonpulse-ai-root .tc-prechat__label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--tc-gray-800);
}

#tonpulse-ai-root .tc-prechat__input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--tc-gray-200);
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--tc-gray-800);
    background: #fff;
    outline: none;
    transition: border-color .15s;
}

#tonpulse-ai-root .tc-prechat__input:focus {
    border-color: var(--tc-primary);
    box-shadow: 0 0 0 3px rgba(var(--tc-primary-rgb), .12);
}

#tonpulse-ai-root .tc-prechat__error {
    font-size: 12px;
    color: #B91C1C;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 6px;
    padding: 6px 10px;
}

#tonpulse-ai-root .tc-prechat__submit {
    background: var(--tc-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    width: 100%;
    margin-top: 4px;
}

#tonpulse-ai-root .tc-prechat__submit:hover { background: var(--tc-primary-dark); }
#tonpulse-ai-root .tc-prechat__submit:disabled { opacity: .6; cursor: not-allowed; }
