/* ========================================
   AI Study Assistant — Professional Chat UI
   ======================================== */

:root {
    /* Color System */
    --primary-50: #f0f4ff;
    --primary-100: #dbe4ff;
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;

    --accent-400: #2dd4bf;
    --accent-500: #14b8a6;
    --accent-600: #0d9488;

    --rose-400: #fb7185;
    --rose-500: #f43f5e;
    --amber-400: #fbbf24;

    /* Surfaces */
    --bg-primary: #0b0f1a;
    --bg-secondary: #111827;
    --bg-elevated: rgba(17, 24, 39, 0.92);
    --bg-hover: rgba(255, 255, 255, 0.04);

    /* Glass */
    --glass-bg: rgba(15, 20, 35, 0.88);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-border-light: rgba(255, 255, 255, 0.1);

    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;

    /* Messages */
    --bot-bg: rgba(99, 102, 241, 0.08);
    --bot-border: rgba(99, 102, 241, 0.15);
    --user-bg: rgba(20, 184, 166, 0.08);
    --user-border: rgba(20, 184, 166, 0.15);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
    --gradient-accent: linear-gradient(135deg, #14b8a6, #06b6d4);
    --gradient-glow: linear-gradient(135deg, #818cf8, #c084fc);

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow-primary: 0 0 20px rgba(99, 102, 241, 0.2);
    --shadow-glow-accent: 0 0 20px rgba(20, 184, 166, 0.2);

    /* Spacing */
    --header-height: 72px;
    --input-height: 120px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
}

/* ========================================
   Reset & Base
   ======================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* ========================================
   Animated Background
   ======================================== */
.bg-effects {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15), transparent 70%);
    top: -10%;
    left: -5%;
    animation: float-orb-1 20s ease-in-out infinite;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.12), transparent 70%);
    bottom: -10%;
    right: -5%;
    animation: float-orb-2 25s ease-in-out infinite;
}

.bg-orb-3 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(20, 184, 166, 0.1), transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float-orb-3 30s ease-in-out infinite;
}

@keyframes float-orb-1 {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(60px, 40px) scale(1.1);
    }

    66% {
        transform: translate(-30px, 60px) scale(0.95);
    }
}

@keyframes float-orb-2 {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(-50px, -30px) scale(1.05);
    }

    66% {
        transform: translate(40px, -50px) scale(0.9);
    }
}

@keyframes float-orb-3 {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.15);
    }
}

/* ========================================
   Chat Container
   ======================================== */
.chat-container {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-left: 1px solid var(--glass-border);
    border-right: 1px solid var(--glass-border);
}

/* ========================================
   Header
   ======================================== */
.chat-header {
    height: var(--header-height);
    padding: 0 24px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.bot-avatar {
    width: 42px;
    height: 42px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 18px;
    position: relative;
    box-shadow: var(--shadow-glow-primary);
}

.avatar-ring {
    position: absolute;
    inset: -3px;
    border-radius: 14px;
    border: 2px solid transparent;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(167, 139, 250, 0.4)) border-box;
    -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: ring-rotate 4s linear infinite;
}

@keyframes ring-rotate {
    to {
        transform: rotate(360deg);
    }
}

.bot-details h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    background: var(--gradient-glow);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-text {
    font-weight: 500;
}

.pulse {
    width: 7px;
    height: 7px;
    background: #34d399;
    border-radius: 50%;
    position: relative;
}

.pulse::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #34d399;
    border-radius: 50%;
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }

    100% {
        transform: scale(2.8);
        opacity: 0;
    }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-400);
    letter-spacing: 0.02em;
}

.header-badge i {
    font-size: 11px;
}

.header-action-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.header-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--glass-border-light);
}

/* ========================================
   Messages Area
   ======================================== */
.chat-messages {
    flex: 1;
    padding: 24px 24px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.25);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.4);
}

/* ========================================
   Welcome Card
   ======================================== */
.welcome-card {
    text-align: center;
    padding: 40px 24px 30px;
    animation: welcome-in 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: var(--gradient-primary);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    color: white;
    box-shadow: var(--shadow-glow-primary), var(--shadow-md);
    animation: icon-float 3s ease-in-out infinite;
}

@keyframes icon-float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-6px);
    }
}

@keyframes welcome-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.welcome-card h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--gradient-glow);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.welcome-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 440px;
    margin: 0 auto 24px;
}

/* Suggestion Chips */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 520px;
    margin: 0 auto;
}

.chip {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.chip i {
    font-size: 12px;
    color: var(--primary-400);
    transition: color 0.25s ease;
}

.chip:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.chip:hover i {
    color: var(--primary-400);
}

.welcome-card.hidden {
    display: none;
}

/* ========================================
   Messages
   ======================================== */
.message {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: msg-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Bot messages */
.bot-message {
    align-self: flex-start;
}

.bot-message .message-content {
    background: var(--bot-bg);
    border: 1px solid var(--bot-border);
    border-top-left-radius: var(--radius-sm);
}

/* User messages */
.user-message {
    align-self: flex-end;
}

.user-message .message-content {
    background: var(--user-bg);
    border: 1px solid var(--user-border);
    border-top-right-radius: var(--radius-sm);
}

/* Markdown elements inside messages */
.message-content .msg-h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 14px 0 8px;
    letter-spacing: -0.01em;
}

.message-content .msg-h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 12px 0 6px;
}

.message-content .msg-h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary-400);
    margin: 10px 0 6px;
}

.message-content .msg-h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 8px 0 4px;
}

.message-content .msg-h1:first-child,
.message-content .msg-h2:first-child,
.message-content .msg-h3:first-child,
.message-content .msg-h4:first-child {
    margin-top: 0;
}

.message-content .msg-hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--glass-border-light), transparent);
    margin: 12px 0;
}

.message-content .msg-list {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content .msg-list li {
    margin: 4px 0;
    line-height: 1.6;
    color: var(--text-primary);
}

.message-content .msg-list li::marker {
    color: var(--primary-400);
}

.message-content .msg-p {
    margin: 4px 0;
    line-height: 1.7;
}

.message-content .msg-p:first-child {
    margin-top: 0;
}

.message-content .msg-p:last-child {
    margin-bottom: 0;
}

.message-content code {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--accent-400);
}

.message-content strong {
    color: var(--primary-400);
    font-weight: 600;
}

.message-content em {
    color: var(--text-secondary);
    font-style: italic;
}

/* Math/KaTeX styling inside messages */
.message-content .katex {
    font-size: 1.05em;
}

.message-content .katex-display {
    margin: 12px 0;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary-500);
    overflow-x: auto;
}

/* Timestamp */
.timestamp {
    font-size: 10px;
    color: var(--text-tertiary);
    padding: 0 6px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.user-message .timestamp {
    align-self: flex-end;
}

/* Math/KaTeX styling inside messages */
.message-content .katex {
    font-size: 1.05em;
}

.message-content .katex-display {
    margin: 12px 0;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary-500);
    overflow-x: auto;
}

/* Code blocks inside messages */
.message-content code {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.message-content strong {
    color: var(--primary-400);
    font-weight: 600;
}

/* ========================================
   Typing Indicator
   ======================================== */
.typing-indicator {
    padding: 8px 24px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: msg-in 0.3s ease;
}

.typing-avatar {
    width: 28px;
    height: 28px;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 12px;
    flex-shrink: 0;
}

.typing-bubble {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    background: var(--bot-bg);
    border: 1px solid var(--bot-border);
    border-radius: var(--radius-md);
    border-top-left-radius: var(--radius-sm);
}

.typing-bubble span {
    width: 7px;
    height: 7px;
    background: var(--primary-400);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
    opacity: 0.6;
}

.typing-bubble span:nth-child(1) {
    animation-delay: 0s;
}

.typing-bubble span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-bubble span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

.hidden {
    display: none !important;
}

/* ========================================
   Input Area
   ======================================== */
.chat-input-area {
    padding: 16px 24px 14px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

#chat-form {
    display: flex;
}

.input-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-lg);
    padding: 4px 4px 4px 18px;
    transition: all 0.25s ease;
}

.input-wrapper:focus-within {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08), var(--shadow-sm);
}

#user-input {
    flex: 1;
    background: none;
    border: none;
    padding: 10px 12px 10px 0;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

#user-input::placeholder {
    color: var(--text-tertiary);
}

#send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--gradient-accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 15px;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow-accent);
}

#send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 24px rgba(20, 184, 166, 0.3);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    background: rgba(100, 116, 139, 0.3);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.input-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
    letter-spacing: 0.01em;
}

.input-footer .separator {
    opacity: 0.4;
}

/* ========================================
   Chat Toggle (hidden in fullscreen mode)
   ======================================== */
.chat-toggle {
    display: none;
}

.close-btn {
    display: none;
}

/* ========================================
   Mobile Responsive
   ======================================== */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
        border-left: none;
        border-right: none;
    }

    .chat-header {
        padding: 0 16px;
    }

    .header-badge {
        display: none;
    }

    .chat-messages {
        padding: 16px;
    }

    .welcome-card {
        padding: 28px 16px 24px;
    }

    .welcome-card h2 {
        font-size: 20px;
    }

    .welcome-card p {
        font-size: 13px;
    }

    .suggestion-chips {
        gap: 6px;
    }

    .chip {
        font-size: 12px;
        padding: 7px 12px;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-area {
        padding: 12px 16px 10px;
    }

    .input-wrapper {
        padding: 3px 3px 3px 14px;
    }

    #send-btn {
        width: 38px;
        height: 38px;
    }

    .bg-orb-1 {
        width: 300px;
        height: 300px;
    }

    .bg-orb-2 {
        width: 250px;
        height: 250px;
    }

    .bg-orb-3 {
        width: 200px;
        height: 200px;
    }
}

@media (max-width: 380px) {
    .welcome-icon {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    .welcome-card h2 {
        font-size: 18px;
    }

    .chip {
        font-size: 11px;
        padding: 6px 10px;
    }

    .chip i {
        display: none;
    }
}

/* ========================================
   Selection & focus styles
   ======================================== */
::selection {
    background: rgba(99, 102, 241, 0.3);
    color: white;
}

:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
}