/* ============================================================================
   Nexora ERP — hoja de estilos base (Fase 1)
   Paleta: azules/slate consistente con el resto de la familia Nexora.
   ============================================================================ */

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

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: #f8fafc;
    color: #0f172a;
    font-size: 14px;
}

a { color: inherit; text-decoration: none; }

#appShell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */

.sidebar {
    width: 260px;
    min-width: 260px;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    transition: width 0.2s, min-width 0.2s;
}

.sidebar.collapsed {
    width: 72px;
    min-width: 72px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.sidebar-logo-badge {
    width: 32px;
    height: 32px;
    min-width: 32px;
    object-fit: contain;
}

.sidebar-logo-texto {
    font-weight: 600;
    font-size: 15px;
    color: #0f172a;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-logo-texto,
.sidebar.collapsed .menu-texto,
.sidebar.collapsed .menu-flecha,
.sidebar.collapsed .sidebar-empresa,
.sidebar.collapsed .sidebar-footer-dev,
.sidebar.collapsed .sidebar-footer-usuario,
.sidebar.collapsed .btn-logout,
.sidebar.collapsed .btn-cambiar-password {
    display: none;
}

.btn-colapsar {
    background: none;
    border: none;
    color: #64748b;
    font-size: 15px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.btn-colapsar:hover { background: #f1f5f9; }

.sidebar-empresa {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #2563eb;
    background: #eff6ff;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    color: #334155;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.menu-item:hover { background: #f1f5f9; }
.menu-item.activo { background: #eff6ff; color: #1d4ed8; font-weight: 600; }

.menu-icono { font-size: 16px; min-width: 20px; text-align: center; }
.menu-flecha { margin-left: auto; font-size: 11px; color: #94a3b8; transition: transform 0.15s; }
.menu-grupo.abierto .menu-flecha { transform: rotate(-180deg); }

.submenu {
    display: none;
    flex-direction: column;
    padding-left: 34px;
    margin: 2px 0 6px;
}
.menu-grupo.abierto .submenu { display: flex; }

.submenu-item {
    padding: 8px 10px;
    border-radius: 6px;
    color: #64748b;
    font-size: 13px;
    white-space: nowrap;
}
.submenu-item:hover { background: #f1f5f9; color: #334155; }
.submenu-item.activo { color: #1d4ed8; font-weight: 600; }

.menu-item[data-permiso], .menu-grupo[data-permiso-grupo] {
    display: none; /* se muestra solo si el usuario tiene el permiso -- ver aplicarVisibilidadMenu() */
}
.menu-item[data-vista="inicio"] { display: flex; } /* Inicio siempre visible */

.sidebar-footer {
    border-top: 1px solid #e2e8f0;
    padding: 14px 16px;
}

.sidebar-footer-dev {
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 8px;
}

.sidebar-footer-usuario {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 10px;
}
#nombreUsuarioSidebar { font-size: 13px; font-weight: 600; color: #0f172a; }
.rol-badge {
    font-size: 11px;
    color: #2563eb;
    background: #eff6ff;
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    width: fit-content;
}

.btn-logout {
    width: 100%;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 8px;
    border-radius: 6px;
    font-size: 12.5px;
    cursor: pointer;
}
.btn-logout:hover { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

.btn-cambiar-password { margin-bottom: 8px; }

/* ── Contenido principal ─────────────────────────────────────────────── */

.pantalla-derecha {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 28px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 5;
}

.btn-menu-movil {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    color: #334155;
    cursor: pointer;
}

#pageTitle {
    font-size: 18px;
    font-weight: 600;
    color: #0f172a;
}

.page-content {
    flex: 1;
    padding: 28px;
    overflow-y: auto;
}

/* ── Componentes comunes (tarjetas, tablas, formularios, botones) ──────── */

.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 22px;
    margin-bottom: 20px;
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.kpi-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px 18px;
}
.kpi-card .kpi-label {
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 6px;
}
.kpi-card .kpi-valor {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
}
.kpi-card.kpi-alerta .kpi-valor { color: #b91c1c; }

.card-titulo {
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.campo { margin-bottom: 14px; }
.campo label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.campo input, .campo select, .campo textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13.5px;
    color: #0f172a;
    background: #f8fafc;
    font-family: inherit;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
    outline: none;
    border-color: #2563eb;
    background: #ffffff;
}
.campo input:disabled { background: #f1f5f9; color: #94a3b8; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 6px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primario { background: #2563eb; color: #ffffff; }
.btn-primario:hover { background: #1d4ed8; }
.btn-secundario { background: #f1f5f9; color: #334155; }
.btn-secundario:hover { background: #e2e8f0; }
.btn-peligro { background: #fef2f2; color: #b91c1c; }
.btn-peligro:hover { background: #fee2e2; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.tabla-wrap { overflow-x: auto; }
table.tabla-datos {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.tabla-datos th {
    text-align: left;
    padding: 10px 12px;
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid #e2e8f0;
}
table.tabla-datos td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}
table.tabla-datos tr:hover td { background: #f8fafc; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 10px; display: inline-block; }
.badge-activo { background: #f0fdf4; color: #15803d; }
.badge-inactivo { background: #fef2f2; color: #b91c1c; }
.badge-neutro { background: #eff6ff; color: #1d4ed8; }
.badge-ambar { background: #fffbeb; color: #b45309; }

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #0f172a;
    color: #ffffff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(15,23,42,0.25);
    z-index: 999;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}
.toast.mostrar { opacity: 1; transform: translateY(0); }
.toast.error { background: #b91c1c; }
.toast.exito { background: #15803d; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-caja {
    background: #ffffff;
    border-radius: 10px;
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    overflow-y: auto;
    padding: 24px;
}
.modal-titulo {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 18px;
    color: #0f172a;
}
.modal-acciones {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.texto-vacio {
    text-align: center;
    color: #94a3b8;
    padding: 40px 0;
    font-size: 13.5px;
}

.chip-lista {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.chip-permiso {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12.5px;
    color: #334155;
}
.chip-permiso input { width: auto; }

.modulo-grupo { margin-bottom: 16px; }
.modulo-grupo-titulo {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 8px;
}

@media (max-width: 900px) {
    .sidebar { position: fixed; left: -260px; z-index: 50; box-shadow: 0 0 0 100vmax rgba(15,23,42,0); transition: left 0.2s; }
    .sidebar.abierta-movil { left: 0; box-shadow: 0 0 40px rgba(15,23,42,0.25); }
    .btn-menu-movil { display: block; }
    .grid-2 { grid-template-columns: 1fr; }
    .page-content { padding: 18px; }
}
