/* =================================================================
   TSDSI LIVE CHAT — Frontend Widget
   Design: Navy #001849 | Blue #2659a9 | Orange #ce440e
   ================================================================= */

/* ---------- Toggle Button ---------- */
#tsdsi-chat-btn {
    position: fixed;
    bottom: 32px;
    left: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #001849 0%, #2659a9 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 24, 73, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    outline: none;
}

#tsdsi-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 24, 73, 0.55);
}

#tsdsi-chat-btn svg {
    width: 26px;
    height: 26px;
    fill: #ffffff;
    flex-shrink: 0;
}

/* Online / pulsing badge */
#tsdsi-chat-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: tsdsi-pulse 2s infinite;
}

#tsdsi-chat-badge.has-unread {
    background: #ce440e;
    animation: tsdsi-pulse-orange 2s infinite;
}

@keyframes tsdsi-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    70%  { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes tsdsi-pulse-orange {
    0%   { box-shadow: 0 0 0 0 rgba(206, 68, 14, 0.5); }
    70%  { box-shadow: 0 0 0 7px rgba(206, 68, 14, 0); }
    100% { box-shadow: 0 0 0 0 rgba(206, 68, 14, 0); }
}

/* ---------- Chat Panel ---------- */
#tsdsi-chat-panel {
    position: fixed;
    bottom: 104px;
    left: 28px;
    width: 320px;
    height: 480px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-radius: 14px;
    box-shadow: 0 8px 40px rgba(0, 24, 73, 0.22), 0 2px 8px rgba(0, 24, 73, 0.1);
    border: 1px solid rgba(38, 89, 169, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 99998;
    overflow: hidden;

    /* Hidden by default */
    opacity: 0;
    transform: translateY(18px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#tsdsi-chat-panel.tcp-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ---------- Header ---------- */
.tcp-header {
    background: linear-gradient(135deg, #001849 0%, #1a3a7a 60%, #2659a9 100%);
    color: #ffffff;
    padding: 14px 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.tcp-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tcp-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.tcp-header-info h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #fff;
    line-height: 1.2;
}

.tcp-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    margin-right: 4px;
    animation: tsdsi-pulse 2.5s infinite;
}

.tcp-online-label {
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
}

.tcp-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.75);
    padding: 4px;
    border-radius: 6px;
    line-height: 1;
    transition: color 0.2s, background 0.2s;
    font-size: 18px;
}

.tcp-close-btn:hover {
    color: #ffffff;
    background: rgba(255,255,255,0.15);
}

/* ---------- Subhead ---------- */
.tcp-subhead {
    background: linear-gradient(135deg, #1a3a7a 0%, #2659a9 100%);
    color: rgba(255,255,255,0.85);
    font-size: 11px;
    text-align: center;
    padding: 5px 12px;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

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

.tcp-messages::-webkit-scrollbar {
    width: 4px;
}
.tcp-messages::-webkit-scrollbar-track {
    background: transparent;
}
.tcp-messages::-webkit-scrollbar-thumb {
    background: rgba(38,89,169,0.25);
    border-radius: 4px;
}

/* ---------- Message bubbles ---------- */
.tcp-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.tcp-msg.from-visitor {
    align-self: flex-end;
    background: #2659a9;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.tcp-msg.from-agent {
    align-self: flex-start;
    background: #ffffff;
    color: #001849;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,24,73,0.07);
}

.tcp-msg.from-ai {
    align-self: flex-start;
    background: linear-gradient(135deg, #f0f0ff 0%, #ede9ff 100%);
    color: #2d2d6b;
    border: 1px solid #c5c3ee;
    border-bottom-left-radius: 4px;
}

.tcp-ai-chip {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: #5b5bd6;
    color: #fff;
    padding: 1px 5px;
    border-radius: 4px;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.tcp-msg-time {
    font-size: 10px;
    opacity: 0.58;
    margin-top: 3px;
    display: block;
    text-align: right;
}

.from-agent .tcp-msg-time,
.from-ai .tcp-msg-time {
    text-align: left;
}

/* ---------- Typing indicator ---------- */
.tcp-typing {
    display: none;
    align-self: flex-start;
    font-size: 12px;
    color: #64748b;
    padding: 6px 10px;
    font-style: italic;
}

.tcp-typing.visible {
    display: block;
}

/* ---------- Start Form ---------- */
.tcp-start-form {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    border-top: 1px solid #e8eef7;
}

.tcp-start-form input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #d1ddf0;
    border-radius: 8px;
    font-size: 13px;
    color: #001849;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    background: #f8fafd;
}

.tcp-start-form input:focus {
    border-color: #2659a9;
    background: #fff;
}

.tcp-start-form input::placeholder {
    color: #94a3b8;
}

.tcp-start-btn {
    background: linear-gradient(135deg, #001849, #2659a9);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    letter-spacing: 0.3px;
}

.tcp-start-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* ---------- Input Row (post-session) ---------- */
.tcp-input-row {
    display: none;
    padding: 10px 12px;
    border-top: 1px solid #e8eef7;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #f8fafd;
}

.tcp-input-row.visible {
    display: flex;
}

.tcp-msg-input {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid #d1ddf0;
    border-radius: 10px;
    font-size: 13px;
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 100px;
    font-family: inherit;
    color: #001849;
    background: #ffffff;
    transition: border-color 0.2s;
    line-height: 1.4;
    box-sizing: border-box;
}

.tcp-msg-input:focus {
    border-color: #2659a9;
}

.tcp-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #2659a9;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

.tcp-send-btn:hover {
    background: #001849;
    transform: scale(1.05);
}

.tcp-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}

/* ---------- Mobile Responsive ---------- */
@media (max-width: 480px) {
    #tsdsi-chat-panel {
        width: calc(100vw - 32px);
        left: 16px;
        right: 16px;
        bottom: 96px;
        height: 72vh;
        max-height: 520px;
    }

    #tsdsi-chat-btn {
        left: 16px;
        bottom: 24px;
    }
}
