/* ==========================================================================
   Variables y Tokens (Mobile-First, Premium UI)
   ========================================================================== */
:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --surface: #1e293b;
    --surface-glass: rgba(30, 41, 59, 0.8);
    --surface-border: rgba(255, 255, 255, 0.1);
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #8b5cf6;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    
    --transition: all 0.2s ease-in-out;
    --header-height: 60px;
    --nav-height: 64px;
}

/* ==========================================================================
   Reset
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-main);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden; /* Prevent body scroll, use inner scroll */
}

.hidden { display: none !important; }

/* ==========================================================================
   Estructura Principal (Mobile First)
   ========================================================================== */
.view-container {
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

.layout-wrapper {
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Login
   ========================================================================== */
/* Login styles stay here (not duplicated below) */
#login-view {
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.login-card {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--surface-border);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    text-align: center;
}
.logo-container { margin-bottom: 2rem; }
.logo-icon { font-size: 3rem; color: var(--primary); }

.input-group { margin-bottom: 1rem; text-align: left; }
.input-group label { display: block; margin-bottom: 0.5rem; color: var(--text-muted); font-size: 0.9rem; }
.input-wrapper { position: relative; display: flex; align-items: center; }
.input-wrapper .material-symbols-outlined { position: absolute; left: 12px; color: var(--text-muted); }
.input-wrapper input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    background: var(--bg-darker);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
}
.input-wrapper input:focus { outline: none; border-color: var(--primary); }

.btn {
    padding: 14px 24px; /* Mobile-first: > 44px touch target */
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-secondary { background: var(--surface-border); color: white; }
.btn-block { width: 100%; }

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    z-index: 10;
}
.header-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1.2rem; }
.badge { background: var(--primary); font-size: 0.7rem; padding: 2px 8px; border-radius: var(--radius-full); }
.icon-btn { background: transparent; border: none; color: var(--text-main); cursor: pointer; padding: 8px; border-radius: var(--radius-md); }
.icon-btn:hover { background: var(--surface); }

/* ==========================================================================
   Chat Area
   ========================================================================== */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.welcome-banner { text-align: center; margin: auto; color: var(--text-muted); }
.welcome-banner .massive-icon { font-size: 4rem; color: var(--accent); margin-bottom: 1rem; }

/* Mensajes */
.message { max-width: 85%; padding: 12px 16px; border-radius: var(--radius-lg); line-height: 1.4; animation: slideIn 0.3s ease; }
.message.user { background: var(--primary); align-self: flex-end; border-bottom-right-radius: 4px; }
.message.assistant { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 4px; border: 1px solid var(--surface-border); }
.message.system { background: var(--warning); color: #000; align-self: center; text-align: center; font-size: 0.9rem; }

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

/* Formularios Inferiores */
.input-area {
    padding: 1rem;
    background: var(--bg-darker);
    border-top: 1px solid var(--surface-border);
}
.input-area form { display: flex; gap: 8px; align-items: flex-end; }

.chat-textarea {
    flex: 1;
    padding: 12px 16px;
    border-radius: 20px;
    border: 1px solid var(--surface-border);
    background: var(--surface);
    color: var(--text-main);
    font-size: 1rem;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    min-height: 48px;
    max-height: 150px;
    overflow-y: auto;
    transition: background-color 0.2s, border-color 0.2s;
}
.chat-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.input-area input {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--surface-border);
    background: var(--surface);
    color: var(--text-main);
    font-size: 1rem;
}
.input-area input:focus { outline: none; border-color: var(--primary); }
.send-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Dev Mode & Modals
   ========================================================================== */
.dev-toolbar { padding: 10px; background: var(--surface); border-bottom: 1px solid var(--surface-border); }
.dev-controls { display: flex; gap: 8px; }
.dev-controls input, .dev-controls select { padding: 8px; border-radius: 4px; background: var(--bg-darker); color: var(--text-main); border: 1px solid var(--surface-border); flex: 1; }

.plan-approval-bar {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--warning);
    margin: 10px;
    padding: 12px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.plan-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.plan-modify-group { display: flex; gap: 4px; flex: 1; }
.plan-modify-group input { flex: 1; padding: 6px; border-radius: 4px; }

/* Plan message cards */
.message.plan-proposal {
    background: linear-gradient(135deg, #1a1a2e 0%, #1e1b2e 100%);
    border: 1px solid rgba(124, 58, 237, 0.4);
    border-left: 4px solid var(--warning);
    border-radius: 12px;
}
.message.plan-proposal::before {
    content: "📋 Plan de Implementación";
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--warning);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.message.execution-result {
    background: linear-gradient(135deg, #0a2e1a 0%, #0f3a22 100%);
    border: 1px solid rgba(5, 150, 105, 0.4);
    border-left: 4px solid var(--success);
    border-radius: 12px;
}
.message.execution-result::before {
    content: "✅ Ejecución Completada";
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Plan phase indicators */
.plan-phase {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    margin: 8px;
}
.plan-phase.waiting {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
}
.plan-phase.executing {
    background: rgba(5, 150, 105, 0.1);
    border: 1px solid rgba(5, 150, 105, 0.3);
    color: var(--success);
}

/* Admin Sections */
.section-header { padding: 1rem; display: flex; justify-content: space-between; align-items: center; }
.card { background: var(--surface); padding: 1rem; margin: 1rem; border-radius: var(--radius-md); }
.form-grid { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.form-grid input, .form-grid select { padding: 10px; border-radius: 4px; background: var(--bg-dark); color: white; border: 1px solid var(--surface-border); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-content { background: var(--surface); width: 100%; max-width: 600px; border-radius: var(--radius-md); overflow: hidden; }
.modal-header { padding: 1rem; display: flex; justify-content: space-between; border-bottom: 1px solid var(--surface-border); }
.modal-body { padding: 1rem; max-height: 70vh; overflow-y: auto; }

/* Typing Indicator */
.typing-indicator { padding: 10px; display: flex; gap: 4px; }

/* Progress text style (dev mode SSE typing) */
.typing-indicator.progress-text {
    background: #1e293b;
    border-radius: 12px;
    padding: 10px 16px;
    margin: 8px 0;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: #94a3b8;
    white-space: pre-line;
    line-height: 1.5;
    animation: none;
}
.typing-indicator.progress-text .dot {
    display: none;
}

/* Tool info messages (dev mode) */
.message-tool-info {
    background: #1e1b2e;
    border: 1px solid rgba(124, 58, 237, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    margin: 6px 0;
    font-size: 12px;
    color: #a78bfa;
    display: flex;
    align-items: center;
    gap: 6px;
}
.message-tool-info .material-symbols-outlined {
    font-size: 16px;
}
.dot { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%; animation: blink 1.4s infinite both; }
.dot:nth-child(1) { animation-delay: 0.2s; }
.dot:nth-child(2) { animation-delay: 0.4s; }
.dot:nth-child(3) { animation-delay: 0.6s; }
@keyframes blink { 0%, 100% { opacity: 0.2; } 20% { opacity: 1; } }

/* Toast */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); padding: 12px 20px; border-radius: var(--radius-md); box-shadow: 0 5px 15px rgba(0,0,0,0.3); border-left: 4px solid var(--primary); animation: slideInRight 0.3s ease forwards; }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ==========================================================================
   SKILLS & DATA GRID STYLES
   ========================================================================== */

/* Contenedor Principal de la Lista de Skills */
#skills-list-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

/* Sección de Categoría (Acordeón) */
.category-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.category-section.collapsed .category-skills-grid {
    display: none;
}

.category-section.collapsed .expand-icon {
    transform: rotate(-90deg);
}

/* Cabecera de la Categoría */
.category-header {
    display: flex;
    align-items: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.category-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.category-header .category-icon {
    font-family: 'Material Symbols Outlined';
    font-size: 24px;
    color: var(--primary);
    margin-right: 12px;
}

.category-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
    flex-grow: 1;
}

.category-header .category-count {
    background: var(--background);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-right: 12px;
    border: 1px solid var(--border);
}

.category-header .expand-icon {
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

/* Grid de Skills (Tarjetas) */
.category-skills-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--background);
}

@media (min-width: 768px) {
    .category-skills-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

/* Tarjeta Individual de Skill */
.skill-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.skill-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--primary);
}

.skill-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.skill-card-info strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.skill-card-info span {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Acciones de la Tarjeta */
.skill-card-actions {
    display: flex;
    gap: 8px;
}

.skill-card-actions .icon-btn {
    background: var(--background);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.skill-card-actions .icon-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Editor de Skills */
#skill-editor-container {
    margin-bottom: 24px;
    animation: slideDown 0.3s ease;
}

#skill-editor-container.hidden {
    display: none;
}

.skill-editor {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.skill-editor h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.CodeMirror {
    border-radius: 8px;
    border: 1px solid var(--border);
    font-family: 'Fira Code', 'Consolas', monospace;
    height: 400px;
}

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

/* Utilitarios de Data Grid generales (fallback) */
.data-grid {
    width: 100%;
}

/* ==========================================================================
   MODAL STYLES
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.close-modal-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.close-modal-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
}

.modal-body pre {
    margin: 0;
    background: var(--background);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.modal-body code {
    white-space: pre;
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   === ARCHITECTURE & LAYOUT (UI/UX MOBILE-FIRST & DESKTOP GRID) ===
   ========================================================================== */

html, body {
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
    overflow: hidden !important; /* Body never scrolls, prevents double scrollbars */
}

/* Mobile First Base Container */
.layout-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* App Header (Top) */
.app-header {
    flex-shrink: 0;
}

/* Bottom Nav (Mobile) */
.bottom-nav {
    height: var(--nav-height);
    z-index: 1000;
    position: relative;
    background: var(--bg-darker);
    border-top: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    flex-shrink: 0;
}
.nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    width: 100%;
    padding: 8px 0;
}
.nav-item span:last-child { font-size: 0.7rem; font-weight: 500; }
.nav-item.active { color: var(--primary); }
.nav-item.danger:hover { color: var(--danger); }

/* Main Area Container */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden; /* Never scroll the main wrapper */
    display: flex;
    flex-direction: column;
}

/* Sections (Chat, Skills, Users, etc) */
/* The sections themselves must NOT scroll. They span the full main-content height. */
.app-section {
    flex: 1;
    width: 100%;
    display: none; /* Overridden by .active */
    flex-direction: column;
    overflow: hidden; 
}

/* ONLY display when active. This fixes the navigation bug! */
.app-section.active {
    display: flex !important;
}

/* Scrollable Areas INSIDE Sections */
/* This isolates the scroll to exactly where the content is, keeping header/input/nav sticky */
.messages-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    padding-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.data-grid,
#skills-list-container,
#users-list-container,
.markdown-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 24px;
}

/* Fix flex shrinking on important static elements */
.input-area, .dev-toolbar {
    flex-shrink: 0;
}

/* ==========================================================================
   Sesiones Sidebar
   ========================================================================== */
#chat-section {
    flex-direction: row !important;
}

.chat-sessions-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sessions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--surface-border);
}

.sessions-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.session-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.session-item.active {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.session-item.empty {
    cursor: default;
    color: var(--text-muted);
    font-size: 0.8rem;
    justify-content: center;
}

.session-icon {
    font-size: 1.1rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.session-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.session-delete-btn {
    opacity: 0;
    transition: var(--transition);
    flex-shrink: 0;
}

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

.chat-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Mobile: ocultar sidebar */
@media (max-width: 767px) {
    .chat-sessions-sidebar {
        display: none;
    }
}

/* ==========================================================================
   === DESKTOP OVERRIDE (CSS GRID) ===
   ========================================================================== */
@media (min-width: 768px) {
    .layout-wrapper {
        display: grid;
        grid-template-columns: 80px 1fr;
        grid-template-rows: 60px 1fr; /* assuming header is 60px */
        grid-template-areas:
            "nav header"
            "nav main";
    }

    .app-header {
        grid-area: header;
    }

    .bottom-nav {
        grid-area: nav;
        height: 100%;
        width: 100%;
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 20px;
        border-top: none;
        border-right: 1px solid var(--surface-border);
    }
    
    .nav-item {
        margin-bottom: 15px;
    }

    .main-content {
        grid-area: main;
        height: 100%;
    }
}


/* ==========================================================================


/* Model Selector */
.model-selector-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    max-width: 320px;
}
.model-btn {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.3);
    color: var(--accent);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.model-btn:hover {
    background: rgba(124, 58, 237, 0.2);
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* ==========================================================================
   CONOCIMIENTO GLOBAL (Knowledge Management)
   ========================================================================== */

.section-header .header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.knowledge-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    margin: 0 16px 12px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.knowledge-search-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
}

.knowledge-search-bar .material-symbols-outlined {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.knowledge-editor {
    margin: 0 16px 12px;
    padding: 16px;
}

.knowledge-editor .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.form-row .input-group {
    margin-bottom: 0;
}

.knowledge-item {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin: 0 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: var(--transition);
}

.knowledge-item:hover {
    border-color: rgba(59, 130, 246, 0.3);
}

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

.knowledge-item-key {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.knowledge-item-content {
    font-size: 0.9rem;
    line-height: 1.5;
}

.knowledge-item-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.knowledge-item-meta .badge {
    font-size: 0.7rem;
    padding: 2px 8px;
}

.knowledge-item-actions {
    display: flex;
    gap: 4px;
}

.knowledge-item-actions .icon-btn {
    font-size: 1rem;
    padding: 4px;
}

/* Tags */
.knowledge-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.knowledge-tag {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
}

/* Señales */
.signals-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--surface-border);
}

.signals-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.signals-list {
    max-height: 400px;
    overflow-y: auto;
}

.signal-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--surface-border);
    font-size: 0.85rem;
}

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

.signal-content {
    flex: 1;
}

.signal-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.signal-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.signal-actions .btn-sm {
    font-size: 0.75rem;
    padding: 4px 10px;
}

#knowledge-signals-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--bg-dark);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    overflow: hidden;
}

/* ==========================================================================
   UX/UI MEJORAS PARA GESTIÓN DE HERRAMIENTAS (SKILLS)
   ========================================================================== */

/* 1. Forzar contenedor a respetar el alto y permitir overflow */
.main-content {
    min-height: 0;
}
.app-section {
    min-height: 0;
}

/* 2. Aislar el scroll de la lista de skills */
#skills-list-container {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 24px;
}

/* 3. Evitar el desbordamiento horizontal en las cards (textos muy largos) */
.skill-card {
    min-width: 0; /* Clave para que funcione el text-overflow en grid/flex */
}
.skill-card-info {
    min-width: 0; /* Permite a los hijos encogerse */
}
.skill-card-info strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* 4. Touch Targets Mínimos (44x44px) - Mejora UX/Accesibilidad */
.skill-card-actions .icon-btn {
    width: 44px;
    height: 44px;
}
.category-header {
    min-height: 56px;
}
.category-header:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

/* 5. Custom Scrollbar refinada */
#skills-list-container::-webkit-scrollbar {
    width: 6px;
}
#skills-list-container::-webkit-scrollbar-track {
    background: transparent;
}
#skills-list-container::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 4px;
}

/* Fix flex-shrink issue on categories */
.category-section {
    flex-shrink: 0 !important;
}

/* --- Professional Chat Enhancements --- */
.message { display: flex; gap: 12px; margin-bottom: 24px; align-items: flex-start; animation: fadeIn 0.3s ease-out; width: 100%; }
.message.user { flex-direction: row-reverse; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 20px; color: white; }
.assistant-avatar { background-color: var(--primary-color, #4f46e5); }
.user-avatar { background-color: var(--text-muted, #64748b); }
.message-content { max-width: 80%; background-color: var(--surface-light, #1e293b); padding: 14px 18px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); line-height: 1.5; font-size: 15px; color: var(--text-color, #f8fafc); }
.message.user .message-content { background-color: #3b82f6; color: #ffffff; border-top-right-radius: 2px; }
.message.assistant .message-content { border-top-left-radius: 2px; }

/* Code Block Wrapper for Copy Button */
.code-wrapper { position: relative; margin: 12px 0; }
.code-wrapper pre { margin: 0; padding-top: 36px !important; border-radius: 8px; }
.copy-btn { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,0.1); border: none; color: #cbd5e1; font-size: 12px; padding: 4px 8px; border-radius: 4px; cursor: pointer; display: flex; align-items: center; gap: 4px; transition: background 0.2s; z-index: 10; }
.copy-btn:hover { background: rgba(255,255,255,0.2); color: white; }

/* Skeleton Loader */
.skeleton-loader { width: 200px; background-color: transparent !important; box-shadow: none !important; padding: 0 !important; }
.skeleton-line { height: 12px; background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%); background-size: 200% 100%; animation: loadingPulse 1.5s infinite; border-radius: 4px; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }
@keyframes loadingPulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.pulse-anim { animation: pulseAvatar 2s infinite; }
@keyframes pulseAvatar { 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4); } 70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(79, 70, 229, 0); } 100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; } }

/* Refined Input Area */
.chat-textarea { resize: none; overflow-y: hidden; line-height: 1.5; padding: 12px; max-height: 150px; }
