/*
  =================================
  CHATBOT STYLES - FIXED & IMPROVED
  Hope AI Mental Health Chatbot
  =================================
*/

/* CSS Variables */
:root { 
    --primary-green: #16a083; 
    --light-green: #e6f7f4; 
    --accent-teal: #117964; 
    --text-dark: #2d3748; 
    --text-light: #718096; 
    --bg-light: #f7fafc; 
    --white: #ffffff; 
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --border-radius: 1rem;
    --border-radius-lg: 1.5rem;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Reset */
* {
    box-sizing: border-box;
}

/*
  =================================
  Chatbot Button - FIXED
  =================================
*/
#chatbot-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 65px;
    height: 65px;
    z-index: 1100;
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal)) !important;
    border: 3px solid var(--white) !important;
    box-shadow: var(--shadow-lg) !important;
    transition: var(--transition) !important;
    cursor: pointer;
    padding: 0 !important;
}

#chatbot-btn:hover {
    transform: translateY(-2px) scale(1.05) !important;
    box-shadow: var(--shadow-xl) !important;
    background: linear-gradient(135deg, var(--accent-teal), var(--primary-green)) !important;
}

#chatbot-btn:active {
    transform: translateY(0) scale(1) !important;
}

#chatbot-btn:focus-visible {
    outline: 3px solid var(--primary-green);
    outline-offset: 4px;
}

/* Attention-catching pulse animation - IMPROVED */
@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 0 0 rgba(22, 160, 131, 0.7); 
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 0 0 15px rgba(22, 160, 131, 0); 
    }
}

#chatbot-btn.attention { 
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; 
}

/*
  =================================
  Greeting Popup - FIXED
  =================================
*/
#greeting-popup {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 320px;
    max-width: calc(100vw - 60px);
    z-index: 1100;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

#greeting-popup .card-body {
    background: linear-gradient(135deg, #16a083, #117964);
    border-radius: var(--border-radius);
}

@keyframes slideInFromButton {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideToButton {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(50px) scale(0.3);
    }
}

.popup-enter {
    animation: slideInFromButton 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.popup-exit {
    animation: slideToButton 0.6s cubic-bezier(0.4, 0, 1, 1);
}

/*
  =================================
  Chatbot Box - FIXED
  =================================
*/
#chatbot-box {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 400px;
    max-width: calc(100vw - 60px);
    max-height: calc(100vh - 140px);
    border-radius: var(--border-radius-lg) !important;
    overflow: hidden;
    z-index: 1050;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
}

#chatbot-box .card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border: none;
}

/* Header - FIXED */
#chatbot-box .card-header {
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal)) !important;
    border-bottom: none !important;
    padding: 1rem;
    flex-shrink: 0;
}

#chatbot-box .card-header h5 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

#chatbot-box .card-header small {
    opacity: 0.9;
}

#chatbot-box .card-header .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#chatbot-box .card-header .btn:hover {
    transform: scale(1.1);
}

/*
  =================================
  Chat Body - FIXED
  =================================
*/
#chat-body {
    height: 400px;
    min-height: 300px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    background: var(--bg-light);
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Custom Scrollbar */
#chat-body::-webkit-scrollbar {
    width: 6px;
}

#chat-body::-webkit-scrollbar-track {
    background: transparent;
}

#chat-body::-webkit-scrollbar-thumb {
    background: rgba(22, 160, 131, 0.3);
    border-radius: 3px;
}

#chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(22, 160, 131, 0.5);
}

/* Messages - IMPROVED */
#chatbot-box .alert {
    margin-bottom: 0.5rem;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 1rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-sm);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* User Messages - FIXED */
#chatbot-box .alert-secondary {
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal)) !important;
    border-color: transparent !important;
    color: var(--white) !important;
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
    max-width: 85%;
}

/* AI Messages - FIXED */
#chatbot-box .alert-primary {
    background: var(--white) !important;
    border: 1px solid #e2e8f0 !important;
    color: var(--text-dark) !important;
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
    max-width: 85%;
}

/* Message Links */
#chatbot-box .alert a {
    color: var(--primary-green);
    text-decoration: underline;
    font-weight: 500;
}

#chatbot-box .alert-secondary a {
    color: var(--white);
    text-decoration: underline;
}

/*
  =================================
  Input Area - FIXED
  =================================
*/
#chatbot-box .card-footer {
    background: var(--white);
    border-top: 1px solid #e2e8f0;
    padding: 1rem;
    flex-shrink: 0;
}

#chatbot-box .input-group {
    position: relative;
}

#user-input {
    border: 2px solid #e2e8f0;
    border-radius: 2rem;
    padding: 0.75rem 1.25rem;
    font-size: 16px; /* Prevents iOS zoom */
    transition: var(--transition);
    background: var(--bg-light);
}

#user-input:focus {
    outline: none;
    border-color: var(--primary-green);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(22, 160, 131, 0.1);
}

#user-input::placeholder {
    color: var(--text-light);
}

#send-btn {
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal)) !important;
    border: none !important;
    border-radius: 2rem !important;
    padding: 0.75rem 1.5rem !important;
    transition: var(--transition) !important;
    box-shadow: var(--shadow-sm);
}

#send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-teal), var(--primary-green)) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

#send-btn:active:not(:disabled) {
    transform: translateY(0);
}

#send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#send-btn:focus-visible {
    outline: 2px solid var(--primary-green);
    outline-offset: 2px;
}

/* Character Counter */
#char-count {
    font-size: 0.75rem;
    transition: var(--transition);
}

#char-count.text-warning {
    color: #f59e0b !important;
    font-weight: 500;
}

#char-count.text-danger {
    color: #ef4444 !important;
    font-weight: 600;
}

/*
  =================================
  Typing Indicator - IMPROVED
  =================================
*/
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    background: var(--white);
    color: var(--text-light);
    border: 1px solid #e2e8f0;
    max-width: fit-content;
    box-shadow: var(--shadow-sm);
    animation: messageSlideIn 0.3s ease-out;
}

.typing-indicator small {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-dots::after {
    content: '...';
    animation: ellipsis 1.5s infinite;
    display: inline-block;
    width: 20px;
}

@keyframes ellipsis {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/*
  =================================
  History Panel - FIXED
  =================================
*/
#history-panel {
    position: fixed;
    bottom: 110px;
    right: 460px;
    width: 350px;
    max-width: calc(100vw - 490px);
    max-height: calc(100vh - 140px);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    z-index: 1040;
    box-shadow: var(--shadow-xl);
}

#history-panel .card-header {
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal)) !important;
    padding: 1rem;
    flex-shrink: 0;
}

#history-panel .card-header .btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#history-list {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100vh - 240px);
    padding: 0.5rem;
    background: var(--bg-light);
}

#history-list::-webkit-scrollbar {
    width: 6px;
}

#history-list::-webkit-scrollbar-track {
    background: transparent;
}

#history-list::-webkit-scrollbar-thumb {
    background: rgba(22, 160, 131, 0.3);
    border-radius: 3px;
}

.history-item {
    cursor: pointer;
    transition: var(--transition);
    background: var(--white);
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
}

.history-item:hover {
    background-color: #f0f9ff !important;
    border-color: var(--primary-green) !important;
    transform: translateX(-2px);
    box-shadow: var(--shadow);
}

.history-item:active {
    transform: translateX(0);
}

.history-item.bg-light {
    background: #e0f2f1 !important;
}

/*
  =================================
  Login Modal - IMPROVED
  =================================
*/
.modal-content {
    border-radius: var(--border-radius-lg);
    border: none;
    box-shadow: var(--shadow-xl);
}

#loginModal .modal-header {
    border-bottom: 1px solid #e2e8f0;
    padding: 1.5rem;
}

#loginModal .modal-body {
    padding: 2rem 1.5rem;
}

#loginModal .modal-footer {
    border-top: 1px solid #e2e8f0;
    padding: 1rem 1.5rem;
}

#loginModal .btn-primary {
    background: linear-gradient(135deg, var(--primary-green), var(--accent-teal));
    border: none;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    transition: var(--transition);
}

#loginModal .btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-teal), var(--primary-green));
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

#loginModal .btn-outline-primary {
    color: var(--primary-green);
    border: 2px solid var(--primary-green);
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    transition: var(--transition);
}

#loginModal .btn-outline-primary:hover {
    background-color: var(--primary-green);
    border-color: var(--primary-green);
    color: var(--white);
    transform: translateY(-1px);
}

/*
  =================================
  Error Messages - IMPROVED
  =================================
*/
.alert-danger {
    background: #fee2e2 !important;
    border: 1px solid #fca5a5 !important;
    color: #991b1b !important;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/*
  =================================
  Responsive Design - FIXED
  =================================
*/

/* Tablets (768px - 1024px) */
@media (max-width: 1024px) {
    #history-panel {
        right: 30px;
        bottom: calc(110px + 450px);
        width: 350px;
        max-width: calc(100vw - 60px);
    }
}

/* Large Mobile (481px - 768px) */
@media (max-width: 768px) {
    #chatbot-box {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: 90px;
    }

    #chat-body {
        height: 350px;
        max-height: calc(100vh - 280px);
    }

    #greeting-popup {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: 100px;
    }

    #history-panel {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: calc(90px + 480px);
        max-width: none;
    }

    #chatbot-btn {
        width: 60px;
        height: 60px;
        bottom: 20px;
        right: 20px;
    }
}

/* Small Mobile (max 480px) - Full Screen */
@media (max-width: 480px) {
    #chatbot-box {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    #chatbot-box .card {
        border-radius: 0 !important;
        height: 100vh;
    }

    #chatbot-box .card-header {
        border-radius: 0 !important;
    }

    #chat-body {
        height: calc(100vh - 180px) !important;
        max-height: none !important;
        border-radius: 0;
    }

    #chatbot-box .card-footer {
        border-radius: 0 !important;
    }

    #greeting-popup {
        width: calc(100vw - 30px);
        left: 15px;
        right: 15px;
        bottom: 90px;
    }

    #history-panel {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        z-index: 1100;
    }

    #history-list {
        max-height: calc(100vh - 140px);
    }

    #chatbot-btn {
        width: 56px !important;
        height: 56px !important;
        bottom: 20px !important;
        right: 20px !important;
    }
}

/* Landscape Mode - Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #chatbot-box {
        height: 90vh !important;
        max-height: 90vh !important;
    }

    #chat-body {
        height: calc(90vh - 180px) !important;
    }

    #greeting-popup {
        bottom: 80px;
    }
}

/* Very Small Devices */
@media (max-width: 360px) {
    #chatbot-box .card-header h5 {
        font-size: 1rem;
    }

    #chatbot-box .card-header small {
        font-size: 0.7rem;
    }

    #user-input {
        font-size: 14px;
        padding: 0.6rem 1rem;
    }

    #send-btn {
        padding: 0.6rem 1.2rem !important;
    }
}

/*
  =================================
  Dark Mode Support (Optional)
  =================================
*/
@media (prefers-color-scheme: dark) {
    :root {
        --bg-light: #1a202c;
        --text-dark: #e2e8f0;
        --text-light: #a0aec0;
    }

    /* Apply dark mode only if body has .dark-mode class */
    body.dark-mode #chat-body {
        background: #1a202c;
    }

    body.dark-mode #chatbot-box .alert-primary {
        background: #2d3748 !important;
        border-color: #4a5568 !important;
        color: #e2e8f0 !important;
    }

    body.dark-mode #user-input {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    body.dark-mode #history-list,
    body.dark-mode #chatbot-box .card-footer {
        background: #1a202c;
    }

    body.dark-mode .history-item {
        background: #2d3748;
        border-color: #4a5568 !important;
    }
}

/*
  =================================
  Print Styles
  =================================
*/
@media print {
    #chatbot-btn,
    #greeting-popup,
    #history-panel {
        display: none !important;
    }

    #chatbot-box {
        position: static;
        width: 100%;
        box-shadow: none;
    }
}

/*
  =================================
  Accessibility Improvements
  =================================
*/

/* Focus visible states for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--primary-green);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #chatbot-box .alert-primary {
        border: 2px solid #000 !important;
    }

    #chatbot-box .alert-secondary {
        border: 2px solid #fff !important;
    }
}