/**
 * TapNSave AI Sales Agent — Chat Widget Stylesheet
 * -------------------------------------------------
 * All classes are prefixed with .tns-chat- or .tns-msg- to ensure
 * zero collision with existing Bootstrap / TapNSave CSS.
 *
 * Brand tokens used:
 *   Primary gradient : linear-gradient(135deg, #ff5a5f, #ff006a)
 *   Dark             : #0d0d0d
 *   Gray             : #4b5563
 *   White            : #ffffff
 */

/* ============================================================
   CSS CUSTOM PROPERTIES
   Scoped to the widget root to avoid polluting global :root
   ============================================================ */
#tns-chat-panel,
#tns-chat-toggle {
    --tns-primary-from   : #ff5a5f;
    --tns-primary-to     : #ff006a;
    --tns-gradient       : linear-gradient(135deg, var(--tns-primary-from), var(--tns-primary-to));
    --tns-dark           : #0d0d0d;
    --tns-gray           : #4b5563;
    --tns-gray-light     : #f3f4f6;
    --tns-gray-border    : #e5e7eb;
    --tns-white          : #ffffff;
    --tns-user-bubble-bg : #0d0d0d;
    --tns-ai-bubble-bg   : #f3f4f6;
    --tns-shadow         : 0 10px 40px rgba(0, 0, 0, 0.18);
    --tns-radius-lg      : 16px;
    --tns-radius-sm      : 10px;
    --tns-font           : system-ui, -apple-system, "Segoe UI", sans-serif;
    --tns-transition     : 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --tns-panel-width    : 350px;
    --tns-panel-height   : 500px;
}

/* ============================================================
   FLOATING TOGGLE BUTTON
   ============================================================ */
.tns-chat-toggle {
    /* Positioning — stacked above WhatsApp button (WA: bottom 20px h48px + 8px gap = 76px) */
    position   : fixed;
    bottom     : 76px;
    right      : 20px;
    z-index    : 9998;

    /* Size & Shape — slightly smaller to match WhatsApp icon */
    width      : 48px;
    height     : 48px;
    border-radius: 50%;

    /* Visuals */
    background : var(--tns-gradient);
    color      : var(--tns-white);
    border     : none;
    cursor     : pointer;
    box-shadow : 0 4px 16px rgba(255, 0, 106, 0.4);

    /* Layout */
    display        : flex;
    align-items    : center;
    justify-content: center;

    /* Animation */
    transition : transform var(--tns-transition), box-shadow var(--tns-transition);
}

.tns-chat-toggle:hover {
    transform  : scale(1.08);
    box-shadow : 0 6px 24px rgba(255, 0, 106, 0.55);
}

.tns-chat-toggle:focus-visible {
    outline        : 3px solid #ff006a;
    outline-offset : 3px;
}

/* "Open" state — slight scale to indicate active */
.tns-chat-toggle--open {
    transform : scale(1.04);
}

/* ============================================================
   CHAT PANEL
   ============================================================ */
.tns-chat-panel {
    /* Positioning — sits above the toggle (toggle: bottom 76px h48px + 8px gap = 132px) */
    position      : fixed;
    bottom        : 132px;
    right         : 20px;
    z-index       : 9999;

    /* Size */
    width         : var(--tns-panel-width);
    height        : var(--tns-panel-height);

    /* Layout */
    display       : flex;
    flex-direction: column;
    overflow      : hidden;

    /* Visuals */
    background    : var(--tns-white);
    border-radius : var(--tns-radius-lg);
    box-shadow    : var(--tns-shadow);
    border        : 1px solid var(--tns-gray-border);

    /* Hidden by default — animated in via JS class */
    opacity       : 0;
    pointer-events: none;
    transform     : translateY(16px) scale(0.97);
    transition    : opacity var(--tns-transition), transform var(--tns-transition);
}

/* Panel open state */
.tns-chat-panel--open {
    opacity       : 1;
    pointer-events: all;
    transform     : translateY(0) scale(1);
}

/* ============================================================
   HEADER
   ============================================================ */
.tns-chat-header {
    display         : flex;
    align-items     : center;
    justify-content : space-between;
    padding         : 14px 16px;
    background      : var(--tns-gradient);
    color           : var(--tns-white);
    flex-shrink     : 0;     /* never compress */
}

.tns-chat-header-info {
    display    : flex;
    align-items: center;
    gap        : 10px;
}

/* Circular avatar showing "AI" text */
.tns-chat-avatar {
    width           : 36px;
    height          : 36px;
    border-radius   : 50%;
    background      : rgba(255, 255, 255, 0.25);
    display         : flex;
    align-items     : center;
    justify-content : center;
    font-size       : 11px;
    font-weight     : 700;
    font-family     : var(--tns-font);
    letter-spacing  : 0.5px;
    flex-shrink     : 0;
}

.tns-chat-header-name {
    font-family : var(--tns-font);
    font-size   : 14px;
    font-weight : 700;
    line-height : 1.2;
}

.tns-chat-header-status {
    font-family : var(--tns-font);
    font-size   : 11px;
    opacity     : 0.85;
    display     : flex;
    align-items : center;
    gap         : 4px;
}

/* Pulsing online indicator dot */
.tns-status-dot {
    display      : inline-block;
    width        : 7px;
    height       : 7px;
    border-radius: 50%;
    background   : #4ade80;
    animation    : tns-pulse 2s infinite;
}

@keyframes tns-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.85); }
}

/* Close button inside header */
.tns-chat-close-btn {
    background    : transparent;
    border        : none;
    color         : var(--tns-white);
    cursor        : pointer;
    padding       : 4px;
    border-radius : 6px;
    display       : flex;
    align-items   : center;
    opacity       : 0.85;
    transition    : opacity 0.15s;
}

.tns-chat-close-btn:hover {
    opacity : 1;
}

.tns-chat-close-btn:focus-visible {
    outline        : 2px solid rgba(255,255,255,0.8);
    outline-offset : 2px;
}

/* ============================================================
   MESSAGES AREA
   ============================================================ */
.tns-chat-messages {
    flex       : 1;
    overflow-y : auto;
    padding    : 14px 12px;
    display    : flex;
    flex-direction: column;
    gap        : 4px;

    /* Thin scrollbar */
    scrollbar-width     : thin;
    scrollbar-color     : var(--tns-gray-border) transparent;
}

.tns-chat-messages::-webkit-scrollbar       { width: 4px; }
.tns-chat-messages::-webkit-scrollbar-track { background: transparent; }
.tns-chat-messages::-webkit-scrollbar-thumb { background: var(--tns-gray-border); border-radius: 99px; }

/* ── Message wrapper — controls alignment ── */
.tns-msg-wrapper {
    display       : flex;
    flex-direction: column;
    max-width     : 82%;
    gap           : 3px;
    margin-bottom : 6px;
}

.tns-msg-user { align-self: flex-end; align-items: flex-end; }
.tns-msg-ai   { align-self: flex-start; align-items: flex-start; }

/* ── Message bubble ── */
.tns-msg-bubble {
    padding      : 10px 13px;
    border-radius: var(--tns-radius-sm);
    font-family  : var(--tns-font);
    font-size    : 13.5px;
    line-height  : 1.5;
    word-break   : break-word;
}

/* User bubble — dark pill */
.tns-bubble-user {
    background    : var(--tns-user-bubble-bg);
    color         : var(--tns-white);
    border-bottom-right-radius: 3px;
}

/* AI bubble — light pill */
.tns-bubble-ai {
    background    : var(--tns-ai-bubble-bg);
    color         : var(--tns-dark);
    border-bottom-left-radius: 3px;
}

/* ── Timestamp ── */
.tns-msg-time {
    font-size : 10.5px;
    color     : #9ca3af;
    font-family: var(--tns-font);
    padding   : 0 2px;
}

/* ============================================================
   TYPING INDICATOR  (three bouncing dots)
   ============================================================ */
.tns-typing {
    display    : flex;
    align-items: center;
    gap        : 5px;
    padding    : 12px 14px;
    min-width  : 52px;
}

.tns-dot {
    width        : 7px;
    height       : 7px;
    border-radius: 50%;
    background   : var(--tns-gray);
    animation    : tns-bounce 1.2s infinite ease-in-out;
}

.tns-dot:nth-child(1) { animation-delay: 0s; }
.tns-dot:nth-child(2) { animation-delay: 0.2s; }
.tns-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ============================================================
   QUICK ACTION CHIPS
   ============================================================ */
.tns-chat-quick-actions {
    display        : none;   /* shown via JS after welcome message */
    flex-wrap      : wrap;
    gap            : 6px;
    padding        : 8px 12px;
    border-top     : 1px solid var(--tns-gray-border);
    flex-shrink    : 0;
}

.tns-chat-chip {
    background    : var(--tns-white);
    border        : 1.5px solid #ff006a;
    color         : #ff006a;
    padding       : 5px 12px;
    border-radius : 999px;
    font-size     : 12px;
    font-family   : var(--tns-font);
    font-weight   : 600;
    cursor        : pointer;
    transition    : background 0.15s, color 0.15s;
    white-space   : nowrap;
}

.tns-chat-chip:hover {
    background : #ff006a;
    color      : var(--tns-white);
}

.tns-chat-chip:focus-visible {
    outline        : 2px solid #ff006a;
    outline-offset : 2px;
}

/* ============================================================
   INPUT AREA
   ============================================================ */
.tns-chat-input-area {
    border-top  : 1px solid var(--tns-gray-border);
    padding     : 10px 12px 8px;
    flex-shrink : 0;
    background  : var(--tns-white);
}

.tns-chat-input-row {
    display    : flex;
    align-items: center;
    gap        : 8px;
}

.tns-chat-input {
    flex        : 1;
    border      : 1.5px solid var(--tns-gray-border);
    border-radius: 999px;
    padding     : 9px 16px;
    font-size   : 13.5px;
    font-family : var(--tns-font);
    color       : var(--tns-dark);
    background  : var(--tns-white);
    outline     : none;
    transition  : border-color 0.15s;
}

.tns-chat-input::placeholder { color: #9ca3af; }

.tns-chat-input:focus {
    border-color: #ff006a;
}

/* Send button */
.tns-chat-send-btn {
    width           : 38px;
    height          : 38px;
    border-radius   : 50%;
    background      : var(--tns-gradient);
    border          : none;
    color           : var(--tns-white);
    cursor          : pointer;
    display         : flex;
    align-items     : center;
    justify-content : center;
    flex-shrink     : 0;
    transition      : transform 0.15s, box-shadow 0.15s;
    box-shadow      : 0 2px 8px rgba(255, 0, 106, 0.35);
}

.tns-chat-send-btn:hover:not(:disabled) {
    transform  : scale(1.08);
    box-shadow : 0 4px 12px rgba(255, 0, 106, 0.5);
}

.tns-chat-send-btn:disabled {
    opacity : 0.5;
    cursor  : default;
}

.tns-chat-send-btn:focus-visible {
    outline        : 2px solid #ff006a;
    outline-offset : 2px;
}

/* Powered-by note */
.tns-chat-footer-note {
    text-align  : center;
    font-size   : 10.5px;
    color       : #9ca3af;
    font-family : var(--tns-font);
    margin      : 5px 0 0;
}

/* ============================================================
   MOBILE RESPONSIVENESS
   Breakpoint matches WhatsApp button mobile override (max-width: 480px).
   Math: WA → bottom:16px h:44px → Chat toggle → bottom:68px (16+44+8) h:44px
         → Panel → bottom:120px (68+44+8)
   ============================================================ */
@media (max-width: 480px) {
    .tns-chat-toggle {
        right  : 12px;
        bottom : 68px;   /* WA: 16px + 44px height + 8px gap */
        width  : 44px;
        height : 44px;
    }

    .tns-chat-panel {
        width  : calc(100vw - 24px);
        right  : 12px;
        bottom : 120px;  /* toggle: 68px + 44px height + 8px gap */
        height : 72vh;   /* relative height so panel fits on any phone */
    }
}

/* Height safety: on very short screens keep the panel inside the viewport */
@media (max-height: 680px) {
    .tns-chat-panel {
        height : calc(100vh - 150px);
    }
}

/* ============================================================
   DESIGN RECOMMENDATION CARDS
   ============================================================ */
.tns-design-cards-header {
    font-family  : var(--tns-font);
    font-size    : 12px;
    font-weight  : 600;
    color        : var(--tns-gray);
    margin-bottom: 8px;
    padding      : 0 2px;
}

.tns-design-cards-list {
    display        : flex;
    gap            : 8px;
    overflow-x     : auto;
    padding-bottom : 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--tns-gray-border) transparent;
}

.tns-design-cards-list::-webkit-scrollbar       { height: 3px; }
.tns-design-cards-list::-webkit-scrollbar-track { background: transparent; }
.tns-design-cards-list::-webkit-scrollbar-thumb { background: var(--tns-gray-border); border-radius: 99px; }

.tns-design-card {
    flex-shrink   : 0;
    width         : 95px;
    background    : var(--tns-white);
    border        : 1.5px solid var(--tns-gray-border);
    border-radius : var(--tns-radius-sm);
    padding       : 8px 6px;
    display       : flex;
    flex-direction: column;
    align-items   : center;
    gap           : 4px;
    transition    : border-color 0.15s, box-shadow 0.15s;
}

.tns-design-card:hover {
    border-color : #ff006a;
    box-shadow   : 0 2px 8px rgba(255, 0, 106, 0.15);
}

.tns-design-card-img {
    width        : 64px;
    height       : 64px;
    object-fit   : cover;
    border-radius: 6px;
    background   : var(--tns-gray-light);
}

.tns-design-card-title {
    font-family : var(--tns-font);
    font-size   : 10.5px;
    font-weight : 600;
    color       : var(--tns-dark);
    text-align  : center;
    line-height : 1.3;
    word-break  : break-word;
    max-height  : 28px;
    overflow    : hidden;
}

.tns-design-card-price {
    font-family: var(--tns-font);
    font-size  : 11px;
    color      : #ff006a;
    font-weight: 700;
}

.tns-design-card-btn {
    background   : var(--tns-gradient);
    color        : var(--tns-white);
    border       : none;
    border-radius: 999px;
    padding      : 4px 10px;
    font-size    : 10.5px;
    font-family  : var(--tns-font);
    font-weight  : 600;
    cursor       : pointer;
    transition   : opacity 0.15s;
    margin-top   : 2px;
}

.tns-design-card-btn:hover {
    opacity: 0.88;
}

.tns-design-timer {
    font-family: var(--tns-font);
    font-size  : 10.5px;
    color      : #9ca3af;
    margin-top : 6px;
    text-align : center;
    padding    : 0 2px;
}
