/**
 * Mental Health Support Chatbot — Custom Styles
 * 
 * Covers: design tokens, glassmorphism, animations, typing indicator,
 * chat bubbles, companion cards, scrollbar, and utility classes.
 * Works in conjunction with TailwindCSS CDN.
 */

/* ─── Google Font import (fallback if preload fails) ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Design Tokens ────────────────────────────────────── */
:root {
    --bg-base:        #06060f;
    --bg-surface:     rgba(255, 255, 255, 0.04);
    --bg-surface-2:   rgba(255, 255, 255, 0.07);
    --border:         rgba(255, 255, 255, 0.08);
    --border-hover:   rgba(255, 255, 255, 0.16);

    --accent-purple:  #8b5cf6;
    --accent-blue:    #3b82f6;
    --accent-pink:    #ec4899;

    --text-primary:   #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:     #475569;

    --user-bubble:    linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    --bot-bubble:     rgba(255, 255, 255, 0.05);
    --bot-border:     rgba(255, 255, 255, 0.08);

    --radius-card:    1.25rem;
    --radius-bubble:  1rem;
    --shadow-card:    0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow:    0 0 40px rgba(139, 92, 246, 0.15);
}

/* ─── Base Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ─── Screen Management ────────────────────────────────── */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    overflow: hidden;
}

#screen-selection {
    overflow-y: auto;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
}

/* ─── Background Orbs (Selection Screen) ──────────────── */
.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    opacity: 0.35;
    animation: orbFloat 8s ease-in-out infinite;
}

.orb-purple {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
    top: -150px;
    right: -100px;
    animation-delay: 0s;
}

.orb-blue {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #2563eb 0%, transparent 70%);
    bottom: -100px;
    left: -80px;
    animation-delay: -4s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%       { transform: translate(20px, -30px) scale(1.05); }
    66%       { transform: translate(-15px, 20px) scale(0.97); }
}

/* ─── Companion Cards ──────────────────────────────────── */
.companion-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
    text-align: center;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.companion-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.06) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.companion-card:hover {
    border-color: rgba(139, 92, 246, 0.4);
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), var(--shadow-glow);
}

.companion-card:hover::before { opacity: 1; }

.companion-card.selected {
    border-color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.08);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3), var(--shadow-glow);
}

.companion-card.selected::before { opacity: 1; }

/* Avatar ring */
.avatar-ring {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    transition: all 0.25s ease;
    margin-bottom: 0.25rem;
}

.companion-card:not(.selected) .avatar-ring {
    background: var(--border);
}

.companion-card.selected .avatar-ring,
.companion-card:hover .avatar-ring {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
}

.companion-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #1e1e2e;
}

.companion-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.gender-badge {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.15rem 0.6rem;
    border-radius: 100px;
    letter-spacing: 0.03em;
}

.gender-badge.male {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.gender-badge.female {
    background: rgba(236, 72, 153, 0.15);
    color: #f472b6;
    border: 1px solid rgba(236, 72, 153, 0.25);
}

.companion-tagline {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

/* ─── Start Button ─────────────────────────────────────── */
.start-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 2.5rem;
    border-radius: 100px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.25s ease;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    color: white;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.35);
}

.start-btn:disabled {
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.start-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(139, 92, 246, 0.5);
}

.start-btn:not(:disabled):active {
    transform: translateY(0);
}

/* ─── Chat Header ──────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: rgba(10, 10, 24, 0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-shrink: 0;
    z-index: 10;
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.back-btn:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* ─── Crisis Banner ────────────────────────────────────── */
.crisis-banner {
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 0.75rem;
    margin: 0.75rem;
    padding: 0.875rem 1rem;
    flex-shrink: 0;
    animation: fadeIn 0.3s ease;
}

.crisis-number {
    display: inline-block;
    color: #fca5a5;
    text-decoration: none;
    padding: 0.25rem 0.75rem;
    background: rgba(220, 38, 38, 0.15);
    border-radius: 100px;
    border: 1px solid rgba(220, 38, 38, 0.3);
    transition: background 0.2s ease;
}

.crisis-number:hover {
    background: rgba(220, 38, 38, 0.25);
}

/* ─── Questionnaire Bar ────────────────────────────────── */
.questionnaire-bar {
    padding: 0.625rem 1rem;
    background: rgba(139, 92, 246, 0.06);
    border-bottom: 1px solid rgba(139, 92, 246, 0.15);
    flex-shrink: 0;
}

/* ─── Messages Container ───────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    scroll-behavior: smooth;
}

/* ─── Custom Scrollbar ─────────────────────────────────── */
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 100px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* ─── Message Bubbles ──────────────────────────────────── */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    animation: slideUp 0.3s ease forwards;
    opacity: 0;
}

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

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    opacity: 0.9;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 72%;
}

.message-row.user .message-content {
    align-items: flex-end;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-bubble);
    line-height: 1.65;
    font-size: 0.9rem;
    word-wrap: break-word;
}

.message-bubble.assistant {
    background: var(--bot-bubble);
    border: 1px solid var(--bot-border);
    border-bottom-left-radius: 0.25rem;
    color: var(--text-primary);
}

.message-bubble.user {
    background: var(--user-bubble);
    border-bottom-right-radius: 0.25rem;
    color: white;
}

.message-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    padding: 0 0.25rem;
}

/* Markdown inside bubbles */
.message-bubble p { margin: 0 0 0.5em; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }
.message-bubble ul, .message-bubble ol {
    margin: 0.4em 0;
    padding-left: 1.25em;
}
.message-bubble li { margin-bottom: 0.2em; }
.message-bubble code {
    background: rgba(255,255,255,0.1);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ─── Typing Indicator ─────────────────────────────────── */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--bot-bubble);
    border: 1px solid var(--bot-border);
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-bubble);
    border-bottom-left-radius: 0.25rem;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--accent-purple);
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

/* ─── Chat Input Area ──────────────────────────────────── */
.chat-input-area {
    padding: 0.75rem 1rem 1rem;
    background: rgba(10, 10, 24, 0.95);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.625rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.08);
}

.chat-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.chat-textarea::placeholder { color: var(--text-muted); }

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    color: white;
}

.send-btn:disabled {
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.send-btn:not(:disabled):active { transform: scale(0.97); }

/* ─── Keyframe Animations ──────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

@keyframes pulseSoft {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

/* ─── Utility ──────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive Adjustments ───────────────────────────── */
@media (max-width: 640px) {
    .companion-card { padding: 1rem 0.75rem; }
    .avatar-ring { width: 72px; height: 72px; }
    .companion-name { font-size: 0.95rem; }
    .companion-tagline { display: none; }
    .message-content { max-width: 85%; }
}
