/* ============================================================
   main.css — Estilos base de la aplicación CORRELA
   ============================================================ */

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

/* ── Reset y base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
    overflow: hidden;
}

a { color: var(--color-accent); text-decoration: none; }

/* ── Scrollbar personalizada ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Layout principal ─────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-sidebar);
    box-shadow: var(--shadow-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s, transform 0.3s ease;
    overflow: hidden;
}

#sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

/* Cabecera del sidebar */
.sidebar-header {
    padding: 20px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 120px;
}

.sidebar-logo img {
    height: 48px;
    object-fit: contain;
    transition: height 0.3s;
}

.sidebar-app-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #FFFFFF;
    letter-spacing: 2px;
    white-space: nowrap;
}

.sidebar-by {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
}

.sidebar-company {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-accent-light);
    white-space: nowrap;
}

#sidebar.collapsed .sidebar-app-name,
#sidebar.collapsed .sidebar-by,
#sidebar.collapsed .sidebar-company { display: none; }
#sidebar.collapsed .sidebar-logo img { height: 32px; }

/* Navegación */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    cursor: pointer;
    color: var(--text-sidebar);
    font-size: 0.85rem;
    font-weight: 400;
    border-radius: 0;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
    user-select: none;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--color-accent);
    border-radius: 0 2px 2px 0;
}

.nav-item i {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    color: var(--color-accent-light);
}

.nav-item .nav-label { white-space: nowrap; }
#sidebar.collapsed .nav-label { display: none; }

.nav-section-title {
    padding: 14px 18px 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.3);
    white-space: nowrap;
}

#sidebar.collapsed .nav-section-title { display: none; }

/* Footer del sidebar */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--color-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #FFFFFF;
    flex-shrink: 0;
}

.user-info { overflow: hidden; }

.user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.68rem;
    color: var(--color-accent-light);
    text-transform: capitalize;
}

#sidebar.collapsed .user-info { display: none; }

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: 6px;
    color: #F87171;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-logout:hover { background: rgba(239,68,68,0.22); }
#sidebar.collapsed .btn-logout span { display: none; }

/* ── Área de contenido ────────────────────────────────────── */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

/* Topbar */
#topbar {
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(27,58,107,0.06);
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s;
}

.topbar-toggle:hover { background: var(--bg-app); }

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

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

.btn-theme {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-theme:hover {
    background: var(--bg-app);
    color: var(--color-primary);
}

/* Página */
#page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;
}

/* Consulta Inteligente: sin scroll de página, solo scroll del chat */
#page-content:has(.ai-query-page) {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: 16px;
}

/* ── Componentes compartidos ──────────────────────────────── */

/* Cards de estadísticas */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(27,58,107,0.12);
}

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-icon.blue   { background: rgba(91,155,213,0.12); color: var(--color-accent); }
.stat-icon.green  { background: rgba(34,197,94,0.12);  color: var(--status-active); }
.stat-icon.yellow { background: rgba(245,158,11,0.12); color: var(--status-pending); }
.stat-icon.red    { background: rgba(239,68,68,0.12);  color: var(--status-critical); }
.stat-icon.purple { background: rgba(139,92,246,0.12); color: #A78BFA; }

.stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* Card genérica */
.card {
    background: var(--bg-card);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

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

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 20px; }

/* Tablas */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

thead tr {
    background: var(--bg-app);
    border-bottom: 2px solid var(--border-color);
}

thead th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

tbody tr:hover { background: var(--bg-table-row-alt); }

tbody td {
    padding: 10px 14px;
    color: var(--text-primary);
    vertical-align: middle;
}

/* Badges de estado */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active    { background: rgba(34,197,94,0.12);  color: var(--status-active); }
.badge-pending   { background: rgba(245,158,11,0.12); color: var(--status-pending); }
.badge-suspended { background: rgba(239,68,68,0.12);  color: var(--status-suspended); }
.badge-verified  { background: rgba(34,197,94,0.12);  color: var(--status-verified); }
.badge-critical  { background: rgba(239,68,68,0.12);  color: var(--status-critical); }
.badge-inactive  { background: var(--bg-app);         color: var(--text-muted); border: 1px solid var(--border-color); }
.badge-success   { background: rgba(34,197,94,0.12);  color: var(--status-active); }

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: #FFFFFF;
}
.btn-primary:hover { background: var(--color-primary-light); }

.btn-secondary {
    background: var(--bg-app);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--border-color); }

.btn-danger {
    background: rgba(239,68,68,0.1);
    color: #EF4444;
    border: 1px solid rgba(239,68,68,0.2);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm { padding: 5px 10px; font-size: 0.76rem; }
.btn-icon { padding: 6px 8px; }

/* Inputs y formularios */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input, .form-select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: border 0.2s;
    outline: none;
}

.form-input:focus, .form-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(91,155,213,0.12);
}

/* Barra de búsqueda */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 0 12px;
    flex: 1;
    max-width: 360px;
}

.search-bar i { color: var(--text-muted); font-size: 0.85rem; }
.search-bar input {
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 8px 0;
    outline: none;
    width: 100%;
}

/* Sección título de página */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Conectores ───────────────────────────────────────────── */
.connectors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.connector-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: transform 0.2s;
}

.connector-card:hover { transform: translateY(-2px); }

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

.connector-icon {
    width: 42px;
    height: 42px;
    border-radius: 9px;
    background: var(--bg-badge);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--color-primary);
    flex-shrink: 0;
}

.connector-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.connector-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    font-size: 0.75rem;
}

.connector-meta-label { color: var(--text-muted); }
.connector-meta-value { color: var(--text-primary); font-weight: 500; }

.connector-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Consulta IA ──────────────────────────────────────────── */
.ai-query-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    gap: 10px;
}

.ai-query-header {
    flex-shrink: 0;
}

.ai-query-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    flex: 1;
    min-height: 0;
}

.ai-chat-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.ai-chat-card > .card-header {
    flex-shrink: 0;
}

.ai-chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0 !important;
    overflow: hidden;
}

.ai-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-app);
    border: none;
    border-radius: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.ai-input-bar {
    flex-shrink: 0 !important;
    min-height: 60px;
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card, var(--bg-app));
}

.ai-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.ai-message.user { flex-direction: row-reverse; }

.ai-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.55;
    word-break: break-word;
    white-space: normal;
}

.ai-message.assistant .ai-bubble {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color);
    border-radius: 10px 10px 10px 2px;
}

.ai-message.user .ai-bubble {
    background: #1B3A6B;
    color: #fff;
    border-radius: 10px 10px 2px 10px;
}

.ai-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-input-row input {
    font-size: 0.9rem;
    padding: 10px 14px;
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-app);
    color: var(--text-primary);
     /* evita zoom en iOS */
}

.ai-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-size: 0.82rem;
}

.ai-sources-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.ai-sources-title i { margin-right: 6px; }

.ai-sources ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ai-sources li {
    margin: 4px 0;
}

.ai-sources li i {
    margin-right: 6px;
    opacity: 0.7;
}

/* ── Login ────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-app);
}

.login-card {
    background: var(--bg-card);
    border-radius: 14px;
    box-shadow: var(--shadow-modal);
    padding: 42px 48px;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border-color);
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo img { height: 56px; }
.login-app-name {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: 3px;
    margin-top: 10px;
}
.login-by { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Spinner de carga ─────────────────────────────────────── */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

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

/* ── Responsive (móvil / tablet) ──────────────────────────── */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 300;
        width: 260px;
        min-width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
    }

    #sidebar-overlay {
    display: none;
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 250;
    }

    #topbar {
        padding: 0 12px;
    }

    #page-content {
        padding: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Chat: altura real del viewport + input visible */
    #page-content:has(.ai-query-page) {
        padding: 10px 10px 8px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
        padding-bottom: 8px;
    }

    .ai-query-page {
        height: auto; max-height: none; flex: 1 1 auto; min-height: 0;
        max-height: auto; max-height: none; flex: 1 1 auto; min-height: 0;
        gap: 8px;
    }

    .ai-query-header {
        margin-bottom: 0;
    }

    .ai-query-header .page-subtitle {
        display: none;
    }

    .ai-query-header .page-title {
        font-size: 1.1rem;
    }

    #ollamaStatus {
        font-size: 0.7rem !important;
    }

    .ai-bubble {
        max-width: 90%;
    }

    .ai-messages {
        padding: 12px;
    }

    .ai-input-bar {
    flex-shrink: 0 !important;
    min-height: 60px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .ai-input-row .btn {
        flex-shrink: 0;
        min-width: 40px;
        padding: 8px 10px;
    }

    .page-header {
        margin-bottom: 12px;
    }
}

/* ── Tamaños de input por dispositivo ─────────────────────── */
@media (max-width: 768px) {
    .ai-input-row input {
        font-size: 16px !important;   /* obligatorio: evita zoom iOS */
        padding: 12px 12px;
    }
    .ai-input-row .btn {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .ai-input-row input {
        font-size: 15px;
        padding: 11px 13px;
    }
}

@media (min-width: 1025px) {
    .ai-input-row input {
        font-size: 0.9rem;
        padding: 10px 14px;
    }
}
/* Complemento de badges de estado (Usuarios / KDB) — mismo estilo que Áreas */
.badge-success   { background: rgba(34,197,94,0.12);  color: var(--status-active, #22C55E); }
.badge-pending   { background: rgba(245,158,11,0.12); color: var(--status-pending, #F59E0B); }
.badge-critical  { background: rgba(239,68,68,0.12);  color: var(--status-critical, #EF4444); }
.badge-verified  { background: rgba(34,197,94,0.12);  color: var(--status-verified, #22C55E); }
.badge-inactive  { background: var(--bg-app, #F4F6FA); color: var(--text-muted, #9AAFC4); border: 1px solid var(--border-color, #DDE5EF); }
.badge-blue      { background: rgba(91,155,213,0.15); color: var(--color-primary, #1B3A6B); }
.badge-purple    { background: rgba(139,92,246,0.15); color: #7C3AED; }
.badge-gray      { background: var(--bg-app, #F4F6FA); color: var(--text-secondary, #5A6A7E); border: 1px solid var(--border-color, #DDE5EF); }
