/* --- VARIÁVEIS (TEMA) --- */
:root {
    --bg-body: #161616; /* Cinza super escuro (fundo principal) */
    --bg-sidebar: #111111; /* Quase preto */
    --bg-header: #111111;
    --bg-input: #222222; /* Cinza para destacar inputs */
    --bg-textarea: #1a1a1a;
    --bg-modal: #1c1c1c;
    --bg-modal-overlay: rgba(0, 0, 0, 0.8);
    --bg-panel: #1e1e1e;
    --border-color: #333333; /* Bordas sóbrias */
    --text-primary: #f0f0f0; /* Branco gelo para não cansar a vista */
    --text-secondary: #888888; /* Cinza médio */
    --text-ai: #f0f0f0;
    --accent-color: #AF9061; /* O BEGE MANTIDO COMO DESTAQUE */
    --accent-color-rgb: 175, 144, 97;
    --accent-gold: #AF9061;
    --accent-hover: #c4a574;
    --accent-text: #111111; /* Texto sobre fundo accent (escuro no dark, claro no light) */
    --fighter-1: #AF9061;
    --fighter-2: #888888;
    --msg-user-bg: #262626; /* Bolha do usuário cinza elegante */
    --msg-user-text: #ffffff;
    --msg-ai-bg: transparent;
    --ui-font-size: 16px;
    --chat-font-size: 16px;
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

[data-theme="light"] {
    --bg-body: #f5f5f5; /* Cinza clarinho executivo */
    --bg-sidebar: #ffffff;
    --bg-header: #ffffff;
    --bg-input: #ffffff;
    --bg-textarea: #f9f9f9;
    --bg-modal: #ffffff;
    --bg-modal-overlay: rgba(255, 255, 255, 0.8);
    --bg-panel: #ffffff;
    --border-color: #e0e0e0;
    --text-primary: #121212; /* Quase preto */
    --text-secondary: #666666;
    --text-ai: #121212;
    --accent-color: #121212; /* No light mode, o destaque principal vira Preto */
    --accent-color-rgb: 18, 18, 18;
    --accent-gold: #AF9061; /* Bege se mantém para pequenos detalhes */
    --accent-hover: #333333;
    --accent-text: #ffffff; /* Texto sobre fundo accent no light mode */
    --fighter-1: #121212;
    --fighter-2: #AF9061;
    --msg-user-bg: #e5e5e5;
    --msg-user-text: #121212;
    --msg-ai-bg: #ffffff;
}

/* --- BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background-color: var(--bg-body); color: var(--text-primary); display: flex; height: 100vh; height: 100dvh; overflow: hidden; font-size: var(--ui-font-size); transition: background-color 0.3s, color 0.3s; }
body.blur-mode main { filter: blur(10px); transition: filter 0.3s; }

/* --- UTILITÁRIOS --- */
.hidden { display: none !important; }
.flex-spacer { flex: 1; }
.text-center { text-align: center; }
.mt-10 { margin-top: 10px; }
.mt-15 { margin-top: 15px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.w-100 { width: 100%; }
.no-border { border: none; }
.cursor-pointer { cursor: pointer; }
.opacity-70 { opacity: 0.7; }
.text-danger { color: #d9534f; }
.backdrop-blur { -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.empty-state { text-align: center; color: var(--text-secondary); margin-top: 50px; }

/* --- SIDEBAR --- */
#sidebar-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 9; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
#sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

aside { width: 280px; background-color: var(--bg-sidebar); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; flex-shrink: 0; z-index: 10; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease, background-color 0.3s; overflow: hidden; white-space: nowrap; }
aside.closed { width: 0; border-right: none; }
aside.closed .sidebar-top, aside.closed .history-list, aside.closed .sidebar-footer { opacity: 0; pointer-events: none; }

.sidebar-top { padding: 15px; border-bottom: 1px solid var(--border-color); }
.sidebar-mobile-header { display: none; }
.mode-switcher { display: flex; gap: 5px; background: var(--bg-input); padding: 4px; border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--border-color); }
.mode-btn { flex: 1; border: none; background: transparent; color: var(--text-secondary); padding: 8px; cursor: pointer; border-radius: 6px; font-weight: 600; font-size: 0.85em; transition: 0.2s; }
.mode-btn.active { background: var(--bg-textarea); color: var(--text-primary); box-shadow: 0 2px 5px rgba(0,0,0,0.3); border: 1px solid var(--border-color); }
[data-theme="light"] .mode-btn.active { box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.mode-btn:hover { color: var(--text-primary); }

.new-chat-btn { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-color); padding: 12px; border-radius: 10px; cursor: pointer; text-align: center; font-weight: 600; font-size: 0.9em; width: 100%; display: block; transition: 0.2s; }
.new-chat-btn:hover { background-color: var(--bg-textarea); border-color: var(--accent-color); color: var(--accent-color); }

.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; padding: 8px; }
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: #444444; border-radius: 2px; }
[data-theme="light"] .history-list::-webkit-scrollbar-thumb { background: #cccccc; }

.history-empty { text-align: center; color: var(--text-secondary); font-size: 0.85em; padding: 24px 10px; opacity: 0.7; }

.history-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 0.9em; color: var(--text-secondary); position: relative; transition: background-color 0.15s, color 0.15s; }
.history-item:hover { background-color: var(--bg-input); color: var(--text-primary); }
.history-item.active { background-color: var(--bg-input); color: var(--text-primary); font-weight: 600; }
.hi-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-actions { display: flex; align-items: center; gap: 1px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.history-item:hover .hi-actions, .history-item.active .hi-actions { opacity: 1; }
/* Em telas de toque, as ações ficam sempre visíveis (não há hover) */
@media (hover: none) { .hi-actions { opacity: 1; } }
.hi-action-btn { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: background-color 0.15s, color 0.15s; }
.hi-action-btn:hover { background-color: var(--bg-textarea); color: var(--text-primary); }
.hi-action-btn.danger:hover { color: #ff5b5b; }

/* Busca de conversas */
.history-search { padding: 8px 8px 2px; }
.history-search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 8px; padding: 8px 10px; transition: border-color 0.15s; }
.history-search-box:focus-within { border-color: var(--accent-color); }
.history-search-box svg { flex-shrink: 0; color: var(--text-secondary); }
.history-search-box input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 0.88em; }
.history-search-box input::placeholder { color: var(--text-secondary); }

/* Rótulos de grupo por data */
.history-group-label { font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-secondary); font-weight: 700; padding: 12px 10px 4px; }
.history-list > .history-group-label:first-child { padding-top: 4px; }

/* Form de troca de senha nas Configurações */
#form-change-password .auth-input-group { margin-bottom: 12px; }
#form-change-password .btn-primary { margin-top: 6px; }

.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 5px; display: flex; align-items: center; justify-content: center; transition: color 0.2s; }
.icon-btn:hover { color: var(--text-primary); }
.delete-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: none; padding: 8px; }
.history-item:hover .delete-btn { display: block; }

.sidebar-footer { padding: 15px; border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; background-color: var(--bg-sidebar); margin-top: auto; }
.user-profile { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 5px 8px; border-radius: 10px; flex: 1; transition: background 0.2s; }
.user-profile:hover { background: var(--bg-input); }
.avatar { width: 36px; height: 36px; min-width: 36px; background: linear-gradient(135deg, var(--accent-color), var(--accent-gold)); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #111; font-size: 0.9em; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.username { font-size: 0.9em; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.settings-btn { padding: 8px; border-radius: 50%; transition: transform 0.6s ease, color 0.3s, background-color 0.3s; }
.settings-btn:hover { color: var(--text-primary); background-color: var(--bg-input); transform: rotate(90deg); }

/* --- MAIN --- */
main { flex: 1; display: flex; flex-direction: column; position: relative; width: 100%; }
header { padding: 15px 20px; border-bottom: 1px solid var(--border-color); background-color: var(--bg-header); display: flex; align-items: center; justify-content: space-between; height: 60px; transition: background-color 0.3s; }
.brand { display: flex; align-items: center; gap: 12px; cursor: default; }

.app-logo { width: 36px; height: 36px; object-fit: contain; filter: none; transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1); cursor: pointer; }
[data-theme="dark"] .app-logo { filter: invert(1); } /* Inverte a logo para branco no dark mode */
.app-logo:hover { transform: rotate(360deg); }

header h1 { font-size: 1.1rem; color: var(--text-primary); letter-spacing: 1px; font-weight: 700; text-transform: uppercase; background: linear-gradient(90deg, var(--accent-color), var(--text-primary)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.theme-toggle { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--text-secondary); padding: 5px; }

.view-section { display: none; flex: 1; flex-direction: column; height: calc(100% - 60px); }
.view-section.active { display: flex; }
#view-dashboard { overflow-y: auto; }

/* Scrollbar customizada — fina, moderna, grudada no canto */
#view-dashboard::-webkit-scrollbar { width: 5px; }
#view-dashboard::-webkit-scrollbar-track { background: transparent; }
#view-dashboard::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
#view-dashboard::-webkit-scrollbar-thumb:hover { background: var(--accent-color); }

/* --- MODAL --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-modal-overlay); z-index: 100; display: none; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s ease; }
.modal-overlay.open { display: flex; opacity: 1; }
.modal-overlay.open .modal { animation: modalSlideIn 0.25s ease-out; }
@keyframes modalSlideIn { from { transform: translateY(12px); opacity: 0.5; } to { transform: translateY(0); opacity: 1; } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.modal { background: var(--bg-modal); width: 850px; max-width: 90%; max-height: 85vh; border-radius: 14px; border: 1px solid var(--border-color); display: flex; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.5); }
[data-theme="light"] .modal { box-shadow: 0 16px 48px rgba(0,0,0,0.15); }
.modal-sidebar { width: 220px; background: var(--bg-sidebar); border-right: 1px solid var(--border-color); padding: 20px; display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.modal-tab { padding: 10px 15px; border-radius: 8px; cursor: pointer; color: var(--text-secondary); font-size: 0.95rem; font-weight: 500; transition: 0.2s; display: flex; align-items: center; gap: 10px; }
.modal-tab.active { background: var(--bg-input); color: var(--accent-color); font-weight: bold; }
.modal-content { flex: 1; padding: 30px; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; }
.close-modal { background: none; border: none; font-size: 1.8rem; color: var(--text-secondary); cursor: pointer; padding: 0 10px; transition: color 0.2s, transform 0.2s; }
.close-modal:hover { color: var(--text-primary); transform: scale(1.1); }

.smart-textarea-container { position: relative; width: 100%; margin-top: 8px; }
.smart-textarea { width: 100%; min-height: 120px; background: var(--bg-textarea); border: 1px solid var(--border-color); color: var(--text-primary); padding: 12px; padding-right: 40px; border-radius: 10px; font-family: inherit; font-size: 0.95rem; resize: vertical; outline: none; white-space: pre-wrap; transition: border-color 0.2s; }
.smart-textarea:focus { border-color: var(--accent-color); }
.expand-btn { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); color: var(--text-secondary); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: background 0.2s, color 0.2s; }
.expand-btn:hover { background: rgba(0,0,0,0.35); color: var(--text-primary); }

.setting-group { margin-bottom: 30px; }
.setting-group h3 { font-size: 0.85rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 15px; letter-spacing: 1px; font-weight: 700; border-left: 3px solid var(--accent-color); padding-left: 10px; }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--border-color); }
.setting-item label { font-size: 1rem; }
.setting-item small { color: var(--text-secondary); font-size: 0.8rem; display: block; margin-top: 4px; }

.modal input[type="text"], .modal select { background: var(--bg-input); border: 1px solid var(--border-color); color: var(--text-primary); padding: 12px; border-radius: 10px; width: 100%; margin-top: 5px; font-size: 1rem; transition: border-color 0.2s; }
.modal input[type="text"]:focus, .modal select:focus { border-color: var(--accent-color); outline: none; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #444; transition: .4s; border-radius: 34px; }
[data-theme="light"] .slider { background-color: #ccc; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(18px); }

.btn-primary { background: var(--accent-color); color: #fff; padding: 12px 20px; border: none; border-radius: 10px; font-weight: bold; cursor: pointer; font-size: 0.95rem; text-shadow: 0 1px 3px rgba(0,0,0,0.4); transition: transform 0.1s, opacity 0.2s, box-shadow 0.2s; }
[data-theme="light"] .btn-primary { color: #fff; text-shadow: none; }
.btn-primary:hover { opacity: 0.9; box-shadow: 0 0 15px rgba(var(--accent-color-rgb), 0.4); }

.btn-primary:focus-visible, .action-btn:focus-visible, .send-btn:focus-visible, .mode-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }

.btn-danger { background: transparent; color: #d9534f; border: 1px solid #d9534f; padding: 10px 15px; border-radius: 10px; cursor: pointer; font-size: 0.9rem; transition: background 0.2s, box-shadow 0.2s; }
.btn-danger:hover { background: rgba(217, 83, 79, 0.08); box-shadow: 0 0 10px rgba(217, 83, 79, 0.15); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; height: 16px; width: 16px; border-radius: 50%; background: var(--accent-color); cursor: pointer; margin-top: -6px; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #444; border-radius: 2px; }
[data-theme="light"] input[type=range]::-webkit-slider-runnable-track { background: #ccc; }

.avatar-upload-container { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; }

.avatar-preview-large { width: 100px; height: 100px; border-radius: 50%; background: var(--bg-input); border: 2px solid var(--accent-color); box-shadow: 0 0 15px -2px var(--accent-color); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; transition: transform 0.3s ease, box-shadow 0.3s ease; }
.avatar-preview-large:hover { transform: scale(1.05); box-shadow: 0 0 25px -2px var(--accent-color); }
.avatar-preview-large img { width: 100%; height: 100%; object-fit: cover; }

#big-editor-overlay { z-index: 200; background: var(--bg-modal-overlay); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.big-editor-modal { width: 90%; height: 90%; background: var(--bg-modal); border: 1px solid var(--border-color); border-radius: 12px; display: flex; flex-direction: column; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.big-editor-textarea { flex: 1; resize: none; border: none; background: transparent; color: var(--text-primary); font-family: monospace; font-size: 1.1rem; line-height: 1.6; outline: none; padding: 10px; }

/* --- CLASSES UTILITÁRIAS EXTRAS --- */
.setting-item-vertical { flex-direction: column; align-items: flex-start; }
.btn-sm { padding: 8px 15px; font-size: 0.9rem; }
.btn-logout { color: #d9534f; }
.btn-logout:hover { color: #e06b68; }
.badge-active { color: #888; font-size: 0.8rem; border: 1px solid #888; padding: 2px 8px; border-radius: 6px; font-weight: 600; letter-spacing: 0.5px; background: rgba(136, 136, 136, 0.08); }
.editor-title { color: var(--text-primary); }
.label-block { display: block; }
.text-hint { font-size: 0.8rem; color: var(--text-secondary); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.app-content { display: flex; width: 100%; height: 100%; }
.avatar-upload-row { display: flex; align-items: center; gap: 20px; }
.avatar-actions { display: flex; flex-direction: column; gap: 10px; }
.big-editor-footer { display: flex; justify-content: flex-end; gap: 10px; padding-top: 15px; border-top: 1px solid var(--border-color); margin-top: 10px; }

/* --- BANNER DE INSTALAÇÃO PWA --- */
.pwa-banner { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 12px); transform: translateX(-50%) translateY(-180%); z-index: 1500; display: flex; align-items: center; gap: 12px; width: min(440px, calc(100% - 24px)); background: var(--bg-modal); border: 1px solid var(--border-color); border-radius: 14px; padding: 12px 14px; box-shadow: 0 12px 36px rgba(0,0,0,0.45); transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1); }
.pwa-banner.visible { transform: translateX(-50%) translateY(0); }
.pwa-banner-icon { width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0; object-fit: contain; }
[data-theme="dark"] .pwa-banner-icon { filter: invert(1); }
.pwa-banner-text { flex: 1; min-width: 0; font-size: 0.85rem; color: var(--text-primary); line-height: 1.35; }
.pwa-banner-install { background: var(--accent-color); color: var(--accent-text); border: none; border-radius: 9px; padding: 9px 16px; font-weight: 700; font-size: 0.85rem; cursor: pointer; flex-shrink: 0; transition: opacity 0.2s; }
.pwa-banner-install:hover { opacity: 0.9; }
.pwa-banner-close { background: none; border: none; color: var(--text-secondary); font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0 2px; flex-shrink: 0; }
.pwa-banner-close:hover { color: var(--text-primary); }

/* --- CARDS DE USUÁRIO (aba Admin > Usuários) --- */
.user-card { padding: 14px 18px; background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 12px; }
.user-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.user-card-info { min-width: 0; flex: 1; }
.user-card-name { font-weight: bold; color: var(--text-primary); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-sub { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-top { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.user-card-actions:empty { display: none; }

@media (max-width: 768px) {
    aside { position: fixed; top: 0; left: 0; height: 100%; width: 85%; transform: translateX(-100%); transition: transform 0.3s ease; box-shadow: 10px 0 30px rgba(0,0,0,0.5); }
    aside.open { transform: translateX(0); width: 85%; }
    aside.closed { width: 85%; transform: translateX(-100%); }
    .modal { width: 100%; height: 100%; max-width: 100%; border-radius: 0; flex-direction: column; border: none; }
    .modal-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); flex-direction: row; overflow-x: auto; padding: 10px; gap: 10px; }
    .modal-tab { white-space: nowrap; padding: 8px 12px; font-size: 0.9rem; flex-shrink: 0; }
    .modal-content { padding: 20px; }
    header { padding: 10px 15px; } header h1 { font-size: 1rem; }
    .input-wrapper { padding: 10px; padding-bottom: max(10px, var(--safe-bottom)); } .input-area { padding: 5px 10px; }
    #menu-btn { display: block !important; }

    /* Chat mais confortável e legível no celular */
    #chat-container { padding: 16px 12px; gap: 20px; }
    .bubble { padding: 14px 16px; text-align: left; hyphens: none; -webkit-hyphens: none; -ms-hyphens: none; overflow-wrap: anywhere; }
    [data-theme="light"] .message.tutoria .bubble { padding-left: 16px; }

    /* Dashboard (admin) sem padding gigante / overflow lateral no mobile */
    #view-dashboard > div { padding: 16px 12px !important; }

    /* Evita scroll horizontal acidental */
    main, .view-section { max-width: 100vw; overflow-x: hidden; }

    /* Botão de fechar o menu (gaveta) no mobile */
    .sidebar-mobile-header { display: flex; justify-content: flex-end; margin-bottom: 6px; }
    .sidebar-close-btn { padding: 6px; border-radius: 8px; }
    .sidebar-close-btn:hover { background-color: var(--bg-input); }
}