/**
 * GPW Chat Widget Styles (Compiled CSS)
 * AI-powered dental health assistant
 */

/* Widget variables - using fallback colors, override with theme CSS custom properties if needed */
:root {
    --chat-primary: #0066cc;
    --chat-primary-dark: #004d99;
    --chat-primary-light: #e6f2ff;
    --chat-text: #333;
    --chat-text-light: #666;
    --chat-bg: #fff;
    --chat-bg-light: #f7f7f7;
    --chat-border: #e0e0e0;
    --chat-shadow: rgba(0, 0, 0, 0.15);
    --chat-radius: 12px;
    --chat-radius-sm: 8px;
    --chat-z-index: 9999;
    --chat-transition: 0.3s ease;
}

/* Widget Container */
#gpw-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

#gpw-chat-widget *,
#gpw-chat-widget *::before,
#gpw-chat-widget *::after {
    box-sizing: border-box;
}

/* Toggle Button */
.gpw-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--chat-shadow);
    transition: transform var(--chat-transition), background-color var(--chat-transition), box-shadow var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.gpw-chat-toggle:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
    box-shadow: 0 6px 16px var(--chat-shadow);
}

.gpw-chat-toggle:focus {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

.gpw-chat-toggle:active {
    transform: scale(0.95);
}

.gpw-chat-toggle svg {
    width: 24px;
    height: 24px;
    transition: opacity var(--chat-transition), transform var(--chat-transition);
}

.gpw-chat-toggle .gpw-chat-icon-open {
    opacity: 1;
}

.gpw-chat-toggle .gpw-chat-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

/* Toggle button when chat is open */
.gpw-chat-open .gpw-chat-toggle .gpw-chat-icon-open {
    opacity: 0;
    transform: rotate(90deg);
}

.gpw-chat-open .gpw-chat-toggle .gpw-chat-icon-close {
    opacity: 1;
    transform: rotate(0);
}

/* Chat Panel */
.gpw-chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px); /* accurate on Safari iOS, falls through otherwise */
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: 0 8px 32px var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity var(--chat-transition), transform var(--chat-transition), visibility var(--chat-transition);
}

.gpw-chat-open .gpw-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.gpw-chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.gpw-chat-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}

.gpw-chat-header-icon {
    width: 20px;
    height: 20px;
}

.gpw-chat-minimize {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.8;
    transition: opacity var(--chat-transition), background-color var(--chat-transition);
}

.gpw-chat-minimize:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.gpw-chat-minimize svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Messages Area */
.gpw-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--chat-bg-light);
    scroll-behavior: smooth;
}

.gpw-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.gpw-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.gpw-chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

.gpw-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Message Bubbles */
.gpw-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: gpw-chat-fade-in 0.3s ease;
}

@keyframes gpw-chat-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gpw-chat-message-user {
    align-self: flex-end;
}

.gpw-chat-message-user .gpw-chat-bubble {
    background: var(--chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.gpw-chat-message-assistant {
    align-self: flex-start;
}

.gpw-chat-message-assistant .gpw-chat-bubble {
    background: var(--chat-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.gpw-chat-bubble {
    padding: 12px 16px;
    border-radius: var(--chat-radius-sm);
    word-wrap: break-word;
}

.gpw-chat-bubble p {
    margin: 0 0 8px;
}

.gpw-chat-bubble p:last-child {
    margin-bottom: 0;
}

/* Inline links in messages */
.gpw-chat-inline-link {
    color: var(--chat-primary);
    text-decoration: underline;
}

.gpw-chat-message-user .gpw-chat-inline-link {
    color: #fff;
    text-decoration-color: rgba(255, 255, 255, 0.6);
}

.gpw-chat-inline-link:hover {
    text-decoration-color: currentColor;
}

/* Suggested Links */
.gpw-chat-links {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--chat-bg);
    border-radius: var(--chat-radius-sm);
    border: 1px solid var(--chat-border);
}

.gpw-chat-links-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.gpw-chat-links-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.gpw-chat-link {
    display: inline-block;
    padding: 4px 10px;
    background: var(--chat-primary-light);
    color: var(--chat-primary-dark);
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: background-color var(--chat-transition), color var(--chat-transition);
}

.gpw-chat-link:hover {
    background: var(--chat-primary);
    color: #fff;
}

/* Loading State */
.gpw-chat-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.gpw-chat-typing span {
    width: 8px;
    height: 8px;
    background: var(--chat-text-light);
    border-radius: 50%;
    animation: gpw-chat-typing 1.4s infinite ease-in-out;
}

.gpw-chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.gpw-chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes gpw-chat-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Input Area */
.gpw-chat-input-container {
    padding: 12px 16px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.gpw-chat-form {
    display: flex;
    gap: 8px;
}

.gpw-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--chat-border);
    border-radius: 100px;
    /* 16px (not 14px) — iOS Safari force-zooms the page on focus when an input
       has font-size < 16px, which throws the whole widget off screen and forces
       the user to pinch-zoom back. Keep this >= 16px.

       !important is required because gpw-public.min.css ships a Bootstrap base
       rule `input[type="text"], textarea { font-size: 14px }` whose attribute-
       selector specificity (0,1,1) beats `.gpw-chat-input` (0,1,0). We want
       this rule to win unconditionally regardless of selector order. */
    font-size: 16px !important;
    font-family: inherit;
    color: var(--chat-text);
    background: var(--chat-bg);
    transition: border-color var(--chat-transition), box-shadow var(--chat-transition);
}

.gpw-chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.gpw-chat-input::placeholder {
    color: var(--chat-text-light);
}

.gpw-chat-input:disabled {
    background: var(--chat-bg-light);
    cursor: not-allowed;
}

.gpw-chat-submit {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color var(--chat-transition), transform var(--chat-transition);
}

.gpw-chat-submit:hover:not(:disabled) {
    background: var(--chat-primary-dark);
}

.gpw-chat-submit:active:not(:disabled) {
    transform: scale(0.95);
}

.gpw-chat-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gpw-chat-submit svg {
    width: 18px;
    height: 18px;
}

/* Disclaimer */
.gpw-chat-disclaimer {
    margin-top: 8px;
    text-align: center;
}

.gpw-chat-disclaimer small {
    font-size: 10px;
    color: var(--chat-text-light);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #gpw-chat-widget {
        bottom: 10px;
        right: 10px;
    }

    .gpw-chat-panel {
        width: calc(100vw - 20px);
        /* Override the base rule's max-width too — otherwise the base
           `max-width: calc(100vw - 40px)` clamps the panel narrower than
           the mobile rule intends (20px gutters, not 40px). */
        max-width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        height: calc(100dvh - 100px); /* accurate on Safari iOS */
        bottom: 66px;
        right: 0;
        border-radius: var(--chat-radius-sm);
    }

    .gpw-chat-toggle {
        width: 50px;
        height: 50px;
    }

    .gpw-chat-toggle svg {
        width: 22px;
        height: 22px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .gpw-chat-panel,
    .gpw-chat-toggle,
    .gpw-chat-message,
    .gpw-chat-typing span {
        animation: none;
        transition: none;
    }
}

/* Print - Hide widget */
@media print {
    #gpw-chat-widget {
        display: none !important;
    }
}

/* ============================================
   Position Variants
   ============================================ */

/* Bottom-left: mirror to the left side of the viewport */
#gpw-chat-widget.position-bottom-left {
    right: auto;
    left: 20px;
}
#gpw-chat-widget.position-bottom-left .gpw-chat-panel {
    right: auto;
    left: 0;
}

/* Mid-right: anchor vertically centered on the right edge */
#gpw-chat-widget.position-mid-right {
    bottom: auto;
    top: 60%;
    transform: translateY(-50%);
}
/* Center the panel on the toggle and cap its height so it never clips the
   bottom of the viewport (previously top:0 grew it downward off-screen). */
#gpw-chat-widget.position-mid-right .gpw-chat-panel {
    bottom: auto;
    top: 50%;
    max-height: calc(80vh - 40px);
    max-height: calc(80dvh - 40px); /* accurate on Safari iOS */
    transform: translateY(calc(-50% - 20px)) scale(0.95);
}
#gpw-chat-widget.position-mid-right.gpw-chat-open .gpw-chat-panel {
    transform: translateY(-50%) scale(1);
}

@media (max-width: 480px) {
    #gpw-chat-widget.position-bottom-left {
        left: 10px;
    }
    /* On phones, fall back to the bottom-anchored layout for all variants. */
    #gpw-chat-widget.position-mid-right {
        top: auto;
        bottom: 10px;
        transform: none;
    }
    #gpw-chat-widget.position-mid-right .gpw-chat-panel {
        top: auto;
        bottom: 66px;
        max-height: calc(100vh - 100px);
        max-height: calc(100dvh - 100px); /* accurate on Safari iOS */
        transform: translateY(20px) scale(0.95);
    }
    #gpw-chat-widget.position-mid-right.gpw-chat-open .gpw-chat-panel {
        transform: translateY(0) scale(1);
    }
}
