/* ==========================================
   Study Buddy - Design System & Stylesheet
   ========================================== */

:root {
    /* Color Palette */
    --bg-main: #0b0f19;
    --bg-secondary: #131b2e;
    --bg-card: rgba(23, 32, 54, 0.7);
    --bg-card-hover: rgba(30, 43, 73, 0.95);
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --user-bubble-gradient: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
    
    --accent-teal: #10b981;
    --accent-cyan: #06b6d4;
    --accent-orange: #f59e0b;
    --accent-pink: #ec4899;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(99, 102, 241, 0.4);
    
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.25);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Plus Jakarta Sans', sans-serif;
}

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

html, body {
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.12) 0%, rgba(11, 15, 25, 1) 70%);
}

/* Header Navbar */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: rgba(19, 27, 46, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

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

.logo-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
    box-shadow: var(--shadow-glow);
}

.brand-text h1 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
    line-height: 1.2;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.12);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(6, 182, 212, 0.25);
}

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

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    opacity: 0.92;
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.icon-btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 9px 14px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-accent {
    background: var(--accent-teal);
    color: #052e16;
    font-weight: 700;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-accent:hover {
    background: #34d399;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-weight: 600;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* Chat Wrapper Main Body */
.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 67px);
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    position: relative;
}

/* API Banner */
.api-key-banner {
    background: rgba(245, 158, 11, 0.12);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    animation: fadeIn 0.3s ease-out;
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 280px;
}

.banner-icon {
    font-size: 1.4rem;
    color: var(--accent-orange);
}

.banner-text {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: #fef3c7;
}

.banner-text code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    color: #fde047;
}

.banner-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.banner-input-group input {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fff;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 200px;
    outline: none;
}

/* Scrollable Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Custom Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 6px;
}
.chat-container::-webkit-scrollbar-track {
    background: transparent;
}
.chat-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
}
.chat-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: auto 0;
    padding: 20px 10px;
    animation: fadeIn 0.4s ease-out;
}

.welcome-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid var(--border-highlight);
    color: #a5b4fc;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.welcome-screen h2 {
    font-family: var(--font-heading);
    font-size: 2.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
    line-height: 1.3;
}

.gradient-text {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-description {
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 640px;
    margin-bottom: 32px;
}

/* Quick Questions Grid */
.quick-questions-section {
    width: 100%;
    max-width: 800px;
    text-align: left;
}

.quick-questions-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-yellow {
    color: var(--accent-orange);
}

.quick-questions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.quick-question-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: var(--radius-lg);
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.quick-question-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-highlight);
    transform: translateY(-3px);
    box-shadow: var(--shadow-glow);
}

.card-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.math-bg { background: rgba(99, 102, 241, 0.2); color: #a5b4fc; }
.science-bg { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.lang-bg { background: rgba(245, 158, 11, 0.2); color: #fde047; }
.chemistry-bg { background: rgba(236, 72, 153, 0.2); color: #f472b6; }

.card-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.card-text strong {
    font-family: var(--font-heading);
    font-size: 0.92rem;
    color: #fff;
    margin-bottom: 2px;
}

.card-text span {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-arrow {
    color: var(--text-dim);
    transition: transform 0.2s ease, color 0.2s ease;
}

.quick-question-card:hover .card-arrow {
    transform: translateX(4px);
    color: var(--primary);
}

/* Chat Messages */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.message-bubble {
    display: flex;
    gap: 14px;
    max-width: 85%;
    animation: popIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

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

.bot-bubble {
    align-self: flex-start;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.user-avatar {
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
    color: #fff;
}

.bot-avatar {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.message-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    position: relative;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.user-bubble .message-content {
    background: var(--user-bubble-gradient);
    border: none;
    color: #ffffff;
    border-top-right-radius: 4px;
}

.bot-bubble .message-content {
    border-top-left-radius: 4px;
    color: #e2e8f0;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.75rem;
}

.user-bubble .message-meta {
    color: rgba(255, 255, 255, 0.75);
    justify-content: flex-end;
}

.bot-bubble .message-meta {
    color: var(--text-muted);
}

.sender-name {
    font-family: var(--font-heading);
    font-weight: 600;
}

.copy-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Markdown formatting inside Bot bubble */
.message-text p {
    margin-bottom: 10px;
}
.message-text p:last-child {
    margin-bottom: 0;
}
.message-text h1, .message-text h2, .message-text h3 {
    font-family: var(--font-heading);
    margin: 14px 0 8px 0;
    color: #fff;
}
.message-text h1 { font-size: 1.3rem; }
.message-text h2 { font-size: 1.15rem; }
.message-text h3 { font-size: 1.05rem; }

.message-text ul, .message-text ol {
    margin: 8px 0 10px 20px;
}

.message-text li {
    margin-bottom: 4px;
}

.message-text code {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88em;
    color: #f472b6;
}

.message-text pre {
    background: #090d16 !important;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 12px 0;
    overflow-x: auto;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

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

/* Loading Thinking Indicator */
.loading-bubble .message-content {
    background: rgba(19, 27, 46, 0.9);
    border-color: var(--border-highlight);
}

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

.thinking-text {
    font-family: var(--font-heading);
    font-weight: 600;
    color: #a5b4fc;
    font-size: 0.92rem;
}

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

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

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

.thinking-sub {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Error message styling */
.error-bubble .message-content {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Input Section Bottom */
.input-section {
    padding: 14px 20px 18px 20px;
    background: rgba(11, 15, 25, 0.95);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-container {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    transition: all 0.25s ease;
}

.input-container:focus-within {
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
    background: rgba(23, 32, 54, 0.95);
}

.textarea-wrapper textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.95rem;
    resize: none;
    max-height: 140px;
    line-height: 1.5;
}

.textarea-wrapper textarea::placeholder {
    color: var(--text-dim);
}

.input-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.helper-info {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.send-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.footer-credit {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-dim);
}

.footer-credit strong {
    color: var(--text-muted);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal-card {
    background: #131b2e;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-accent {
    color: var(--primary);
}

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

.close-btn:hover {
    color: #fff;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.modal-body a {
    color: var(--accent-cyan);
    text-decoration: none;
}

.modal-body a:hover {
    text-decoration: underline;
}

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

.form-group label {
    font-weight: 600;
    color: #fff;
    font-size: 0.85rem;
}

.form-group input {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    outline: none;
}

.form-group input:focus {
    border-color: var(--primary);
}

.modal-note {
    font-size: 0.78rem;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #c7d2fe;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background: rgba(15, 23, 42, 0.5);
    border-top: 1px solid var(--border-color);
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes pulseDot {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Responsive Styles */
@media (max-width: 640px) {
    .app-header {
        padding: 10px 14px;
    }
    
    .brand-text h1 {
        font-size: 1.1rem;
    }
    
    .btn-label {
        display: none;
    }

    .welcome-screen h2 {
        font-size: 1.5rem;
    }
    
    .message-bubble {
        max-width: 95%;
    }
    
    .banner-input-group {
        width: 100%;
    }
    
    .banner-input-group input {
        flex: 1;
    }
    
    .quick-questions-grid {
        grid-template-columns: 1fr;
    }
}
