/* ═══════════════════════════════════════════════════════════════════
   MSI Chatbot Widget — Styles
   v8.0 — Faster UX, mobile-optimized, responsive, touch-friendly
   ═══════════════════════════════════════════════════════════════════ */

/* ── Chat Bubble (trigger) — Construction worker avatar ─────── */
.chat-bubble {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 950;
    width: 162px;
    height: 162px;
    border-radius: 50%;
    background: none;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.chat-bubble:hover {
    transform: scale(1.1);
}
.chat-bubble:active {
    transform: scale(0.92);
}
.chat-bubble .chat-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transition: transform 0.2s ease;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
}
.chat-bubble:hover .chat-icon {
    transform: scale(1.05);
    filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.45));
}
.chat-bubble--open .chat-icon {
    transform: scale(0.95);
}
.chat-bubble__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-secondary, #e67e22);
    border: 2px solid var(--bg-dark, #1a1a2e);
    display: none;
}
.chat-bubble__badge--visible {
    display: block;
    animation: pulse-badge 1.5s infinite;
}
@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ── Streaming cursor ────────────────────────────────────────────── */
.chat-stream-cursor::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent, #c0392b);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s step-end infinite;
}
@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Chat Panel ──────────────────────────────────────────────────── */
.chat-panel {
    position: fixed;
    bottom: 100px;
    right: 18px;
    z-index: 951;
    width: 380px;
    height: 520px;
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Panel header */
.chat-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    position: relative;
}
.chat-panel__drag-handle {
    display: none;
}
.chat-panel__title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chat-panel__name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-light, #fff);
}
.chat-panel__status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-light-muted, rgba(255,255,255,0.7));
}
.chat-panel__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}
.chat-panel__close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-panel__close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
    -webkit-overflow-scrolling: touch;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Welcome state (centered avatar + pills) ─────────────────────── */
.chat-welcome {
    text-align: center;
    padding: 32px 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.chat-welcome__avatar {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 14px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}
.chat-welcome__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-welcome__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-light, #fff);
    margin: 0 0 6px;
}
.chat-welcome__sub {
    font-size: 0.78rem;
    color: var(--text-light-muted, rgba(255,255,255,0.6));
    margin: 0 0 20px;
    line-height: 1.5;
    padding: 0 8px;
}
.chat-welcome__pills {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.chat-welcome__pill {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 0.8rem;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--text-light-muted, rgba(255,255,255,0.7));
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-welcome__pill:hover {
    border-color: var(--accent, #c0392b);
    color: var(--text-light, #fff);
    background: var(--accent-glow, rgba(192, 57, 43, 0.12));
}
.chat-welcome__pill:active {
    transform: scale(0.98);
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    animation: msg-in 0.25s ease;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg--bot {
    align-self: flex-start;
}
.chat-msg--user {
    align-self: flex-end;
}
.chat-msg__bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-msg--bot .chat-msg__bubble {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-light, #fff);
    border-bottom-left-radius: 4px;
}
.chat-msg--user .chat-msg__bubble {
    background: var(--accent, #c0392b);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Markdown in bot messages */
.chat-msg__bubble a {
    color: var(--accent-secondary, #e67e22);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-msg__bubble strong {
    font-weight: 600;
}

/* Message timestamps */
.chat-msg__time {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 3px;
}
.chat-msg--bot .chat-msg__time {
    align-self: flex-start;
}
.chat-msg--user .chat-msg__time {
    align-self: flex-end;
    color: rgba(255, 255, 255, 0.45);
}

/* Button choices */
.chat-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.chat-btn {
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-light, #fff);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}
.chat-btn:hover {
    border-color: var(--accent, #c0392b);
    background: var(--accent-glow, rgba(192, 57, 43, 0.15));
    color: #fff;
}
.chat-btn:active {
    transform: scale(0.96);
    background: var(--accent-glow, rgba(192, 57, 43, 0.25));
}
.chat-btn--selected {
    background: var(--accent, #c0392b);
    border-color: var(--accent, #c0392b);
    color: #fff;
    pointer-events: none;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}
.chat-typing__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    animation: typing-bounce 1.2s infinite;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Progress bar (lead capture) */
.chat-progress {
    height: 2px;
    background: rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.chat-progress__bar {
    height: 100%;
    width: 0;
    background: var(--accent, #c0392b);
    transition: width 0.4s ease;
    border-radius: 2px;
}

/* Input area */
.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
}
.chat-input__field {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: var(--text-light, #fff);
    font-size: 0.88rem;
    font-family: inherit;
    outline: 2px solid transparent;
    outline-offset: 2px;
    transition: border-color 0.15s;
    resize: none;
    min-height: 36px;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
}
.chat-input__field::placeholder {
    color: rgba(255, 255, 255, 0.3);
}
.chat-input__field:focus {
    border-color: var(--accent, #c0392b);
}
.chat-input__send {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent, #c0392b);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.chat-input__send:hover {
    background: var(--accent-hover, #a93226);
}
.chat-input__send:active {
    transform: scale(0.9);
}
.chat-input__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.chat-input__send svg {
    width: 16px;
    height: 16px;
}
.chat-input__send--loading svg {
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Body scroll lock when chat fullscreen */
body.chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* ── Responsive ──────────────────────────────────────────────────── */

/* Tablet (768px-1024px) — wider panel, touch-friendly targets */
@media (min-width: 481px) and (max-width: 1024px) {
    .chat-panel {
        width: 420px;
        height: 560px;
        bottom: 96px;
    }
    .chat-btn {
        min-height: 44px;
        padding: 10px 18px;
        font-size: 0.85rem;
    }
    .chat-input__field {
        min-height: 44px;
        font-size: 1rem;
    }
    .chat-input__send {
        width: 44px;
        height: 44px;
    }
    .chat-panel__close {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Phone (480px and below) — full-screen takeover */
@media (max-width: 480px) {
    .chat-proactive-tooltip {
        bottom: 100px;
        right: 8px;
        left: 8px;
        max-width: none;
    }
    .chat-chip {
        font-size: 0.72rem;
        padding: 4px 10px;
    }
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100dvh;
        height: calc(var(--chat-vh, 1vh) * 100);
        border-radius: 0;
        max-height: none;
    }
    .chat-panel__header {
        padding-top: calc(12px + env(safe-area-inset-top, 0));
        padding-left: 16px;
        padding-right: 16px;
        padding-bottom: 12px;
    }
    .chat-panel__drag-handle {
        display: block;
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.2);
    }
    .chat-input {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }
    .chat-input__field {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
    }
    .chat-bubble {
        bottom: 6px;
        right: 6px;
        width: 101px;
        height: 101px;
    }
    .chat-bubble .chat-icon {
        width: 101px;
        height: 101px;
    }
    .chat-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }
    .chat-messages {
        padding: 12px 12px 6px;
        gap: 10px;
    }
}

/* ── Suggested question chips ────────────────────────────────────── */
.chat-suggested-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    animation: msg-in 0.25s ease;
}
.chat-chip {
    padding: 5px 12px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: var(--accent-secondary, #e67e22);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-chip:hover {
    border-color: var(--accent-secondary, #e67e22);
    background: rgba(230, 126, 34, 0.1);
}
.chat-chip:active {
    transform: scale(0.96);
}

/* ── CSAT micro-survey ──────────────────────────────────────────── */
.chat-csat {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    align-items: center;
}
.chat-csat__btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-csat__btn:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.05);
}
.chat-csat__btn--selected {
    opacity: 1;
    border-color: var(--accent-secondary, #e67e22);
    background: rgba(230, 126, 34, 0.15);
}
.chat-csat--submitted .chat-csat__btn:not(.chat-csat__btn--selected) {
    opacity: 0.2;
    pointer-events: none;
}

/* ── Human handoff button ───────────────────────────────────────── */
.chat-handoff-btn {
    display: block;
    margin-top: 8px;
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    background: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chat-handoff-btn:hover {
    border-color: var(--accent, #c0392b);
    color: #fff;
    background: rgba(192, 57, 43, 0.1);
}
.chat-handoff-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* ── Proactive tooltip ──────────────────────────────────────────── */
.chat-proactive-tooltip {
    position: fixed;
    bottom: 140px;
    right: 18px;
    z-index: 949;
    max-width: 280px;
    padding: 12px 32px 12px 16px;
    background: var(--bg-dark, #1a1a2e);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-light, #fff);
    font-size: 0.85rem;
    line-height: 1.4;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    animation: tooltip-in 0.3s ease;
}
@keyframes tooltip-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-proactive-tooltip__close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
}
.chat-proactive-tooltip__close:hover {
    color: #fff;
}

/* ── Responsive: Landscape (short viewport) ─────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-panel {
        height: 100dvh;
        height: calc(var(--chat-vh, 1vh) * 100);
        width: 50%;
        min-width: 320px;
        right: 0;
        bottom: 0;
        top: 0;
        left: auto;
        border-radius: 0;
    }
    .chat-panel__header {
        padding: 8px 16px;
    }
    .chat-msg__bubble {
        padding: 6px 10px;
        font-size: 0.82rem;
    }
    .chat-messages {
        padding: 8px 12px;
        gap: 6px;
    }
}
