/* HH Chat Widget — Frontend Styles */

/* ── CSS Variables (overridden inline via JS for dynamic color) ── */
:root {
    --hh-color: #1a73e8;
    --hh-color-dark: #1557b0;
    --hh-color-light: rgba(26, 115, 232, 0.1);
    --hh-radius: 16px;
    --hh-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    --hh-z: 999999;
}

/* ── Widget container ── */
.hh-chat-widget {
    position: fixed;
    z-index: var(--hh-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.hh-chat-bottom-right { bottom: 24px; right: 24px; }
.hh-chat-bottom-left  { bottom: 24px; left: 24px; align-items: flex-start; }

/* ── Toggle button ── */
.hh-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--hh-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    position: relative;
    flex-shrink: 0;
    order: 2;
}

.hh-chat-bottom-left .hh-chat-toggle { order: 0; }

.hh-chat-toggle:hover {
    background: var(--hh-color-dark);
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.hh-chat-toggle:focus-visible {
    outline: 3px solid var(--hh-color);
    outline-offset: 3px;
}

.hh-chat-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hh-chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53935;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ── Chat window ── */
.hh-chat-window {
    width: 360px;
    max-width: calc(100vw - 24px);
    height: 520px;
    max-height: calc(100vh - 100px);
    border-radius: var(--hh-radius);
    box-shadow: var(--hh-shadow);
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 12px;
    order: 1;
    animation: hh-slide-up 0.25s ease;
}

.hh-chat-bottom-left .hh-chat-window {
    margin-bottom: 12px;
}

@keyframes hh-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ── */
.hh-chat-header {
    background: var(--hh-color);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.hh-chat-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.hh-chat-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.hh-chat-header-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hh-chat-header-status {
    font-size: 12px;
    opacity: 0.8;
}

.hh-chat-test-badge {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.hh-chat-header-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.hh-chat-header-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

/* ── Messages area ── */
.hh-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f5f7fb;
    scroll-behavior: smooth;
}

/* Scrollbar */
.hh-chat-messages::-webkit-scrollbar { width: 4px; }
.hh-chat-messages::-webkit-scrollbar-track { background: transparent; }
.hh-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ── Message bubbles ── */
.hh-chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.hh-chat-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.hh-chat-msg-bot {
    align-self: flex-start;
    align-items: flex-start;
}

.hh-chat-msg-system {
    align-self: center;
    max-width: 100%;
}

.hh-chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

/* User bubbles: plain text, preserve newlines */
.hh-chat-msg-user .hh-chat-bubble {
    white-space: pre-wrap;
}

/* Bot bubbles: rendered HTML, no pre-wrap */
.hh-chat-bubble-rich {
    white-space: normal;
}

/* ── Rich text inside bot bubbles ── */
.hh-chat-bubble-rich strong { font-weight: 600; }
.hh-chat-bubble-rich em     { font-style: italic; }

.hh-chat-bubble-rich code {
    background: #f0f0f0;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 90%;
}

.hh-chat-bubble-rich a {
    color: var(--hh-color);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.hh-chat-bubble-rich a:hover { text-decoration: none; }

.hh-chat-bubble-rich ul,
.hh-chat-bubble-rich ol {
    margin: 4px 0 4px 18px;
    padding: 0;
}

.hh-chat-bubble-rich li { margin: 3px 0; }

/* ── Product cards ── */
.hh-product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px 12px;
    text-decoration: none !important;
    color: inherit !important;
    margin: 8px 0;
    transition: box-shadow 0.15s, transform 0.15s;
    max-width: 100%;
    box-sizing: border-box;
}

.hh-product-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
    border-color: var(--hh-color);
}

.hh-product-img {
    width: 68px;
    height: 68px;
    object-fit: cover;
    border-radius: 7px;
    flex-shrink: 0;
    background: #f5f5f5;
    display: block;
}

.hh-product-img-placeholder {
    background: #ebebeb;
}

.hh-product-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.hh-product-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e1e1e;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hh-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--hh-color);
}

.hh-product-cta {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

.hh-chat-msg-user .hh-chat-bubble {
    background: var(--hh-color);
    color: #fff;
    border-radius: 16px 16px 2px 16px;
}

.hh-chat-msg-bot .hh-chat-bubble {
    background: #fff;
    color: #1e1e1e;
    border: 1px solid #e8e8e8;
    border-radius: 16px 16px 16px 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.hh-chat-msg-system .hh-chat-bubble {
    background: none;
    color: #888;
    font-size: 12px;
    padding: 4px 0;
    border: none;
    text-align: center;
}

/* ── Feedback buttons (test mode only) ── */
.hh-chat-msg-feedback {
    display: flex;
    gap: 4px;
    margin-top: 5px;
}

.hh-chat-feedback-btn {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    color: #555;
}

.hh-chat-feedback-btn:hover { background: #f0f0f0; }

.hh-chat-feedback-btn.hh-voted-up {
    background: #d4edda;
    border-color: #1a8a1a;
    color: #1a8a1a;
}

.hh-chat-feedback-btn.hh-voted-down {
    background: #f8d7da;
    border-color: #cc0000;
    color: #cc0000;
}

/* ── Typing indicator ── */
.hh-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 16px 16px 16px 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    width: fit-content;
}

.hh-chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: hh-chat-bounce 0.9s infinite;
}

.hh-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.hh-chat-typing-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes hh-chat-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); background: #888; }
}

/* ── Input area ── */
.hh-chat-input-area {
    flex-shrink: 0;
    border-top: 1px solid #e8e8e8;
    background: #fff;
    padding: 10px 12px 8px;
}

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

.hh-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.15s;
    background: #f9f9f9;
}

.hh-chat-input:focus {
    border-color: var(--hh-color);
    background: #fff;
}

.hh-chat-input::placeholder { color: #aaa; }

.hh-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--hh-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s, transform 0.15s;
}

.hh-chat-send-btn:hover:not(:disabled) {
    background: var(--hh-color-dark);
    transform: scale(1.05);
}

.hh-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.hh-chat-input-footer {
    text-align: center;
    font-size: 11px;
    color: #bbb;
    margin-top: 6px;
}

.hh-chat-input-footer a {
    color: #bbb;
    text-decoration: none;
}

.hh-chat-input-footer a:hover { color: #999; }

/* ── Feedback modal (test mode) ── */
.hh-chat-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--hh-z) + 1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.hh-chat-modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.hh-chat-modal-content h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.hh-chat-modal-content p {
    font-size: 13px;
    color: #666;
    margin: 0 0 14px;
}

.hh-chat-modal-textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    outline: none;
}

.hh-chat-modal-textarea:focus { border-color: var(--hh-color); }

.hh-chat-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    justify-content: flex-end;
}

.hh-chat-modal-btn {
    padding: 8px 18px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.hh-chat-modal-btn:hover { background: #f5f5f5; }

.hh-chat-modal-btn-primary {
    background: var(--hh-color);
    border-color: var(--hh-color);
    color: #fff;
}

.hh-chat-modal-btn-primary:hover { background: var(--hh-color-dark); }

/* ── Mobile responsive ── */
@media (max-width: 480px) {
    .hh-chat-bottom-right,
    .hh-chat-bottom-left {
        bottom: 16px;
        right: 16px;
        left: auto;
    }

    .hh-chat-bottom-left {
        left: 16px;
        right: auto;
    }

    .hh-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        max-height: none;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .hh-chat-window,
    .hh-chat-toggle,
    .hh-chat-typing-dot { animation: none; transition: none; }
}
