/* ==========================================
   Chatbot Styles - Vintage Newspaper Theme
   mattburd.com
   ========================================== */

/* Chat Button (uses your custom PNG image) */
#chatbot-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    cursor: pointer;
    z-index: var(--z-popover, 500);
    transition: transform var(--transition-base, 300ms ease), 
                filter var(--transition-base, 300ms ease);
    border: none;
    background: transparent;
    padding: 0;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    border-radius: 50%; /* Circular for smooth glow */
    overflow: visible; /* Allow glow to extend beyond */
    animation: chat-button-pulse 4s ease-in-out infinite;
}

/* Notification Bubble */
#chatbot-notification-bubble {
    position: fixed;
    bottom: 96px;
    right: 20px;
    background: #ffffff;
    color: #1a1a1a;
    padding: 12px 16px;
    border: 2px solid #2a2a2a;
    border-radius: 12px;
    font-family: var(--font-body, Helvetica, sans-serif);
    font-size: var(--text-sm, 0.875rem);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: var(--z-popover, 500);
    max-width: 200px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

/* Bubble arrow pointing to button */
#chatbot-notification-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #2a2a2a;
}

#chatbot-notification-bubble::before {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 21px;
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 9px solid #ffffff;
    z-index: 1;
}

/* Bubble states */
#chatbot-notification-bubble.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    pointer-events: none;
}

#chatbot-notification-bubble.show {
    opacity: 1;
    transform: scale(1) translateY(0);
    animation: bubble-bounce 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Bounce animation for bubble */
@keyframes bubble-bounce {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    50% {
        transform: scale(1.05) translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Dark mode bubble */
body.dark-mode #chatbot-notification-bubble {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #2a2a2a;
}

body.dark-mode #chatbot-notification-bubble::after {
    border-top-color: #2a2a2a;
}

body.dark-mode #chatbot-notification-bubble::before {
    border-top-color: #ffffff;
}

#chatbot-button img {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 50%; /* Circular mask */
    object-fit: cover; /* Crop to circle */
}

#chatbot-button:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 8px 20px rgba(0, 255, 136, 0.4));
}

#chatbot-button:active {
    transform: scale(0.95);
}

/* Continuous pulse animation matching header logo */
@keyframes chat-button-pulse {
    0%, 100% {
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15))
                drop-shadow(0 0 20px rgba(0, 255, 136, 0.3));
    }
    50% {
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15))
                drop-shadow(0 0 40px rgba(0, 255, 136, 0.6));
    }
}

/* Pulse animation for first-time visitors (more dramatic) */
@keyframes pulse-attention {
    0%, 100% {
        transform: scale(1);
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    }
    50% {
        transform: scale(1.15);
        filter: drop-shadow(0 8px 24px rgba(0, 255, 136, 0.6));
    }
}

#chatbot-button.pulse {
    animation: pulse-attention 2s ease-in-out 3;
}

/* Chat Modal Overlay */
#chatbot-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: var(--z-modal, 400);
    opacity: 0;
    transition: opacity var(--transition-base, 300ms ease);
    backdrop-filter: blur(4px);
}

#chatbot-overlay.active {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
}

/* Chat Window */
#chatbot-window {
    background: #ffffff;
    border: 3px solid #2a2a2a;
    border-radius: 6px;
    width: 90%;
    max-width: 500px;
    height: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

#chatbot-overlay.active #chatbot-window {
    transform: scale(1);
    opacity: 1;
}

/* Same style in dark mode */
body.dark-mode #chatbot-window {
    background: #ffffff;
    border-color: #2a2a2a;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

/* Chat Header - Same for both modes */
#chatbot-header {
    background: #2a2a2a !important;
    color: #ffffff !important;
    padding: 16px 20px;
    border-bottom: 3px solid #2a2a2a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body.dark-mode #chatbot-header {
    background: #2a2a2a !important;
    color: #ffffff !important;
    border-bottom-color: #2a2a2a;
}

#chatbot-title {
    font-family: var(--font-headline, Georgia, serif);
    font-size: 1.36rem;
    font-weight: var(--font-bold, 700);
    letter-spacing: 0.05em;
    margin: 0;
    color: #ffffff !important; /* White in light theme */
    /* Override global H2 styles */
    text-transform: none !important; 
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

body.dark-mode #chatbot-title {
    color: #ffffff;
}

/* Counter text */
#chatbot-counter {
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 0.85rem;
    opacity: 1; /* Changed from 0.9 to prevent grey appearance */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 6px;
    color: inherit; /* Inherits from parent header color */
}

#chatbot-close {
    background: transparent;
    border: 2px solid #ffffff;
    border-radius: 6px;
    color: #ffffff;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: var(--text-xl, 1.25rem);
    transition: all 0.2s ease;
    font-weight: bold;
    line-height: 1;
}

#chatbot-close:hover {
    background: #ffffff;
    border-color: #ffffff;
    color: #2a2a2a;
    transform: rotate(90deg);
}

body.dark-mode #chatbot-close {
    border-color: #ffffff;
    color: #ffffff;
}

body.dark-mode #chatbot-close:hover {
    background: #ffffff;
    border-color: #ffffff;
    color: #2a2a2a;
}

/* Chat Messages Container */
#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: #faf8f3;
    position: relative;
}

/* Paper texture overlay - matches website */
#chatbot-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.03) 2px,
            rgba(0, 0, 0, 0.03) 4px
        );
}

/* Ensure messages appear above texture */
#chatbot-messages > * {
    position: relative;
    z-index: 2;
    isolation: isolate;
}

body.dark-mode #chatbot-messages {
    background: #faf8f3;
}

/* Individual Message */
.chatbot-message {
    display: flex;
    gap: 12px;
    animation: messageSlide 0.3s ease;
    align-items: flex-start;
    margin-bottom: 16px;
    min-height: fit-content;
    flex-shrink: 0;
}

/* Remove margin from last message */
.chatbot-message:last-child {
    margin-bottom: 0;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.user {
    justify-content: flex-end;
}

.chatbot-message-content {
    max-width: 75%;
    padding: 12px 16px;
    border: 2px solid var(--ink-black, #1a1a1a);
    border-radius: 6px;
    font-family: var(--font-body, Helvetica, sans-serif);
    font-size: var(--text-sm, 0.875rem);
    line-height: var(--leading-normal, 1.6);
    word-wrap: break-word;
    overflow-wrap: break-word;
    display: block;
    min-height: 20px;
}

/* Assistant message styling - light gray bubble */
.chatbot-message.assistant .chatbot-message-content {
    background: #f5f5f5;
    border-color: #e0e0e0;
    color: #1a1a1a;
}

/* User message styling - dark gray bubble */
.chatbot-message.user .chatbot-message-content {
    background: #2a2a2a;
    color: #ffffff;
    border-color: #2a2a2a;
}

/* Same in dark mode */
body.dark-mode .chatbot-message.assistant .chatbot-message-content {
    background: #f5f5f5;
    border-color: #e0e0e0;
    color: #1a1a1a;
}

body.dark-mode .chatbot-message.user .chatbot-message-content {
    background: #2a2a2a;
    color: #ffffff;
    border-color: #2a2a2a;
}

/* Typing Indicator */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    width: fit-content;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #2a2a2a;
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

body.dark-mode .chatbot-typing {
    background: #f5f5f5;
    border-color: #e0e0e0;
}

body.dark-mode .chatbot-typing span {
    background: #2a2a2a;
}

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

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

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Chat Input Area */
#chatbot-input-area {
    padding: 16px 20px;
    border-top: 2px solid #505050;
    background: #3d3d3d;
    display: flex;
    gap: 12px;
}

body.dark-mode #chatbot-input-area {
    background: #3d3d3d;
    border-top-color: #505050;
}

#chatbot-input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #505050;
    border-radius: 6px;
    background: #ffffff;
    color: #1a1a1a;
    font-family: var(--font-body, Helvetica, sans-serif);
    font-size: var(--text-sm, 0.875rem);
    resize: none;
    min-height: 40px;
    max-height: 100px;
    transition: border-color 0.2s ease;
}

#chatbot-input:focus {
    outline: none;
    border-color: #2a2a2a;
    box-shadow: 0 0 0 1px #2a2a2a;
}

#chatbot-input::placeholder {
    color: #808080;
}

body.dark-mode #chatbot-input {
    background: #ffffff;
    border-color: #505050;
    color: #1a1a1a;
}

body.dark-mode #chatbot-input:focus {
    border-color: #2a2a2a;
    box-shadow: 0 0 0 1px #2a2a2a;
}

body.dark-mode #chatbot-input::placeholder {
    color: #808080;
}

#chatbot-send {
    padding: 10px 20px;
    background: #ffffff;
    color: #1a1a1a;
    border: 2px solid #ffffff;
    border-radius: 6px;
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: var(--text-sm, 0.875rem);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}

/* Sweep animation effect */
#chatbot-send::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg, 
        transparent, 
        rgba(255, 255, 255, 0.3), 
        transparent
    );
    transition: left 0.5s ease;
}

#chatbot-send:hover::before {
    left: 100%;
}

#chatbot-send:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border-color: #2a2a2a;
}

#chatbot-send:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#chatbot-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

body.dark-mode #chatbot-send {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #ffffff;
}

body.dark-mode #chatbot-send:hover:not(:disabled) {
    border-color: #2a2a2a;
}

/* Error Message */
.chatbot-error {
    background: #ff0055;
    color: white;
    padding: 12px 16px;
    border: 2px solid #cc0044;
    border-radius: 6px;
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: var(--text-sm, 0.875rem);
    text-align: center;
    margin: 0 20px;
}

/* Limit Reached Message */
.chatbot-limit-reached {
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    padding: 20px;
    margin: 20px;
    text-align: center;
    font-family: var(--font-body, Helvetica, sans-serif);
}

.chatbot-limit-reached h3 {
    font-family: var(--font-headline, Georgia, serif);
    font-size: var(--text-lg, 1.125rem);
    margin-bottom: 8px;
    color: #2a2a2a;
}

.chatbot-limit-reached p {
    font-size: var(--text-sm, 0.875rem);
    color: #3d3d3d;
}

body.dark-mode .chatbot-limit-reached {
    background: #f5f5f5;
    border-color: #e0e0e0;
}

body.dark-mode .chatbot-limit-reached h3 {
    color: #2a2a2a;
}

body.dark-mode .chatbot-limit-reached p {
    color: #3d3d3d;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    #chatbot-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    #chatbot-notification-bubble {
        bottom: 78px;
        right: 16px;
        max-width: 160px;
        font-size: 0.8rem;
        padding: 10px 14px;
    }
    
    #chatbot-notification-bubble::after {
        right: 16px;
    }
    
    #chatbot-notification-bubble::before {
        right: 17px;
    }
    
    #chatbot-window {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100vh;
        border: none;
        border-radius: 0;
    }
    
    #chatbot-header {
        padding: 14px 16px;
    }
    
    #chatbot-title {
        font-size: 1rem !important;
    }
    
    #chatbot-counter {
        font-size: 0.7rem;
        margin-top: 4px;
    }
    
    #chatbot-close {
        width: 28px;
        height: 28px;
        font-size: 1.1rem;
    }
    
    #chatbot-messages {
        padding: 16px 12px;
        gap: 12px;
    }
    
    .chatbot-message-content {
        max-width: 85%;
        font-size: 0.9rem;
        padding: 10px 14px;
    }
    
    #chatbot-input-area {
        padding: 12px;
        gap: 8px;
    }
    
    #chatbot-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 10px;
    }
    
    #chatbot-send {
        padding: 10px 16px;
        font-size: 0.75rem;
    }
}

/* Accessibility */
#chatbot-button:focus-visible,
#chatbot-send:focus-visible,
#chatbot-close:focus-visible {
    outline: 3px solid var(--retro-glow, #00ff88);
    outline-offset: 2px;
}

/* Scrollbar styling */
#chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

#chatbot-messages::-webkit-scrollbar-track {
    background: #faf8f3;
}

#chatbot-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 4px;
}

#chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #2a2a2a;
}

body.dark-mode #chatbot-messages::-webkit-scrollbar-track {
    background: #faf8f3;
}

body.dark-mode #chatbot-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
}

body.dark-mode #chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #2a2a2a;
}
