:root {
    color-scheme: light;
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --bg: #f0f2f5;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #a0aec0;
    --sidebar-active: #667eea;
    --card-bg: #ffffff;
    --text: #2d3748;
    --text-light: #718096;
    --border: #e2e8f0;
    --success: #48bb78;
    --warning: #ecc94b;
    --error: #f56565;
    --radius: 12px;
    --shadow: 0 4px 6px rgba(0,0,0,0.07), 0 10px 15px rgba(0,0,0,0.1);
    --chat-user-bg: var(--primary);
    --chat-user-text: #fff;
    --chat-assistant-bg: var(--bg);
    --chat-assistant-text: var(--text);
    --input-bg: #fff;
    --hover-bg: rgba(0,0,0,0.04);
}

body.theme-dark {
    color-scheme: dark;
    --primary: #7c8cf0;
    --primary-dark: #6b7ce8;
    --secondary: #8b6cc9;
    --bg: #0f0f1a;
    --sidebar-bg: #0a0a14;
    --sidebar-text: #6b7280;
    --card-bg: #1a1a2e;
    --text: #e5e7eb;
    --text-light: #9ca3af;
    --border: #2d2d4a;
    --success: #4ade80;
    --warning: #fbbf24;
    --error: #f87171;
    --shadow: 0 4px 6px rgba(0,0,0,0.3), 0 10px 15px rgba(0,0,0,0.4);
    --chat-user-bg: #5a6cdb;
    --chat-user-text: #fff;
    --chat-assistant-bg: #1f1f38;
    --chat-assistant-text: #e5e7eb;
    --input-bg: #1a1a2e;
    --hover-bg: rgba(255,255,255,0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header i { font-size: 2em; color: var(--primary); }
.sidebar-header h2 { font-size: 1.2em; font-weight: 700; }

.sidebar-nav { flex: 1; padding: 16px 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.nav-item:hover { color: white; background: rgba(255,255,255,0.05); }
.nav-item.active { color: white; background: rgba(102,126,234,0.15); border-left-color: var(--primary); }
.nav-item i { width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: var(--sidebar-text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.15); color: white; }

.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1em;
}
.user-info small { display: block; color: var(--sidebar-text); font-size: 0.75em; }

.logout-btn { color: var(--sidebar-text); text-decoration: none; padding: 8px; border-radius: 8px; transition: all 0.2s; }
.logout-btn:hover { color: var(--error); background: rgba(245,101,101,0.1); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.topbar h1 { font-size: 1.8em; font-weight: 700; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.creditos-display {
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 0.9em;
    color: var(--text-light);
}
.creditos-display i { color: var(--warning); margin-right: 6px; }

/* Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}
.card:hover { transform: translateY(-2px); }

.card-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    margin-bottom: 16px;
}
.card-icon.purple { background: rgba(102,126,234,0.1); color: var(--primary); }
.card-icon.green { background: rgba(72,187,120,0.1); color: var(--success); }
.card-icon.orange { background: rgba(236,201,75,0.1); color: var(--warning); }
.card-icon.red { background: rgba(245,101,101,0.1); color: var(--error); }

.card h3 { font-size: 0.9em; color: var(--text-light); margin-bottom: 8px; }
.card .card-value { font-size: 2em; font-weight: 700; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d2d6dc; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--error); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8em; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9em; color: var(--text); }
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95em;
    transition: border-color 0.2s;
    background: var(--input-bg);
    color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { appearance: auto; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.modal.active { display: flex; }

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 500px;
    max-width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal-lg { width: 700px; }
.modal-full { width: 90%; max-width: 1200px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.3em; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px 8px;
    border-radius: 6px;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.tab {
    padding: 10px 16px;
    border: none;
    background: var(--bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
}
.tab:hover { background: var(--border); }
.tab.active { background: var(--primary); color: #fff; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Results */
.result-box {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.85em;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin: 10px 0;
}

.image-result {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 16px 0;
}
.image-result img {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.2s;
}
.image-result img:hover { transform: scale(1.02); }

/* Projects */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.project-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    cursor: pointer;
}
.project-card:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0,0,0,0.1); }
.project-card .project-title { font-size: 1.1em; font-weight: 600; margin-bottom: 8px; }
.project-card .project-desc { color: var(--text-light); font-size: 0.9em; margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-card .project-meta { display: flex; justify-content: space-between; font-size: 0.8em; color: var(--text-light); }

/* Status badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75em; font-weight: 600; }
.badge-gratuito { background: #e2e8f0; color: #4a5568; }
.badge-basico { background: #c6f6d5; color: #276749; }
.badge-pro { background: #bee3f8; color: #2a4365; }
.badge-enterprise { background: #fed7d7; color: #9b2c2c; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: #fed7d7; color: #9b2c2c; border: 1px solid #feb2b2; }

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 40px;
    width: 400px;
    max-width: 95%;
    box-shadow: var(--shadow);
}
.login-header { text-align: center; margin-bottom: 32px; }
.login-header i { font-size: 3em; color: var(--primary); margin-bottom: 16px; }
.login-header h1 { font-size: 1.8em; font-weight: 700; }
.login-header p { color: var(--text-light); margin-top: 4px; }
.login-footer { text-align: center; margin-top: 24px; font-size: 0.85em; color: var(--text-light); }
.login-footer a { color: var(--primary); text-decoration: none; }

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

body.theme-dark .loading-overlay-inner { background: var(--card-bg) !important; color: var(--text); }
body.theme-dark .toast-error { background: rgba(249,113,113,0.2) !important; color: #fca5a5 !important; border-color: rgba(249,113,113,0.3) !important; }
body.theme-dark .toast-success { background: rgba(74,222,128,0.2) !important; color: #6ee7b7 !important; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-state i { font-size: 3em; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* Chat IA */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.chat-welcome {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.chat-welcome i { font-size: 4em; color: var(--primary); margin-bottom: 16px; opacity: 0.6; }
.chat-welcome h3 { font-size: 1.5em; color: var(--text); margin-bottom: 8px; }
.chat-welcome p { max-width: 400px; margin: 0 auto; line-height: 1.6; }

.chat-msg {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: msgFadeIn 0.3s ease;
}
@keyframes msgFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    flex-shrink: 0;
}
.chat-msg-user .chat-msg-avatar { background: var(--primary); color: white; }
.chat-msg-assistant .chat-msg-avatar { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }

.chat-msg-body { flex: 1; min-width: 0; }

.chat-msg-content {
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 0.95em;
    line-height: 1.6;
    word-wrap: break-word;
}
.chat-msg-user .chat-msg-content {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 4px;
}
.chat-msg-assistant .chat-msg-content {
    background: var(--chat-assistant-bg);
    color: var(--chat-assistant-text);
    border-bottom-left-radius: 4px;
}

.chat-msg-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85em;
    font-family: 'Consolas', 'Courier New', monospace;
    margin: 8px 0;
    max-height: 400px;
    overflow-y: auto;
}
.chat-msg-content code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'Consolas', 'Courier New', monospace;
}
.chat-msg-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}
.chat-msg-content h1, .chat-msg-content h2, .chat-msg-content h3 {
    margin: 12px 0 6px;
    color: var(--text);
}
.chat-msg-content h1 { font-size: 1.3em; }
.chat-msg-content h2 { font-size: 1.15em; }
.chat-msg-content h3 { font-size: 1.05em; }
.chat-msg-content ul { margin: 6px 0; padding-left: 20px; }
.chat-msg-content li { margin: 3px 0; }
.chat-msg-content strong { font-weight: 700; }
.chat-msg-content em { font-style: italic; }
.chat-msg-content br { content: ''; display: block; margin: 4px 0; }

.chat-msg-actions {
    margin-top: 4px;
    padding-left: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
.chat-msg-body:hover .chat-msg-actions { opacity: 1; }
.chat-action-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
}
.chat-action-btn:hover { background: var(--bg); color: var(--text); }

.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}

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

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 0.95em;
    resize: none;
    max-height: 200px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    line-height: 1.5;
    background: var(--input-bg);
    color: var(--text);
}
.chat-input:focus { border-color: var(--primary); }
.chat-input::placeholder { color: var(--text-light); }

.btn-send {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1em;
}

.chat-model-info {
    text-align: center;
    font-size: 0.75em;
    color: var(--text-light);
    margin-top: 8px;
}

body.theme-dark .result-box { background: #0a0a14; }
body.theme-dark .modal-header { border-bottom-color: var(--border); }
body.theme-dark table th { background: var(--bg); color: var(--text); }
body.theme-dark table td { color: var(--text); }
body.theme-dark .login-header h1 { color: var(--text); }
body.theme-dark .chat-msg-content code { background: rgba(255,255,255,0.1); }
body.theme-dark .alert-error { background: rgba(249,113,113,0.15); color: #fca5a5; border-color: rgba(249,113,113,0.3); }
body.theme-dark .badge-gratuito { background: #374151; color: #d1d5db; }
body.theme-dark .badge-basico { background: #065f46; color: #6ee7b7; }
body.theme-dark .badge-pro { background: #1e3a5f; color: #93c5fd; }
body.theme-dark .badge-enterprise { background: #7f1d1d; color: #fca5a5; }

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .sidebar-nav .nav-item span, .user-info div, .sidebar-footer .logout-btn { display: none; }
    .sidebar-header { justify-content: center; padding: 16px; }
    .nav-item { justify-content: center; padding: 12px; }
    .sidebar-footer { justify-content: center; }
    .main-content { margin-left: 60px; }
    .topbar { flex-direction: column; gap: 12px; }
    .cards-grid { grid-template-columns: 1fr; }
}
