﻿@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --bg-app: #f8fafc;
    --sidebar-bg: #0f172a;
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --radius-lg: 12px;
    --radius-md: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body:not(.is-admin) .admin-only {
    display: none !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* =========================================
   LOGIN SCREEN (FIXED)
   ========================================= */
.login-overlay {
    position: fixed;
    inset: 0;
    background: #020617;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.login-card {
    background: white;
    width: 450px;
    padding: 56px;
    border-radius: 32px;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.form-group label {
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input {
    width: 100%;
    padding: 16px 20px;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    outline: none;
    background: #f8fafc;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-group input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.login-card .logo-wrapper.large {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

.login-card .logo-box {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 1.4rem;
}

.login-card .logo-text {
    font-family: 'Outfit';
    font-size: 1.8rem;
    font-weight: 800;
    color: #0f172a;
}

.login-card .logo-tag {
    font-size: 0.75rem;
    background: #eff6ff;
    color: #2563eb;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: 4px;
}

.login-card .text-muted {
    text-align: center;
    font-size: 0.95rem;
    color: #64748b;
    margin-bottom: 8px;
    line-height: 1.5;
}

/* =========================================
   NAVIGATION RAIL
   ========================================= */
.nav-rail {
    width: 68px;
    background: #020617;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0;
    gap: 20px;
    flex-shrink: 0;
}

.nav-item {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    font-size: 1.3rem;
    transition: 0.2s;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
    color: white;
    background: var(--primary);
}

.view-container {
    flex: 1;
    display: flex;
    min-width: 0;
    position: relative;
}

.view {
    display: none;
    width: 100%;
    height: 100%;
}

.view.active {
    display: flex;
}

/* =========================================
   CHAT SIDEBAR
   ========================================= */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-top {
    padding: 32px 24px 16px 24px;
}

.sidebar .logo-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
}

.sidebar .logo-box {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-family: 'Outfit';
}

.sidebar .logo-text {
    font-family: 'Outfit';
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    text-align: center;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.history-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
    color: #94a3b8;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.history-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 600;
}

.delete-chat-btn {
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #94a3b8;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: 0.2s;
    flex-shrink: 0;
    margin-left: 8px;
}

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

.delete-chat-btn:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    transform: scale(1.1);
}

.sidebar-bottom {
    padding: 24px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.1);
}

.area-config-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.label-tiny {
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.professional-select {
    width: 100%;
    padding: 10px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    color: white;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

/* =========================================
   CHAT MAIN AREA
   ========================================= */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 0;
}

.chat-header {
    height: 74px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 40px;
    background: white;
    flex-shrink: 0;
}

.chat-header .header-info h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
}

.chat-header .badge-status {
    font-size: 0.75rem;
    color: #10b981;
    margin-top: 2px;
}

.chat-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 40px 0;
    background: #f8fafc;
}

.message-bubble {
    width: 100%;
    max-width: 950px;
    margin: 0 auto 32px auto;
    padding: 0 32px;
    display: flex;
    gap: 20px;
    animation: fadeIn 0.4s ease;
}

/* AI LEFT STYLING */
.message-bubble.assistant {
    flex-direction: row;
    justify-content: flex-start;
}

/* USER RIGHT STYLING - PINNED TO RIGHT */
.message-bubble.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.bubble-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
    font-family: 'Outfit';
}

.assistant .bubble-avatar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.user .bubble-avatar {
    background: #475569;
    color: white;
}

.bubble-content {
    max-width: 70%;
    /* Ancho adaptativo para burbujas reales */
    line-height: 1.6;
    font-size: 0.98rem;
    padding: 16px 20px;
    border-radius: 20px;
}

.assistant .bubble-content {
    background: white;
    color: #1e293b;
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
}

.user .bubble-content {
    background: var(--primary);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.15);
    text-align: left;
}

.source-container {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.source-tag:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.chat-input-area {
    padding: 0 32px 40px 32px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.input-wrapper {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 18px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

textarea#user-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 6px 0;
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
    color: #1e293b;
    background: transparent;
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: 0.2s;
    flex-shrink: 0;
}

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

/* =========================================
   KNOWLEDGE (ESPACIOS) SIDEBAR
   ========================================= */
.k-sidebar {
    width: 300px;
    background: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.k-sidebar-header {
    padding: 32px 24px 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.k-sidebar-header h3 {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    font-family: 'Outfit';
}

.k-sidebar-header .btn-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: 0.2s;
}

.k-sidebar-header .btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.area-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.area-card {
    padding: 14px 16px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 6px;
    transition: 0.2s;
    position: relative;
    color: #475569;
    font-weight: 600;
}

.area-card:hover {
    background: #f1f5f9;
}

.area-card.active {
    background: #eff6ff;
    color: var(--primary);
}

.delete-area-btn,
.file-delete-btn {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: #94a3b8;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.area-card:hover .delete-area-btn,
.file-card:hover .file-delete-btn {
    opacity: 1;
}

.delete-area-btn:hover,
.file-delete-btn:hover {
    color: #ef4444;
    border-color: #fee2e2;
}

/* =========================================
   KNOWLEDGE MAIN CONTENT
   ========================================= */
.k-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 0;
}

.k-header {
    padding: 0 40px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 90px;
    background: white;
    flex-shrink: 0;
}

.k-area-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.k-area-info h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: #0f172a;
    font-family: 'Outfit';
}

.k-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper span {
    position: absolute;
    left: 14px;
    opacity: 0.4;
}

.search-input-wrapper input {
    padding: 11px 16px 11px 44px;
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
    width: 250px;
    font-size: 0.9rem;
    background: #f8fafc;
}

.k-grid {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 32px;
    align-content: start;
}

.file-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 32px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    transition: 0.2s ease;
    position: relative;
}

.file-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px -10px rgba(0, 0, 0, 0.05);
}

.file-icon-box {
    width: 60px;
    height: 78px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.file-tag {
    position: absolute;
    bottom: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    background: #64748b;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-family: 'Outfit';
}

.file-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1e293b;
    word-break: break-all;
    line-height: 1.3;
}

/* =========================================
   USER MANAGEMENT (THE ICONS FIX)
   ========================================= */
.users-table-container {
    background: white;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    margin-top: 32px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.pro-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.pro-table th {
    background: #f8fafc;
    padding: 20px 24px;
    font-size: 0.75rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    border-bottom: 2px solid #f1f5f9;
}

.pro-table td {
    padding: 20px 24px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.95rem;
    color: #475569;
}

.pro-table tr:hover {
    background: #fcfcfd;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.status-indicator.active {
    background: #10b981;
}

.status-indicator.inactive {
    background: #ef4444;
}

.user-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #eff6ff;
    color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}

.role-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.role-badge.admin {
    background: #fef3c7;
    color: #92400e;
}

.role-badge.viewer {
    background: #f1f5f9;
    color: #475569;
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: white;
    cursor: pointer;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #475569;
    padding: 0;
    line-height: 1;
}

.btn-icon-sm:hover {
    border-color: var(--primary);
    background: #f8fafc;
    color: var(--primary);
}

/* =========================================
   MODALS & ELEMENTS
   ========================================= */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.95rem;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-ghost {
    padding: 12px 20px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #475569;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-ghost:hover {
    background: #e2e8f0;
}

.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    display: none;
}

.file-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px -10px rgba(0, 0, 0, 0.05);
}

.file-icon-box {
    width: 60px;
    height: 78px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.file-tag {
    position: absolute;
    bottom: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    background: #64748b;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-family: 'Outfit';
}

.file-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1e293b;
    word-break: break-all;
    line-height: 1.3;
}

/* =========================================
   USER MANAGEMENT (THE ICONS FIX)
   ========================================= */
.users-table-container {
    background: white;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    margin-top: 32px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.pro-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.pro-table th {
    background: #f8fafc;
    padding: 20px 24px;
    font-size: 0.75rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    border-bottom: 2px solid #f1f5f9;
}

.pro-table td {
    padding: 20px 24px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.95rem;
    color: #475569;
}

.pro-table tr:hover {
    background: #fcfcfd;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.status-indicator.active {
    background: #10b981;
}

.status-indicator.inactive {
    background: #ef4444;
}

.user-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #eff6ff;
    color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}

.role-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.role-badge.admin {
    background: #fef3c7;
    color: #92400e;
}

.role-badge.viewer {
    background: #f1f5f9;
    color: #475569;
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: white;
    cursor: pointer;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #475569;
    padding: 0;
    line-height: 1;
}

.btn-icon-sm:hover {
    border-color: var(--primary);
    background: #f8fafc;
    color: var(--primary);
}

/* =========================================
   MODALS & ELEMENTS
   ========================================= */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.95rem;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-ghost {
    padding: 12px 20px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #475569;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-ghost:hover {
    background: #e2e8f0;
}

.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 6000;
}

/* =========================================
   ESTRUCTURA DE MODAL PRO (STIKY CONTROLS)
   ========================================= */
.modal-card {
    background: white;
    width: 100%;
    max-width: 950px;
    padding: 0;
    /* Quitamos padding general para control total */
    border-radius: 28px;
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.3);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* El scroll será interno */
}

.modal-header-pro {
    padding: 32px 40px 24px 40px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.modal-tabs {
    padding: 0 40px;
    background: #fff;
    flex-shrink: 0;
    z-index: 10;
}

.source-viewer {
    flex: 1;
    overflow-y: auto;
    padding: 0 40px;
    min-height: 0;
    /* Crucial para flex scroll */
}

/* Scrollbar Personalizada Técnica */
.source-viewer::-webkit-scrollbar {
    width: 8px;
}

.source-viewer::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.source-viewer::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.source-viewer::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.document-page {
    background: #fdfdfd;
    padding: 40px 0;
    /* Padding vertical solo */
    line-height: 1.8;
    font-size: 0.95rem;
    color: #1e293b;
    white-space: pre-wrap;
    font-family: 'Inter', sans-serif;
}

.modal-footer {
    padding: 24px 40px 32px 40px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    background: #fff;
}

/* Clases de utilidad */
.source-modal-tabs {
    display: flex;
    gap: 32px;
    border-bottom: 2px solid var(--border);
}

.source-tab-btn {
    padding: 16px 4px;
    font-size: 1rem;
}

.highlight-match {
    background-color: #fef08a !important;
    border-radius: 4px;
    padding: 2px 4px;
    font-weight: 700;
    color: #000;
    box-shadow: 0 0 12px rgba(254, 240, 138, 1);
    display: inline;
    transition: all 0.3s ease;
}

@keyframes pulse-highlight {
    0% {
        background-color: #fef08a;
        box-shadow: 0 0 12px rgba(254, 240, 138, 1);
    }

    50% {
        background-color: #fffbcf;
        box-shadow: 0 0 20px rgba(254, 240, 138, 0.5);
    }

    100% {
        background-color: #fef08a;
        box-shadow: 0 0 12px rgba(254, 240, 138, 1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   MOBILE RESPONSIVE
   ========================================= */

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px 12px;
    line-height: 1;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .nav-rail {
        width: 100%;
        height: 60px;
        flex-direction: row;
        padding: 0 12px;
        order: 2;
        justify-content: space-around;
        gap: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .nav-item[style*="margin-top: auto;"] {
        margin-top: 0 !important;
    }

    .view-container {
        height: calc(100vh - 60px);
    }

    .sidebar {
        position: absolute;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 2000;
        width: 80%;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
    }

    .k-sidebar {
        position: absolute;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 2000;
        width: 80%;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
    }

    .sidebar.open {
        left: 0;
    }

    .k-sidebar.open {
        left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .message-bubble {
        padding: 0 12px;
    }

    .bubble-content {
        max-width: 88%;
        font-size: 0.92rem;
    }

    .login-card {
        width: 92%;
        padding: 32px 24px;
    }

    .modal-card {
        max-height: 100vh;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}

/* FIX: mobile toggle button override - dark icon on white header */
.mobile-menu-toggle {
    color: #0f172a !important;
    font-size: 1.5rem !important;
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: block !important;
    }
}

/* =========================================
   AREA INTELLIGENCE DASHBOARD
   ========================================= */
.intel-card {
    background: linear-gradient(135deg, #ffffff, #f1f5f9);
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    overflow: hidden;
}

.intel-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.intel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.intel-badge {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--primary);
    background: var(--primary-light);
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.05em;
}

.intel-summary p {
    font-size: 1.05rem;
    color: #1e293b;
    line-height: 1.5;
    font-weight: 500;
}

.intel-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.intel-tag {
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
}

.intel-footer {
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.intel-questions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.intel-question-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.intel-question-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.loading-dots::after {
    content: '.';
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60% {
        content: '...';
    }

    80%,
    100% {
        content: '';
    }
}

/* =========================================
   NEW UPLOAD PROGRESS PANEL (ELITE)
   ========================================= */
.upload-progress-panel {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 380px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
    z-index: 5000;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#progress-status-text {
    font-weight: 800;
    font-size: 0.95rem;
    color: #0f172a;
    font-family: 'Outfit';
}

.progress-percentage {
    font-weight: 900;
    color: var(--primary);
    font-size: 1.1rem;
}

.progress-bar-container {
    height: 8px;
    background: #f1f5f9;
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #6366f1);
    transition: width 0.4s ease;
}

.upload-file-list-container {
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid #f1f5f9;
    margin-top: 4px;
}

.upload-file-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.progress-file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 4px;
    border-bottom: 1px solid #f8fafc;
}

.progress-file-item span:first-child {
    font-size: 0.85rem;
    font-weight: 500;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.file-status {
    font-size: 1rem;
}

.loading-spinner-sm {
    width: 18px;
    height: 18px;
    border: 2.5px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* =========================================
   FILE CARD ACTIONS (NEW)
   ========================================= */
.file-card-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: 0.2s;
    z-index: 10;
}

.file-card:hover .file-card-actions {
    opacity: 1;
}

.file-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    transition: 0.2s;
}

.file-action-btn.dl:hover {
    background: #eff6ff;
    border-color: var(--primary);
    color: var(--primary);
}

.file-action-btn.del:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
}

/* Hide admin only buttons if not admin */
body:not(.is-admin) .is-admin-only {
    display: none !important;
}

/* =========================================
   LOGIN ENHANCEMENTS
   ========================================= */
.error-text {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #e11d48;
    padding: 14px 20px;
    border-radius: 16px;
    font-size: 0.92rem;
    font-weight: 600;
    margin-top: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    text-align: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    50% {
        transform: translateX(8px);
    }

    75% {
        transform: translateX(-4px);
    }
}

/* =========================================
   MARKDOWN & DIAGRAMS SUPPORT
   ========================================= */
.markdown-body {
    line-height: 1.6;
    font-size: 0.95rem;
}

.markdown-body p {
    margin-bottom: 12px;
}

.markdown-body ul,
.markdown-body ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin: 16px 0 8px 0;
    font-family: 'Outfit';
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.85rem;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.markdown-body th,
.markdown-body td {
    padding: 12px;
    border: 1px solid #f1f5f9;
    text-align: left;
}

.markdown-body th {
    background: #f8fafc;
    font-weight: 700;
    color: var(--primary);
}

.markdown-body code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.markdown-body pre {
    background: #0f172a;
    color: #f8fafc;
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 12px 0;
}

/* Mermaid Container Adjustment */
.mermaid {
    background: white !important;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin: 16px 0;
    display: flex;
    justify-content: center;
}

.language-mermaid {
    background: white !important;
    color: initial !important;
}

/* =========================================
   USAGE & BILLING STYLES
   ========================================= */
.usage-badge {
    margin-top: 12px;
    padding: 6px 12px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 0.75rem;
    color: #475569;
    border: 1px solid #e2e8f0;
    display: inline-flex;
    align-items: center;
    font-weight: 500;
}

.usage-badge span {
    display: inline-flex;
    align-items: center;
}

.session-usage-box {
    margin-top: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    flex-direction: column;
    gap: 8px;
}

.usage-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.usage-stats span:first-child {
    background: #ffffff;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    color: #475569;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.usage-stats span:last-child {
    background: #ecfdf5;
    color: #059669;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #a7f3d0;
    font-family: monospace;
    font-size: 0.85rem;
}

/* ANALYTICS DASHBOARD */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 24px;
    margin-top: 30px;
}

.stat-card {
    grid-column: span 2;
    background: #ffffff;
    border: 1px solid var(--border);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.stat-value {
    font-size: 2.2rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    margin: 12px 0;
    color: #0f172a;
}

.stat-progress {
    height: 8px;
    background: #f1f5f9;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    border-radius: 10px;
    transition: width 1s ease;
}

.chart-container-full {
    grid-column: span 6;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.chart-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.chart-legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 4px 12px;
    border-radius: 20px;
}

.chart-wrapper {
    height: 380px;
    position: relative;
}

.analytics-card {
    grid-column: span 3;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.usage-list { margin-top: 20px; }

.user-usage-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid #f1f5f9;
}

.user-usage-item:last-child { border-bottom: none; }

.user-usage-info { display: flex; align-items: center; gap: 12px; }

.user-usage-avatar {
    width: 32px;
    height: 32px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.service-item { margin-top: 24px; }

.service-bar-container {
    height: 10px;
    background: #f1f5f9;
    border-radius: 10px;
    margin: 10px 0;
    overflow: hidden;
}

.service-bar {
    height: 100%;
    background: #8b5cf6;
    border-radius: 10px;
}

.service-val {
    font-family: monospace;
    font-weight: 700;
    color: var(--text-main);
}
