/* ========== VARIABLES ========== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #ec4899;
    --accent: #06b6d4;
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --bg-card: #2d2d4a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
    --gradient-1: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    --gradient-2: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    --radius: 12px;
    --radius-lg: 16px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ========== RESET & BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

/* ========== APP CONTAINER ========== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--gradient-1);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-light);
    transform: translateY(-1px);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 600;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--bg-card);
    border-color: var(--primary-light);
}

.history-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
}

.history-item i {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.history-title {
    flex: 1;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
}

.history-item.active .history-title {
    color: var(--text-primary);
}

.history-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-item:hover .history-actions {
    opacity: 1;
}

.history-actions button {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.history-actions button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.clear-history-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.clear-history-btn:hover {
    color: var(--secondary);
    border-color: var(--secondary);
}

/* ========== MAIN CONTENT ========== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ========== HEADER ========== */
.header {
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.menu-toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: var(--radius);
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.menu-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
}

.header-icon {
    font-size: 1.3rem;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

/* ========== CHAT CONTAINER ========== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* ========== WELCOME SCREEN ========== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

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

.welcome-content {
    max-width: 900px;
    width: 100%;
}

.welcome-icon {
    width: 100px;
    height: 100px;
    background: var(--gradient-1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin: 0 auto 24px;
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.welcome-screen h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 1.15rem;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}

.feature-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.feature-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-light);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.feature-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.feature-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.suggested-questions {
    margin-top: 20px;
}

.suggested-title {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.suggested-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.chip {
    padding: 10px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chip:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-light);
    color: var(--text-primary);
    transform: translateY(-1px);
}

/* ========== MESSAGES - Estilo Chat Conversacional ========== */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    padding-bottom: 100px;
}

.message {
    display: flex;
    gap: 8px;
    animation: messageSlide 0.3s ease;
    max-width: 85%;
}

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

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

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    margin-top: 4px;
}

.message.user .message-avatar {
    background: var(--gradient-2);
}

.message.assistant .message-avatar {
    background: var(--gradient-1);
}

/* Burbujas de chat tipo WhatsApp */
.message-content {
    padding: 10px 14px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.message.assistant .message-content {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Contenido de los mensajes */
.message-content p {
    margin: 0;
}

.message-content p + p {
    margin-top: 8px;
}

/* Estilos para KaTeX matemáticas */
.message-content .katex {
    font-size: 1.1em;
}

.message-content .math-inline {
    display: inline;
}

.message-content .math-display {
    display: block;
    margin: 10px 0;
    overflow-x: auto;
}

/* Headers en chat */
.message-content .chat-header-small,
.message-content .chat-header-medium,
.message-content .chat-header-large {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}

.message-content .chat-header-small { font-size: 1rem; }
.message-content .chat-header-medium { font-size: 1.1rem; }
.message-content .chat-header-large { font-size: 1.2rem; }

/* Código inline */
.message-content code {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.message.assistant .message-content code {
    background: rgba(255, 255, 255, 0.1);
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Bloques de código */
.message-content pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    overflow-x: auto;
    margin: 10px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1.5;
}

/* Listas en chat */
.message-content ul {
    margin: 8px 0;
    padding-left: 18px;
}

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

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
}

.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content .katex {
    font-size: 1.1em;
}

.message-content .katex-display {
    margin: 16px 0;
    overflow-x: auto;
}

/* Step by step styling */
.step-box {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--primary);
    padding: 16px;
    margin: 12px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.step-number {
    display: inline-block;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 28px;
    font-weight: 600;
    font-size: 0.85rem;
    margin-right: 10px;
}

/* Graph container in messages */
.graph-container {
    margin: 16px 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.graph-header {
    background: var(--bg-tertiary);
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.graph-header i {
    color: var(--accent);
}

.graph-container .js-plotly-plot {
    height: 400px !important;
}

/* ========== INPUT AREA ========== */
.input-area {
    padding: 20px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-container {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
}

textarea {
    width: 100%;
    padding: 16px 56px 16px 56px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-sans);
    resize: none;
    min-height: 56px;
    max-height: 200px;
    outline: none;
    transition: all 0.2s ease;
}

textarea:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

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

.send-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.send-btn.spinning i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 10px;
}

.input-hint i {
    margin-right: 4px;
}

/* ========== IMAGE UPLOAD ========== */
.attach-btn {
    position: absolute;
    left: 12px;
    bottom: 12px;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.attach-btn:hover {
    background: var(--bg-card);
    color: var(--primary-light);
    border-color: var(--primary-light);
}

.attach-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

textarea.with-attach {
    padding-left: 64px;
}

.image-preview-area {
    max-width: 900px;
    margin: 0 auto 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 4px;
}

.image-preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.image-preview-item .remove-image:hover {
    background: var(--secondary);
    transform: scale(1.1);
}

.image-preview-item .upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--bg-tertiary);
}

.image-preview-item .upload-progress-bar {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

/* Image in message */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    margin-top: 8px;
    border: 1px solid var(--border);
}

.message-images-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.message-image-wrapper {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.message-image-wrapper img {
    max-width: 200px;
    max-height: 200px;
    object-fit: cover;
    display: block;
}

/* ========== INTERACTIVE EXERCISES - V2 ULTRA COMPACT ========== */
.exercise-container {
    display: inline-block;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin: 4px 0;
    min-width: 200px;
    max-width: 320px;
}

.exercise-container.answered {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.05);
}

.exercise-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--border);
}

.exercise-icon { font-size: 0.8rem; }

.exercise-title {
    font-weight: 600;
    color: var(--primary-light);
    font-size: 0.65rem;
    text-transform: uppercase;
}

.exercise-question {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.3;
}

.exercise-input-row {
    display: flex;
    gap: 5px;
    align-items: center;
}

.exercise-input {
    width: 90px;
    padding: 5px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}

.exercise-input:focus { border-color: var(--primary-light); }

.exercise-input.small {
    width: 40px;
    text-align: center;
    padding: 5px 3px;
}

.exercise-fraction-input {
    display: flex;
    align-items: center;
    gap: 3px;
}

.fraction-line {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.exercise-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.exercise-choice-btn {
    padding: 5px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 45px;
}

.exercise-choice-btn:hover {
    border-color: var(--primary-light);
    background: var(--bg-card);
}

.exercise-choice-btn.correct {
    background: rgba(16, 185, 129, 0.2);
    border-color: #10b981;
    color: #10b981;
}

.exercise-submit-btn {
    padding: 5px 12px;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
}

.exercise-submit-btn:hover { background: var(--primary-light); }

.exercise-hint-btn {
    padding: 3px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.65rem;
    cursor: pointer;
    margin-top: 4px;
}

.exercise-hint {
    margin-top: 4px;
    padding: 4px 6px;
    background: rgba(6, 182, 212, 0.1);
    border-left: 2px solid var(--accent);
    border-radius: 0 4px 4px 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.exercise-feedback {
    margin-top: 4px;
    font-size: 0.8rem;
}

.exercise-correct { color: #10b981; }
.exercise-incorrect { color: #ef4444; }

.exercise-completed-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 8px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid #10b981;
    border-radius: 12px;
    color: #10b981;
    font-size: 0.75rem;
    margin-top: 3px;
}

.exercise-completed-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ========== GRAPH LOADING INDICATOR ========== */
.graph-loading {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--accent);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    display: none;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
    z-index: 1000;
    animation: pulse 1.5s infinite;
}

.graph-loading i {
    font-size: 1.1rem;
}

/* ========== TYPING INDICATOR ========== */
.typing-indicator {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 12px 20px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

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

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

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

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

/* ========== GRAPH PANEL ========== */
.graph-panel {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.graph-panel.open {
    right: 0;
}

.graph-panel-header {
    height: 60px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.graph-panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.graph-panel-header h2 i {
    color: var(--accent);
}

.close-panel-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}

.close-panel-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.graph-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.panel-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Graph Tabs */
.graph-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.graph-tab {
    flex: 1;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.graph-tab:hover {
    background: var(--bg-card);
}

.graph-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.graph-section {
    display: none;
}

.graph-section.active {
    display: block;
}

.graph-input-area {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.graph-input-area label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.graph-input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.graph-input-row input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-mono);
    outline: none;
}

.graph-input-row input:focus {
    border-color: var(--primary-light);
}

.graph-input-row button {
    padding: 12px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.graph-input-row button:hover {
    background: #0891b2;
    transform: translateY(-1px);
}

.range-inputs {
    display: flex;
    gap: 12px;
}

.range-group {
    flex: 1;
}

.range-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.range-group input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

.graph-display {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 400px;
    margin-bottom: 16px;
}

.graph-examples {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.graph-examples h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 500;
}

.example-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.example-chip {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.example-chip:hover {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text-primary);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-card);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
    .graph-panel {
        width: 400px;
        right: -400px;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: flex;
    }

    .features-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .graph-panel {
        width: 100%;
        right: -100%;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 0 12px;
        height: 50px;
    }

    .header-title {
        font-size: 0.9rem;
    }

    .header-title span:last-child {
        display: none;
    }

    .header-btn {
        width: 36px;
        height: 36px;
    }

    .chat-container {
        padding: 12px;
    }

    .welcome-screen h1 {
        font-size: 1.5rem;
    }

    .welcome-subtitle {
        font-size: 0.9rem;
        padding: 0 16px;
    }

    .features-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .feature-card {
        padding: 14px;
    }

    .feature-card h3 {
        font-size: 0.95rem;
    }

    .feature-card p {
        font-size: 0.8rem;
    }

    .suggested-chips {
        gap: 8px;
    }

    .chip {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .message-content {
        max-width: calc(100% - 45px);
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .input-area {
        padding: 10px 12px;
    }

    .input-container {
        min-height: 50px;
    }

    textarea {
        padding: 12px 48px 12px 48px;
        font-size: 16px; /* Previene zoom en iOS */
    }

    .send-btn, .attach-btn {
        width: 36px;
        height: 36px;
        bottom: 7px;
    }

    .attach-btn {
        left: 8px;
    }

    .send-btn {
        right: 8px;
    }

    /* Ejercicios en móvil */
    .exercise-container {
        padding: 6px 8px;
        margin: 3px 0;
        min-width: 180px;
        max-width: 280px;
    }

    .exercise-header {
        margin-bottom: 3px;
        padding-bottom: 2px;
    }

    .exercise-title {
        font-size: 0.6rem;
    }

    .exercise-question {
        font-size: 0.85rem;
        margin-bottom: 4px;
        line-height: 1.25;
    }

    .exercise-input {
        width: 80px;
        padding: 4px 6px;
        font-size: 16px;
    }

    .exercise-input.small {
        width: 35px;
        padding: 4px 2px;
    }

    .exercise-input-row {
        gap: 4px;
    }

    .exercise-choices {
        gap: 3px;
    }

    .exercise-choice-btn {
        padding: 4px 8px;
        font-size: 0.75rem;
        min-width: 40px;
    }

    .exercise-submit-btn {
        padding: 4px 10px;
        font-size: 0.75rem;
    }

    .exercise-fraction-input {
        gap: 2px;
    }

    .fraction-line {
        font-size: 0.8rem;
    }

    .exercise-hint-btn {
        padding: 2px 6px;
        font-size: 0.6rem;
        margin-top: 3px;
    }

    .exercise-hint {
        margin-top: 3px;
        padding: 3px 5px;
        font-size: 0.7rem;
    }

    .exercise-feedback {
        margin-top: 3px;
        font-size: 0.75rem;
    }

    .exercise-completed-badge {
        padding: 2px 6px;
        font-size: 0.7rem;
    }

    .exercise-completed-text {
        font-size: 0.7rem;
    }

    .graph-panel-content {
        padding: 12px;
    }

    .graph-tabs {
        flex-direction: column;
    }

    .range-inputs {
        flex-direction: column;
        gap: 8px;
    }

    .graph-examples {
        padding: 12px;
    }

    .example-chips {
        gap: 6px;
    }

    .example-chip {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Image previews en móvil */
    .image-preview-area {
        gap: 6px;
    }

    .image-preview-item {
        width: 60px;
        height: 60px;
    }

    /* Sidebar en móvil */
    .sidebar {
        width: 280px;
    }

    .sidebar-header {
        padding: 16px;
    }

    .logo-text {
        font-size: 1.1rem;
    }

    .new-chat-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    /* Typing indicator */
    .typing-indicator {
        left: 12px;
        bottom: 70px;
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* ========== LOADING & ANIMATIONS ========== */
.loading-shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-card) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Math expression highlighting */
.math-expression {
    font-family: var(--font-mono);
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent);
}

/* Success message */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 14px 24px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: #22c55e;
}

.toast.success i {
    color: #22c55e;
}

.toast.error {
    border-color: #ef4444;
}

.toast.error i {
    color: #ef4444;
}