/* ============================================
   LIGHT MODE (default)
   ============================================ */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --text-primary: #0d0d0d;
    --text-secondary: #565869;
    --border-color: #d1d5db;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --button-hover: #f0f0f1;
    --accent-color: #10a37f;
    --accent-dark: #088860;
    --message-user-bg: #10a37f;
    --message-bot-bg: #f7f7f8;
    --message-user-text: #ffffff;
    --message-bot-text: #0d0d0d;
    --header-bg: #ffffff;
    --header-border: #d1d5db;
    --sidebar-bg: #ffffff;
    --sidebar-border: #d1d5db;
}

/* ============================================
   DARK MODE - OVERRIDE
   ============================================ */
[data-theme="dark"] {
    --bg-primary: #191919;
    --bg-secondary: #2a2a2a;
    --text-primary: #ececf1;
    --text-secondary: #c5c5d2;
    --border-color: #4d4d4d;
    --input-bg: #2a2a2a;
    --input-border: #4d4d4d;
    --button-hover: #343541;
    --message-user-bg: #10a37f;
    --message-bot-bg: #343541;
    --message-user-text: #ffffff;
    --message-bot-text: #ececf1;
    --header-bg: #191919;
    --header-border: #4d4d4d;
    --sidebar-bg: #1a1a1a;
    --sidebar-border: #4d4d4d;
}

/* ============================================
   RESET
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: all 0.3s ease;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.menu-toggle-btn {
    display: none;
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    padding: 8px;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
}

.menu-toggle-btn:hover {
    background: var(--border-color);
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 24px;
    height: 18px;
}

.hamburger-icon::before,
.hamburger-icon::after,
.hamburger-icon span {
    content: '';
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    border-radius: 2px;
}

.hamburger-icon span {
    content: '';
}

.menu-toggle-btn.active .hamburger-icon::before {
    transform: rotate(45deg) translate(8px, 8px);
}

.menu-toggle-btn.active .hamburger-icon span {
    opacity: 0;
}

.menu-toggle-btn.active .hamburger-icon::after {
    transform: rotate(-45deg) translate(8px, -8px);
}

.logo {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.theme-btn {
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

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

/* ============================================
   CONTAINER
   ============================================ */
.container {
    display: flex;
    height: calc(100vh - 54px);
    max-width: 1400px;
    margin: 0 auto;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 12px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.new-chat-btn:hover {
    background: var(--accent-dark);
}

/* Material Symbols icon size reduction */
.new-chat-btn .material-symbols-rounded {
    font-size: 20px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: var(--button-hover);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: var(--text-primary);
    border: 1px solid transparent;
    margin-bottom: 5px;
}

.history-item:hover {
    background: var(--border-color);
}

.history-item.active {
    background: var(--accent-color);
    color: var(--message-user-text);
    border-color: var(--accent-dark);
    font-weight: 600;
}

.history-item-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-delete-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px;
    opacity: 0.6;
    transition: all 0.2s ease;
}

.history-delete-btn:hover {
    opacity: 1;
}

.discipline-list {
    list-style: none;
}

.discipline-list li {
    margin-bottom: 8px;
}

.discipline-list a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.discipline-list a:hover {
    background: var(--button-hover);
    color: var(--accent-color);
}

.sidebar-search {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-search-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.sidebar-search-icon {
    position: absolute;
    left: 12px;
    font-size: 0.95rem;
    opacity: 0.7;
    pointer-events: none;
}

.sidebar-search-input {
    width: 100%;
    padding: 11px 12px 11px 36px;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.92rem;
    outline: none;
    transition: all 0.2s ease;
}

.sidebar-search-input::placeholder {
    color: var(--text-secondary);
}

.sidebar-search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.08);
}

.discipline-list {
    list-style: none;
}

.discipline-list.filtered-empty::after {
    content: "Nenhuma disciplina encontrada.";
    display: block;
    padding: 12px;
    border-radius: 8px;
    background: var(--button-hover);
    color: var(--text-secondary);
    font-size: 0.88rem;
    text-align: center;
}

.discipline-list li.is-hidden {
    display: none;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
}

.welcome-content h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.welcome-content p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.quick-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.quick-btn {
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

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

/* ============================================
   CHAT MESSAGES
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    animation: slideUp 0.3s ease;
}

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

.message.user {
    justify-content: flex-end;
}

.message.user .message-content {
    background: var(--message-user-bg);
    color: var(--message-user-text);
    border-radius: 12px 4px 12px 12px;
}

.message.bot .message-content {
    background: var(--message-bot-bg);
    color: var(--message-bot-text);
    border-radius: 4px 12px 12px 12px;
}

.message-content {
    white-space: pre-wrap;
    max-width: 70%;
    padding: 12px 16px;
    word-wrap: break-word;
    line-height: 1.5;
}

.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.4;
}

.message-content h2 {
    font-size: 1.4em;
}

.message-content h3 {
    font-size: 1.2em;
}

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

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

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

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

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

.message-content code {
    white-space: pre-wrap;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    word-break: break-word;
}

/* Limpar espaços extras e caracteres especiais */
.message-content {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Garantir que não apareçam símbolos markdown residuais (preservar placeholders/math inline) */
.message-content :empty:not(.math-inline):not(.math-display):not(.latex-placeholder):not(.latex-fallback):not(.math-inline-fallback):not(.math-display-fallback) {
    display: none;
}

.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-top: 8px;
}

.message-file {
    max-width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    font-size: 0.9em;
}

.typing-indicator {
    display: flex;
  gap: 6px;
  padding: 8px 12px;
  align-items: center;
  min-height: 30px;
}

.typing-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-color);
  animation: bounce 1.4s infinite;
  display: inline-block;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% {
    opacity: 0.5;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-10px);
  }
}

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

.input-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.discipline-select {
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.discipline-select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

.type-buttons {
    display: flex;
    gap: 6px;
}

.type-btn {
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.type-btn:hover {
    background: var(--button-hover);
}

.type-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

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

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

.message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: all 0.2s ease;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.input-actions {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.action-btn {
    padding: 10px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--button-hover);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

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

.send-btn {
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--button-hover);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    font-size: 0;
    position: relative;
}

.send-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.send-btn::after {
    content: '➤';
    font-size: 18px;
    display: block;
}

/* Material Symbols icon styling */
.send-btn .material-symbols-rounded {
    font-size: 20px;
}

.file-preview {
    position: relative;
    display: inline-block;
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
}

.file-preview img {
    max-width: 200px;
    max-height: 200px;
    display: block;
}

.file-preview-text {
    padding: 8px 12px;
    background: var(--message-bot-bg);
    border-radius: 6px;
    display: inline-block;
    color: var(--text-primary);
    font-size: 0.9em;
}

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

.remove-file-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.emoji-picker-container {
    position: absolute;
    bottom: 300px;
    left: 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    max-width: 350px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.emoji-btn {
    background: var(--button-hover);
    border: none;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.emoji-btn:hover {
    background: var(--border-color);
    transform: scale(1.1);
}

.input-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0 4px;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* ============================================
   RESPONSIVO
   ============================================ */
@media (max-width: 768px) {
    .menu-toggle-btn {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        top: 54px;
        height: calc(100vh - 54px);
        z-index: 999;
        width: 260px;
        transition: left 0.3s ease;
        background: var(--sidebar-bg);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open {
        left: 0;
    }

    .container::before {
        content: '';
        position: fixed;
        top: 54px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        opacity: 0;
        pointer-events: none;
        z-index: 998;
        transition: opacity 0.3s ease;
    }

    .container.sidebar-open::before {
        opacity: 1;
        pointer-events: auto;
    }

    .message-content {
        white-space: pre-wrap;
        max-width: 85%;
    }

    .quick-buttons {
        grid-template-columns: 1fr;
    }

    .sidebar-search-input {
        font-size: 0.95rem;
    }

    .input-toolbar {
        flex-direction: column;
    }

    .discipline-select,
    .type-buttons {
        width: 100%;
    }

    .type-buttons {
        justify-content: space-between;
    }

    .type-btn {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 0.95rem;
    }

    .message-content {
        white-space: pre-wrap;
        max-width: 90%;
        font-size: 0.95rem;
    }

    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ============================================
   TRANSIÇÕES
   ============================================ */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

button, input, textarea, select {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.discipline-search {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.discipline-search:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

.discipline-search::placeholder {
    color: var(--text-secondary);
}

.file-message {
  margin-top: 8px;
  padding: 8px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
}

.file-message img {
  display: block;
  margin-top: 5px;
}