/* ============================================
   HEALTH WELLNESS AGENT - CHAT UI
   Purple/Violet Chatbot Theme
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --primary: #7C3AED;
    --primary-dark: #6D28D9;
    --primary-light: #8B5CF6;
    --primary-lighter: #A78BFA;
    --primary-bg: #EDE9FE;
    --primary-bg-soft: #F5F3FF;
    --accent: #7C3AED;
    --bg-body: #F0EEFA;
    --bg-chat: #FFFFFF;
    --bg-bot-msg: #F3F0FF;
    --bg-user-msg: #7C3AED;
    --text-primary: #1E1B4B;
    --text-secondary: #6B7280;
    --text-bot: #312E81;
    --text-user: #FFFFFF;
    --border-color: #E5E1F5;
    --shadow-sm: 0 1px 3px rgba(124, 58, 237, 0.08);
    --shadow-md: 0 4px 20px rgba(124, 58, 237, 0.12);
    --shadow-lg: 0 12px 40px rgba(124, 58, 237, 0.18);
    --shadow-bubble: 0 8px 32px rgba(124, 58, 237, 0.25);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Chat Container ---------- */
.chat-container {
    width: 420px;
    max-width: 100%;
    height: 640px;
    max-height: calc(100vh - 40px);
    background: var(--bg-chat);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ---------- Chat Header ---------- */
.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    right: 0;
    height: 8px;
    background: linear-gradient(180deg, rgba(124,58,237,0.06) 0%, transparent 100%);
    pointer-events: none;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar-header {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.header-info h1 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.2px;
    margin: 0;
    line-height: 1.2;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: #34D399;
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}

.status-text {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 400;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* ---------- Chat Messages ---------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--primary-lighter);
    border-radius: 4px;
}

/* --- Message Row --- */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 100%;
}

.message-row.bot {
    flex-direction: row;
    align-self: flex-start;
}

.message-row.user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

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

/* --- Bot Avatar --- */
.msg-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.msg-avatar svg {
    width: 16px;
    height: 16px;
}

/* --- Message Bubble --- */
.message-bubble {
    padding: 11px 15px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    line-height: 1.55;
    max-width: 280px;
    word-wrap: break-word;
    position: relative;
}

.message-row.bot .message-bubble {
    background: var(--bg-bot-msg);
    color: var(--text-bot);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.message-row.user .message-bubble {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-user);
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.2);
}

/* --- Message Content Formatting --- */
.message-bubble h3,
.message-bubble h4 {
    font-size: 13px;
    font-weight: 700;
    margin: 10px 0 5px 0;
    color: inherit;
}

.message-bubble h3:first-child,
.message-bubble h4:first-child {
    margin-top: 0;
}

.message-bubble p {
    margin: 4px 0;
}

.message-bubble ul,
.message-bubble ol {
    padding-left: 18px;
    margin: 4px 0;
}

.message-bubble li {
    margin: 2px 0;
}

.message-bubble strong {
    font-weight: 600;
}

/* --- Timestamp --- */
.msg-time {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 3px;
    padding: 0 4px;
    opacity: 0.7;
}

.message-row.user .msg-time {
    text-align: right;
}

/* --- Typing indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--primary-lighter);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.7);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ---------- Quick Replies ---------- */
.quick-replies {
    padding: 0 16px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.quick-reply-btn {
    padding: 7px 14px;
    border: 1.5px solid var(--primary-lighter);
    background: var(--primary-bg-soft);
    color: var(--primary);
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    white-space: nowrap;
}

.quick-reply-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(124, 58, 237, 0.2);
}

.quick-reply-btn:active {
    transform: scale(0.97);
}

/* ---------- Chat Input ---------- */
.chat-input-area {
    padding: 10px 16px 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-chat);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-bg-soft);
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    padding: 4px 4px 4px 14px;
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--primary-lighter);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
    background: white;
}

#chatInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--text-primary);
    padding: 8px 0;
}

#chatInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    border-radius: 11px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.send-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.3);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.powered-by {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 10.5px;
    color: var(--text-secondary);
    opacity: 0.5;
}

.powered-by strong {
    font-weight: 600;
}

/* ---------- Minimized Chat Bubble ---------- */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-bubble);
    transition: var(--transition);
    animation: bubbleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
}

.chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 40px rgba(124, 58, 237, 0.35);
}

@keyframes bubbleIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ---------- Context Panel (hidden by default) ---------- */
.context-panel {
    background: var(--primary-bg-soft);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 6px 0;
    font-size: 12px;
    color: var(--text-bot);
    border: 1px solid var(--border-color);
    animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.context-panel h4 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.context-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 4px 0;
    font-size: 11.5px;
    line-height: 1.4;
}

.context-item .label {
    font-weight: 600;
    color: var(--primary-dark);
    min-width: 70px;
    flex-shrink: 0;
}

.context-item .value {
    color: var(--text-secondary);
}

/* ---------- Error message ---------- */
.error-bubble {
    background: #FEF2F2 !important;
    color: #DC2626 !important;
    border: 1px solid #FECACA !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    body {
        padding: 0;
    }
    .chat-container {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}
