/* ========================================
   GameHub AI Chatbot - WORKING VERSION
   Focus: Functionality First
   ======================================== */

:root {
    --ghcb-primary: #6366f1;
    --ghcb-secondary: #1e293b;
    --ghcb-bg-light: #ffffff;
    --ghcb-text-light: #64748b;
    --ghcb-text-dark: #1e293b;
    --ghcb-border: #e2e8f0;
    --ghcb-z-index: 999999;
}

/* ========================================
   Chat Button
   ======================================== */
.ghcb-chat-button {
    position: fixed;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    z-index: var(--ghcb-z-index);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ghcb-position-bottom-right {
    bottom: 24px;
    right: 24px;
}

.ghcb-position-bottom-left {
    bottom: 24px;
    left: 24px;
}

.ghcb-chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.5);
}

.ghcb-button-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ghcb-button-icon-text {
    font-size: 32px;
    line-height: 1;
}

.ghcb-button-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--ghcb-primary);
    animation: ghcb-pulse 2s ease-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes ghcb-pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ========================================
   Chat Window - FIXED STRUCTURE
   ======================================== */
.ghcb-chat-window {
    position: fixed;
    width: 420px;
    max-width: calc(100vw - 32px);
    height: 650px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    z-index: calc(var(--ghcb-z-index) - 1);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    overflow: hidden;
}

.ghcb-chat-window.ghcb-position-bottom-right {
    bottom: 100px;
    right: 24px;
}

.ghcb-chat-window.ghcb-position-bottom-left {
    bottom: 100px;
    left: 24px;
}

.ghcb-chat-window.ghcb-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ========================================
   Chat Header
   ======================================== */
.ghcb-chat-header {
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.ghcb-header-content {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.ghcb-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.ghcb-header-text {
    flex: 1;
    min-width: 0;
}

.ghcb-header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.ghcb-header-subtitle {
    margin: 3px 0 0;
    font-size: 13px;
    opacity: 0.95;
    line-height: 1.3;
}

.ghcb-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.ghcb-header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s ease;
}

.ghcb-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ghcb-header-btn span {
    line-height: 1;
}

/* ========================================
   Chat Messages - ONLY THIS SCROLLS
   ======================================== */
.ghcb-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.ghcb-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ghcb-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ghcb-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* ========================================
   Message
   ======================================== */
.ghcb-message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.ghcb-message-user {
    flex-direction: row-reverse;
}

.ghcb-message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.ghcb-message-bot .ghcb-message-avatar {
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    color: white;
}

.ghcb-message-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 70%;
}

.ghcb-message-user .ghcb-message-wrapper {
    align-items: flex-end;
}

.ghcb-message-bot .ghcb-message-wrapper {
    align-items: flex-start;
}

.ghcb-message-content {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ghcb-text-dark);
    word-wrap: break-word;
}

.ghcb-message-user .ghcb-message-content {
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.ghcb-message-bot .ghcb-message-content {
    border-bottom-left-radius: 6px;
}

.ghcb-message-time {
    font-size: 11px;
    color: var(--ghcb-text-light);
    padding: 0 6px;
}

/* ========================================
   Typing Indicator
   ======================================== */
.ghcb-typing-indicator {
    display: flex;
    gap: 5px;
    padding: 8px 0;
}

.ghcb-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ghcb-primary);
    animation: ghcb-typing 1.4s ease-in-out infinite;
}

.ghcb-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ghcb-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ghcb-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ========================================
   Quick Replies - NO SCROLL
   ======================================== */
.ghcb-quick-replies {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--ghcb-border);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    flex-shrink: 0;
}

.ghcb-quick-reply-btn {
    padding: 12px 16px;
    background: white;
    border: 2px solid var(--ghcb-border);
    border-radius: 12px;
    font-size: 14px;
    color: var(--ghcb-text-dark);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ghcb-quick-reply-btn:hover {
    background: var(--ghcb-primary);
    border-color: var(--ghcb-primary);
    color: white;
    transform: translateY(-2px);
}

/* ========================================
   Chat Input - FIXED HEIGHT DESKTOP
   ======================================== */
.ghcb-chat-input {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--ghcb-border);
    flex-shrink: 0;
}

.ghcb-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #f8fafc;
    border-radius: 12px;
    padding: 10px 12px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
}

.ghcb-input-wrapper:focus-within {
    border-color: var(--ghcb-primary);
    background: white;
}

#ghcb-message-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 15px;
    color: var(--ghcb-text-dark);
    resize: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.4;
    /*padding: 0;*/
    margin: 0;
    overflow-y: hidden;
    min-height: 21px;
    max-height: 100px;
}

#ghcb-message-input::placeholder {
    color: var(--ghcb-text-light);
}

.ghcb-send-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: none;
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.ghcb-send-button:hover:not(:disabled) {
    transform: scale(1.05);
}

.ghcb-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ghcb-send-icon-text {
    line-height: 1;
}

/* ========================================
   Powered By
   ======================================== */
.ghcb-powered-by {
    padding: 10px 20px;
    text-align: center;
    font-size: 11px;
    color: var(--ghcb-text-light);
    background: white;
    border-top: 1px solid var(--ghcb-border);
    flex-shrink: 0;
}

/* ========================================
   Chat Link
   ======================================== */
.ghcb-chat-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.ghcb-chat-link:hover {
    transform: translateY(-2px);
    color: white;
}

/* ========================================
   MOBILE - CRITICAL FIXES
   ======================================== */
@media (max-width: 768px) {
    /* Full screen chat */
    .ghcb-chat-window {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height */
        max-width: 100vw !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
    }
    
    /* Header */
    .ghcb-chat-header {
        padding: 16px 20px;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .ghcb-header-title {
        font-size: 17px;
    }
    
    .ghcb-header-subtitle {
        font-size: 12px;
    }
    
    .ghcb-header-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }
    
    /* Messages - Must scroll properly */
    .ghcb-chat-messages {
        padding: 16px;
        flex: 1;
        overflow-y: auto !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .ghcb-message-wrapper {
        max-width: 80%;
    }
    
    /* Quick Replies - Single column */
    .ghcb-quick-replies {
        padding: 12px 16px;
        grid-template-columns: 1fr;
        gap: 8px;
        flex-shrink: 0;
    }
    
    .ghcb-quick-reply-btn {
        min-height: 44px;
        font-size: 13px;
    }
    
    /* Input - MUST BE CLICKABLE */
    .ghcb-chat-input {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        flex-shrink: 0;
        position: relative;
        z-index: 10;
    }
    
    .ghcb-input-wrapper {
        padding: 10px 12px;
    }
    
    #ghcb-message-input {
        font-size: 16px; /* Prevents zoom on iOS */
        -webkit-appearance: none;
        appearance: none;
    }
    
    .ghcb-send-button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        font-size: 16px;
    }
    
    /* Powered by */
    .ghcb-powered-by {
        padding: 8px 16px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        flex-shrink: 0;
    }
    
    /* Chat button */
    .ghcb-chat-button {
        width: 60px;
        height: 60px;
        bottom: 20px;
    }
    
    .ghcb-button-icon-text {
        font-size: 28px;
    }
    
    /* Hide button when chat open */
    .ghcb-chat-window.ghcb-open ~ .ghcb-chat-button {
        display: none !important;
    }
}

/* ========================================
   Dark Theme
   ======================================== */
body.woodmart-dark-theme {
    --ghcb-bg-light: #1e293b;
    --ghcb-text-dark: #e2e8f0;
    --ghcb-text-light: #94a3b8;
    --ghcb-border: #334155;
}

body.woodmart-dark-theme .ghcb-chat-window,
body.woodmart-dark-theme .ghcb-chat-input,
body.woodmart-dark-theme .ghcb-quick-replies,
body.woodmart-dark-theme .ghcb-powered-by {
    background: #1e293b;
}

body.woodmart-dark-theme .ghcb-chat-messages {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
}

body.woodmart-dark-theme .ghcb-message-content {
    background: #1e293b;
    color: #e2e8f0;
}

body.woodmart-dark-theme .ghcb-message-user .ghcb-message-content {
    background: linear-gradient(135deg, var(--ghcb-primary) 0%, #4f46e5 100%);
    color: white;
}

body.woodmart-dark-theme .ghcb-input-wrapper {
    background: #0f172a;
}

body.woodmart-dark-theme #ghcb-message-input {
    color: #e2e8f0;
}

body.woodmart-dark-theme .ghcb-quick-reply-btn {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

/* ========================================
   Accessibility
   ======================================== */
.ghcb-chat-button:focus,
.ghcb-header-btn:focus,
.ghcb-send-button:focus,
.ghcb-quick-reply-btn:focus {
    outline: 2px solid var(--ghcb-primary);
    outline-offset: 2px;
}

/* ========================================
   Print
   ======================================== */
@media print {
    .ghcb-chat-button,
    .ghcb-chat-window {
        display: none !important;
    }
}

/* Game CTA button wrapper */
.game-cta {
  margin-top: 10px;
}

/* View Game button */
.cta-button {
  display: inline-block;
  width: 100%;
  padding: 10px 16px;
  background: var(--ghcb-primary, #ff3d00);
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  border-radius: 8px;
  line-height: 1.2;
}

/* Tap / click feedback */
.cta-button:active {
  transform: scale(0.97);
}

/* Hover (desktop only) */
@media (hover: hover) {
  .cta-button:hover {
    opacity: 0.9;
  }
}

.login-cta {
  margin-top: 10px;
}

.login-button {
  display: inline-block;
  width: 100%;
  padding: 10px 16px;
  background: #0f172a;
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  border-radius: 8px;
}

.login-button:active {
  transform: scale(0.97);
}
