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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .chat-container {
            width: 100%;
            max-width: 900px;
            height: 90vh;
            background: #ffffff;
            border-radius: 16px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .chat-header {
            background: linear-gradient(135deg, #059669 0%, #047857 100%);
            color: white;
            padding: 20px;
            position: relative;
        }

        .chat-header-top {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
        }

        .chat-header h1 {
            font-size: 1.5rem;
            font-weight: 600;
            margin-bottom: 4px;
        }

        .chat-header p {
            font-size: 0.875rem;
            opacity: 0.9;
        }

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

        .btn-header {
            background: rgba(255,255,255,0.2);
            border: none;
            color: white;
            padding: 8px 14px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 0.8rem;
            transition: background 0.2s;
            display: flex;
            align-items: center;
            gap: 6px;
            text-decoration: none;
        }

        .btn-header:hover {
            background: rgba(255,255,255,0.3);
        }

        .toggle-container {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-top: 16px;
            padding-top: 16px;
            border-top: 1px solid rgba(255,255,255,0.2);
        }

        .toggle-label {
            font-size: 0.875rem;
            opacity: 0.9;
        }

        .toggle {
            position: relative;
            width: 44px;
            height: 24px;
        }

        .toggle input {
            opacity: 0;
            width: 0;
            height: 0;
        }

        .toggle-slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255,255,255,0.3);
            border-radius: 24px;
            transition: 0.3s;
        }

        .toggle-slider:before {
            position: absolute;
            content: "";
            height: 18px;
            width: 18px;
            left: 3px;
            bottom: 3px;
            background: white;
            border-radius: 50%;
            transition: 0.3s;
        }

        .toggle input:checked + .toggle-slider {
            background: #fbbf24;
        }

        .toggle input:checked + .toggle-slider:before {
            transform: translateX(20px);
        }

        .chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 20px;
            background: #f9fafb;
        }

        .message {
            margin-bottom: 16px;
            display: flex;
            gap: 12px;
            animation: fadeIn 0.3s ease;
        }

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

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

        .message-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
            font-weight: 600;
            flex-shrink: 0;
        }

        .message.assistant .message-avatar {
            background: linear-gradient(135deg, #059669 0%, #047857 100%);
            color: white;
        }

        .message.user .message-avatar {
            background: #3b82f6;
            color: white;
        }

        .message-content {
            max-width: 75%;
            padding: 14px 18px;
            border-radius: 16px;
            line-height: 1.6;
            font-size: 0.95rem;
        }

        .message.assistant .message-content {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 16px 16px 16px 4px;
            color: #1f2937;
        }

        .message.user .message-content {
            background: #3b82f6;
            color: white;
            border-radius: 16px 16px 4px 16px;
        }

        .message-content pre {
            background: #1f2937;
            color: #e5e7eb;
            padding: 12px;
            border-radius: 8px;
            overflow-x: auto;
            margin: 10px 0;
            font-size: 0.85rem;
        }

        .message-content code {
            background: #f3f4f6;
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 0.85rem;
            color: #1f2937;
        }

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

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

        /* Citations */
        .citations {
            margin-top: 14px;
            padding-top: 14px;
            border-top: 1px solid #e5e7eb;
        }

        .citations-title {
            font-size: 0.7rem;
            color: #6b7280;
            text-transform: uppercase;
            margin-bottom: 8px;
            font-weight: 600;
        }

        .citation-item {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            font-size: 0.75rem;
            background: #ecfdf5;
            color: #047857;
            padding: 4px 10px;
            border-radius: 6px;
            margin-right: 6px;
            margin-bottom: 6px;
        }

        .citation-item.web {
            background: #fef3c7;
            color: #92400e;
        }

        .citation-item a {
            color: inherit;
            text-decoration: none;
        }

        .citation-item a:hover {
            text-decoration: underline;
        }

        .no-results {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: #991b1b;
            padding: 12px;
            border-radius: 8px;
            font-size: 0.875rem;
            margin-top: 10px;
        }

        .chat-input-container {
            padding: 20px;
            background: white;
            border-top: 1px solid #e5e7eb;
        }

        .chat-input-wrapper {
            display: flex;
            gap: 12px;
            align-items: flex-end;
        }

        .chat-input {
            flex: 1;
            padding: 14px 18px;
            border: 2px solid #e5e7eb;
            border-radius: 24px;
            font-size: 1rem;
            outline: none;
            transition: border-color 0.2s;
            resize: none;
            max-height: 120px;
            font-family: inherit;
        }

        .chat-input:focus {
            border-color: #059669;
        }

        .send-button {
            width: 50px;
            height: 50px;
            border: none;
            background: linear-gradient(135deg, #059669 0%, #047857 100%);
            color: white;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .send-button:hover:not(:disabled) {
            transform: scale(1.05);
            box-shadow: 0 4px 12px rgba(5, 150, 105, 0.4);
        }

        .send-button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        .send-button svg {
            width: 22px;
            height: 22px;
        }

        .typing-indicator {
            display: flex;
            gap: 4px;
            padding: 14px 18px;
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 16px;
            width: fit-content;
        }

        .typing-indicator span {
            width: 8px;
            height: 8px;
            background: #9ca3af;
            border-radius: 50%;
            animation: bounce 1.4s infinite ease-in-out;
        }

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

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

        .error-message {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: #dc2626;
            padding: 12px 16px;
            border-radius: 8px;
            margin-bottom: 16px;
        }

        /* Toggle divider */
        .toggle-divider {
            opacity: 0.3;
            margin: 0 4px;
        }

        /* Quiz mode toggle slider */
        .toggle input:checked + .toggle-slider.quiz-slider {
            background: #22c55e;
        }

        /* Quiz Response Styles */
        .quiz-response .message-avatar {
            background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%) !important;
        }

        .quiz-result {
            padding: 0;
        }

        .quiz-result.found {
            border-left: 4px solid #22c55e;
            padding-left: 16px;
        }

        .quiz-result.not-found {
            text-align: center;
            padding: 20px;
        }

        .quiz-match-score {
            display: inline-block;
            background: #dcfce7;
            color: #166534;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.75rem;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .quiz-materia {
            color: #f59e0b;
            font-size: 0.75rem;
            text-transform: uppercase;
            font-weight: 600;
            margin-bottom: 8px;
            letter-spacing: 0.5px;
        }

        .quiz-question-original {
            color: #6b7280;
            font-size: 0.9rem;
            margin-bottom: 16px;
            padding: 10px;
            background: #f9fafb;
            border-radius: 8px;
        }

        .quiz-answer {
            background: linear-gradient(135deg, #dcfce7 0%, #d1fae5 100%);
            padding: 16px;
            border-radius: 12px;
            margin-bottom: 12px;
        }

        .quiz-answer .answer-label {
            display: block;
            font-size: 0.7rem;
            color: #166534;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 6px;
        }

        .quiz-answer .answer-text {
            font-size: 1.1rem;
            font-weight: 600;
            color: #15803d;
        }

        .quiz-wrong-answers {
            margin-top: 12px;
            padding: 12px;
            background: #fef2f2;
            border-radius: 8px;
        }

        .quiz-wrong-answers .wrong-label {
            display: block;
            font-size: 0.7rem;
            color: #991b1b;
            font-weight: 600;
            text-transform: uppercase;
            margin-bottom: 8px;
        }

        .quiz-wrong-answers ul {
            margin: 0;
            padding-left: 18px;
            color: #b91c1c;
            font-size: 0.85rem;
        }

        .quiz-wrong-answers li {
            margin: 4px 0;
        }

        .quiz-alternatives {
            margin-top: 12px;
            padding: 10px;
            background: #f3f4f6;
            border-radius: 8px;
            font-size: 0.8rem;
        }

        .quiz-alternatives .alt-label {
            display: block;
            font-size: 0.7rem;
            color: #6b7280;
            font-weight: 600;
            margin-bottom: 6px;
        }

        .quiz-alternatives ul {
            margin: 0;
            padding-left: 16px;
            color: #4b5563;
        }

        .quiz-not-found-icon {
            width: 60px;
            height: 60px;
            background: #fef2f2;
            color: #dc2626;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            font-weight: bold;
            margin: 0 auto 16px;
        }

        .quiz-not-found-msg {
            color: #1f2937;
            font-size: 1rem;
            margin-bottom: 12px;
        }

        .quiz-suggestion {
            background: #fef3c7;
            padding: 12px;
            border-radius: 8px;
            font-size: 0.85rem;
            color: #92400e;
            margin-bottom: 10px;
        }

        .quiz-tip {
            color: #6b7280;
            font-size: 0.8rem;
            font-style: italic;
        }

        @media (max-width: 640px) {
            body { padding: 0; }
            .chat-container {
                height: 100vh;
                border-radius: 0;
            }
            .message-content { max-width: 85%; }
            .header-actions { flex-direction: column; gap: 4px; }
            .toggle-container { flex-wrap: wrap; }
        }
