/* ==========================================================================
   STUDY BUDDY STYLE SYSTEM
   Theme: Cute, Minimalist, Soft Blue Pastel
   ========================================================================== */

/* Custom Variables */
:root {
    --color-bg: #F0F9FF;          /* Soft celestial blue background */
    --color-panel: #FFFFFF;      /* Panel background (white) */
    --color-primary: #3B82F6;    /* Vibrant accent blue */
    --color-primary-hover: #2563EB;
    --color-secondary: #E0F2FE;  /* Soft light blue */
    --color-secondary-hover: #BAE6FD;
    --color-text-main: #1E293B;  /* Slate 800 dark text */
    --color-text-muted: #64748B; /* Slate 500 muted text */
    --color-text-darkblue: #1E3A8A; /* Blue 900 for dark blue text contrast */
    --color-user-bubble: #DBEAFE; /* Blue 100 for user */
    --color-buddy-bubble: #FFFFFF; /* White for Study Buddy */
    --color-border: #E2E8F0;     /* Slate 200 border */
    --color-danger: #EF4444;     /* Red 500 danger */
    --color-danger-hover: #DC2626;
    --color-success: #10B981;    /* Green 500 success */
    
    --font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-sm: 0 2px 4px rgba(59, 130, 246, 0.04);
    --shadow-md: 0 4px 12px rgba(59, 130, 246, 0.08);
    --shadow-lg: 0 10px 25px -5px rgba(59, 130, 246, 0.12), 0 8px 10px -6px rgba(59, 130, 246, 0.12);
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 12px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: -webkit-fill-available; /* Mobile height fix */
    overflow: hidden;
}

html {
    height: -webkit-fill-available;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    height: 90vh;
    background-color: var(--color-panel);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    position: relative;
    border: 3px solid #E0F2FE;
    transition: var(--transition-normal);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid #E0F2FE;
    z-index: 10;
}

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

.logo-emoji {
    font-size: 2rem;
    animation: float 3s ease-in-out infinite;
}

.logo-text h1 {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--color-text-darkblue);
    line-height: 1.2;
}

.logo-text p {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--border-radius-md);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    outline: none;
}

.btn-primary {
    background-color: var(--color-primary);
    color: white;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--color-secondary);
    color: var(--color-text-darkblue);
}

.btn-secondary:hover {
    background-color: var(--color-secondary-hover);
}

.btn-danger {
    background-color: var(--color-secondary);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background-color: #FEE2E2;
    color: var(--color-danger-hover);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--border-radius-sm);
}

.icon-btn {
    background: var(--color-secondary);
    border: none;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-btn:hover {
    background: var(--color-secondary-hover);
    transform: scale(1.05);
}

/* Warning Banner */
.warning-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background-color: #FEF3C7;
    border-bottom: 2px solid #FDE68A;
    padding: 12px 24px;
    font-size: 0.85rem;
    color: #92400E;
    animation: slideDown 0.3s ease-out;
}

.warning-content p {
    line-height: 1.4;
}

.warning-icon {
    font-size: 1.2rem;
}

/* Chat Messages Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg);
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Scrollbar Customization */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: #CBD5E1;
    border-radius: 20px;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin: auto 0;
    padding: 20px 0;
    max-width: 550px;
    align-self: center;
    animation: fadeIn 0.5s ease-out;
}

.buddy-avatar-large {
    font-size: 4rem;
    background-color: white;
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    border: 3px solid var(--color-secondary);
    margin-bottom: 20px;
    animation: float 4s ease-in-out infinite;
}

.welcome-screen h2 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--color-text-darkblue);
    margin-bottom: 12px;
}

.welcome-text {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin-bottom: 28px;
}

/* Question Shortcuts */
.shortcut-container {
    width: 100%;
}

.shortcut-container h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.shortcut-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.shortcut-card {
    background: var(--color-panel);
    border: 2px solid #E2E8F0;
    padding: 14px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.shortcut-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background-color: var(--color-bg);
}

.shortcut-icon {
    font-size: 1.4rem;
    background: var(--color-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.shortcut-label {
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-darkblue);
    line-height: 1.3;
}

/* Chat Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

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

.message-buddy {
    align-self: flex-start;
}

.avatar-container {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: var(--shadow-sm);
    border: 2px solid #E2E8F0;
    flex-shrink: 0;
}

.message-user .avatar-container {
    background-color: var(--color-secondary);
    border-color: #BFDBFE;
}

.message-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sender-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

.message-user .sender-name {
    text-align: right;
}

.bubble {
    padding: 14px 18px;
    border-radius: var(--border-radius-md);
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.message-user .bubble {
    background-color: var(--color-user-bubble);
    color: var(--color-text-darkblue);
    border-top-right-radius: 4px;
    border: 1px solid #BFDBFE;
}

.message-buddy .bubble {
    background-color: var(--color-buddy-bubble);
    color: var(--color-text-main);
    border-top-left-radius: 4px;
    border: 1px solid #E2E8F0;
}

/* Typing Indicator Styling */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px 20px 24px;
    align-self: flex-start;
    animation: fadeIn 0.2s ease-out;
}

.buddy-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: var(--shadow-sm);
    border: 2px solid #E2E8F0;
}

.typing-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background-color: white;
    border: 1px solid #E2E8F0;
    border-radius: var(--border-radius-md);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

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

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

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

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

/* Markdown Styling inside Bubble */
.bubble p {
    margin-bottom: 8px;
}
.bubble p:last-child {
    margin-bottom: 0;
}

.bubble strong {
    font-weight: 800;
    color: #1E3A8A;
}

.bubble em {
    font-style: italic;
}

.bubble ul, .bubble ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.bubble li {
    margin-bottom: 4px;
}

.bubble pre {
    background-color: #F1F5F9;
    border-radius: var(--border-radius-sm);
    padding: 10px;
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid #E2E8F0;
}

.bubble code {
    font-family: "Courier New", Courier, monospace;
    font-size: 0.85rem;
    font-weight: bold;
    background-color: #F1F5F9;
    padding: 2px 4px;
    border-radius: 4px;
    color: #D97706;
}

.bubble pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    color: #0F172A;
    font-weight: normal;
}

.bubble blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: 12px;
    color: var(--color-text-muted);
    font-style: italic;
    margin: 8px 0;
}

/* Footer / Input Area */
.app-footer {
    padding: 16px 24px;
    background-color: white;
    border-top: 2px solid #E0F2FE;
}

.chat-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #E2E8F0;
    border-radius: var(--border-radius-md);
    font-family: var(--font-family);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition-fast);
    background-color: #F8FAFC;
}

#message-input:focus {
    border-color: var(--color-primary);
    background-color: white;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: white;
    width: 90%;
    max-width: 500px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    border: 3px solid #E0F2FE;
    overflow: hidden;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background-color: var(--color-bg);
    border-bottom: 2px solid #E0F2FE;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--color-text-darkblue);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: var(--transition-fast);
}

.close-btn:hover {
    color: var(--color-text-main);
    transform: scale(1.1);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-body p {
    font-size: 0.9rem;
    color: var(--color-text-main);
    line-height: 1.5;
}

.api-instructions {
    background-color: var(--color-bg);
    border: 1px dashed #BFDBFE;
    padding: 14px 18px;
    border-radius: var(--border-radius-md);
}

.api-instructions h3 {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--color-text-darkblue);
    margin-bottom: 8px;
}

.api-instructions ol {
    margin-left: 20px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}

.api-instructions a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 700;
}

.api-instructions a:hover {
    text-decoration: underline;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-darkblue);
}

.form-group input {
    padding: 12px 16px;
    border: 2px solid #E2E8F0;
    border-radius: var(--border-radius-md);
    outline: none;
    font-family: var(--font-family);
    transition: var(--transition-fast);
}

.form-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.helper-text {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.3;
}

.modal-status {
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    padding: 6px;
    border-radius: var(--border-radius-sm);
    display: none;
}

.modal-status.success {
    display: block;
    background-color: #D1FAE5;
    color: #065F46;
}

.modal-status.error {
    display: block;
    background-color: #FEE2E2;
    color: #991B1B;
}

.modal-footer {
    padding: 16px 24px;
    background-color: #F8FAFC;
    border-top: 1px solid #E2E8F0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Utilities & Animations */
.hidden {
    display: none !important;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
    100% { transform: translateY(0px); }
}

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

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes popIn {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

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

/* ==========================================================================
   RESPONSIVENESS (MEDIA QUERIES)
   ========================================================================== */

/* Tablet Viewports */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
        border: none;
    }
}

/* Mobile Viewports */
@media (max-width: 580px) {
    .app-header {
        padding: 12px 16px;
    }
    
    .logo-text h1 {
        font-size: 1.15rem;
    }
    
    .logo-text p {
        display: none; /* Hide subtitle to save space */
    }
    
    .logo-emoji {
        font-size: 1.6rem;
    }

    .btn-text {
        display: none; /* Icon-only button on mobile to save space */
    }

    .btn-secondary {
        padding: 10px;
        border-radius: 50%;
        width: 40px;
        height: 40px;
    }

    .chat-messages {
        padding: 16px;
        gap: 16px;
    }

    .welcome-screen h2 {
        font-size: 1.3rem;
    }

    .welcome-text {
        font-size: 0.85rem;
        margin-bottom: 20px;
    }

    .shortcut-grid {
        grid-template-columns: 1fr; /* Single column shortcuts */
        gap: 8px;
    }

    .shortcut-card {
        padding: 10px;
    }

    .shortcut-icon {
        width: 30px;
        height: 30px;
        font-size: 1.1rem;
    }

    .shortcut-label {
        font-size: 0.8rem;
    }

    .message {
        max-width: 92%;
    }

    .bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .app-footer {
        padding: 12px 16px;
    }

    #message-input {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
}
