/* ==========================================================================
   STUDY BUDDY - CUTE & MINIMALIST DESIGN SYSTEM
   Dominant Palette: Light Blue (#BFDBFE, #EFF6FF, #3B82F6)
   ========================================================================== */

/* CSS Variables / Custom Properties */
:root {
    /* Color Palette */
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --primary-light: #BFDBFE;
    --primary-soft: #EFF6FF;
    --primary-subtle: #DBEAFE;
    --accent: #60A5FA;
    --accent-dark: #1D4ED8;
    
    /* Background Colors */
    --bg-app: #F4F9FF;
    --bg-card: #FFFFFF;
    --bg-user-msg: linear-gradient(135deg, #DBEAFE 0%, #BFDBFE 100%);
    --bg-bot-msg: #FFFFFF;
    
    /* Text Colors */
    --text-primary: #1E293B;
    --text-secondary: #475569;
    --text-muted: #64748B;
    --text-white: #FFFFFF;
    
    /* Border & Shadow */
    --border-soft: #E2E8F0;
    --border-blue: #93C5FD;
    --shadow-sm: 0 2px 8px rgba(59, 130, 246, 0.06);
    --shadow-md: 0 4px 16px rgba(59, 130, 246, 0.1);
    --shadow-lg: 0 10px 30px rgba(59, 130, 246, 0.15);
    
    /* Layout & Sizing */
    --header-height: 72px;
    --footer-height: auto;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    /* Fonts */
    --font-primary: 'Nunito', 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Reset & Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    font-family: var(--font-primary);
    background-color: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Main App Wrapper */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1000px;
    margin: 0 auto;
    background-color: var(--bg-app);
    box-shadow: var(--shadow-lg);
    position: relative;
}

/* ==========================================================================
   HEADER SECTION
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--primary-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

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

.avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    position: relative;
    user-select: none;
}

.header-avatar {
    background: linear-gradient(135deg, #DBEAFE 0%, #BFDBFE 100%);
    border: 2px solid var(--primary);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.2);
}

.status-indicator {
    width: 12px;
    height: 12px;
    background-color: #22C55E;
    border: 2.5px solid #FFFFFF;
    border-radius: var(--radius-full);
    position: absolute;
    bottom: 0;
    right: 0;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.2px;
}

.header-title .badge {
    font-size: 0.65rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-dark) 100%);
    color: var(--text-white);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.status-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 1px;
}

.pulse-dot {
    font-size: 0.5rem;
    color: #22C55E;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1); }
}

/* Header Buttons */
.btn-reset {
    background-color: var(--primary-soft);
    color: var(--primary);
    border: 1.5px solid var(--primary-subtle);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-reset:hover {
    background-color: var(--primary-light);
    border-color: var(--primary);
    color: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-reset:active {
    transform: translateY(0);
}

/* ==========================================================================
   CHAT MAIN CONTAINER
   ========================================================================== */
.chat-main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scroll-behavior: smooth;
    background-image: 
        radial-gradient(var(--primary-subtle) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Scrollbar Customization */
.chat-main::-webkit-scrollbar {
    width: 6px;
}

.chat-main::-webkit-scrollbar-track {
    background: transparent;
}

.chat-main::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: var(--radius-full);
}

.chat-main::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* ==========================================================================
   WELCOME SCREEN & SUGGESTION CHIPS
   ========================================================================== */
.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: auto 0;
    padding: 1rem 0;
    animation: fadeIn 0.4s ease-out;
}

.welcome-card {
    background: #FFFFFF;
    border: 2px solid var(--primary-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem 1.75rem;
    text-align: center;
    max-width: 540px;
    width: 100%;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.welcome-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: linear-gradient(90deg, #93C5FD 0%, #3B82F6 50%, #60A5FA 100%);
}

.welcome-avatar {
    width: 64px;
    height: 64px;
    background: var(--primary-soft);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    margin: 0 auto 1rem auto;
    border: 2px solid var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.welcome-card h2 {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.welcome-card p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.suggestions-section {
    margin-top: 1.75rem;
    width: 100%;
    max-width: 580px;
}

.suggestions-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.suggestions-title i {
    color: #F59E0B;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
}

.suggestion-chip {
    background-color: #FFFFFF;
    border: 1.5px solid var(--primary-subtle);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    text-align: left;
    font-family: var(--font-primary);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.suggestion-chip .chip-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.suggestion-chip .chip-text {
    line-height: 1.3;
}

.suggestion-chip:hover {
    background-color: var(--primary-soft);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--accent-dark);
}

.suggestion-chip:active {
    transform: translateY(0);
}

/* ==========================================================================
   CHAT MESSAGES LIST & BUBBLES
   ========================================================================== */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

.message-row {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: slideUp 0.3s ease-out forwards;
}

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

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

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

.bot-avatar {
    background: linear-gradient(135deg, #FFFFFF 0%, var(--primary-soft) 100%);
    border: 2px solid var(--primary-light);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.user-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-dark) 100%);
    color: var(--text-white);
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

/* Message Bubble */
.message-bubble {
    padding: 1rem 1.25rem;
    border-radius: 20px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.65;
    word-break: break-word;
}

.user-row .message-bubble {
    background: var(--bg-user-msg);
    color: var(--text-primary);
    border: 1.5px solid var(--primary-light);
    border-top-right-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.bot-row .message-bubble {
    background-color: var(--bg-bot-msg);
    color: var(--text-primary);
    border: 1.5px solid var(--border-soft);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: block;
    font-weight: 600;
}

.user-row .message-time {
    text-align: right;
    color: #475569;
}

.bot-row .message-time {
    text-align: left;
}

/* Markdown Formatted Content Inside Message */
.markdown-content p {
    margin-bottom: 0.75rem;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content strong {
    font-weight: 700;
    color: #0F172A;
}

.markdown-content em {
    font-style: italic;
    color: #334155;
}

.markdown-content ul, .markdown-content ol {
    margin: 0.5rem 0 0.75rem 1.5rem;
    padding-left: 0.5rem;
}

.markdown-content li {
    margin-bottom: 0.35rem;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    font-weight: 800;
    margin: 0.85rem 0 0.4rem 0;
    color: #0F172A;
    line-height: 1.3;
}

.markdown-content h1 { font-size: 1.15rem; }
.markdown-content h2 { font-size: 1.05rem; }
.markdown-content h3 { font-size: 0.98rem; }

.markdown-content code.inline-code {
    background-color: var(--primary-soft);
    color: var(--accent-dark);
    border: 1px solid var(--primary-subtle);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.85em;
    font-weight: 600;
}

.markdown-content pre {
    background-color: #0F172A;
    color: #F8FAFC;
    padding: 1rem;
    border-radius: 12px;
    overflow-x: auto;
    margin: 0.75rem 0;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88rem;
    position: relative;
}

.markdown-content pre code {
    background: transparent;
    padding: 0;
    border: none;
    color: inherit;
}

.code-block-wrapper {
    position: relative;
    margin: 0.75rem 0;
}

.code-header {
    background-color: #1E293B;
    color: #94A3B8;
    padding: 6px 12px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
}

.code-header + pre {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    margin-top: 0;
}

.btn-copy-code {
    background: transparent;
    border: none;
    color: #94A3B8;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: var(--font-primary);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.btn-copy-code:hover {
    color: #FFFFFF;
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */
.typing-container {
    display: flex;
    gap: 12px;
    align-items: center;
    max-width: 80%;
    margin-top: 0.25rem;
    animation: fadeIn 0.3s ease;
}

.typing-bubble {
    background: #FFFFFF;
    border: 1.5px solid var(--primary-subtle);
    border-radius: 20px;
    border-top-left-radius: 4px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.typing-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.bouncing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
.dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.2); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================================================
   FOOTER INPUT AREA (FIXED BOTTOM)
   ========================================================================== */
.app-footer {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 2px solid var(--primary-subtle);
    padding: 1rem 1.5rem 0.85rem 1.5rem;
    box-shadow: 0 -4px 20px rgba(59, 130, 246, 0.08);
    z-index: 10;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background-color: var(--primary-soft);
    border: 2px solid var(--primary-subtle);
    border-radius: var(--radius-lg);
    padding: 8px 12px 8px 16px;
    transition: all 0.25s ease;
}

.input-container:focus-within {
    border-color: var(--primary);
    background-color: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

textarea#chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-primary);
    font-size: 0.95rem;
    color: var(--text-primary);
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
}

textarea#chat-input::placeholder {
    color: var(--text-muted);
    font-weight: 500;
}

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-dark) 100%);
    color: var(--text-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

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

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

.btn-send:disabled {
    background: #CBD5E1;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.7;
}

.footer-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
    font-weight: 600;
}

.footer-info i {
    color: var(--primary);
}

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

/* ==========================================================================
   TOAST NOTIFICATION / ALERT MODAL
   ========================================================================== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    left: 20px;
    max-width: 400px;
    margin: 0 auto;
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: #FFFFFF;
    border-radius: var(--radius-md);
    padding: 12px 18px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: auto;
    animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1.5px solid var(--border-soft);
}

.toast.error {
    border-color: #FCA5A5;
    background-color: #FEF2F2;
    color: #991B1B;
}

.toast.info {
    border-color: var(--primary-light);
    background-color: var(--primary-soft);
    color: var(--accent-dark);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ========================================================================== */
@media (max-width: 640px) {
    .app-container {
        height: 100vh;
        max-width: 100%;
        box-shadow: none;
    }

    .app-header {
        padding: 0 1rem;
        height: 64px;
    }

    .header-title h1 {
        font-size: 1.1rem;
    }

    .btn-reset .btn-text {
        display: none; /* Icon-only on mobile for cleaner look */
    }

    .btn-reset {
        padding: 8px 12px;
    }

    .chat-main {
        padding: 1rem;
        gap: 1rem;
    }

    .message-row {
        max-width: 90%;
    }

    .welcome-card {
        padding: 1.5rem 1.25rem;
    }

    .welcome-card h2 {
        font-size: 1.25rem;
    }

    .suggestions-grid {
        grid-template-columns: 1fr;
    }

    .app-footer {
        padding: 0.75rem 1rem 0.75rem 1rem;
    }

    .footer-info {
        font-size: 0.7rem;
    }
}
